Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplifying Nix #5154

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/nix-dev-cache.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
fail-fast: false
matrix:
os:
- ubuntu-20.04
- ubuntu-22.04
- macOS-12
- macOS-14
steps:
Expand All @@ -37,4 +37,4 @@ jobs:
name: unison
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: build all packages and development shells
run: nix -L build --accept-flake-config --no-link --keep-going '.#build-tools'
run: nix -L build --accept-flake-config --no-link --keep-going '.#all'
19 changes: 5 additions & 14 deletions development.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ This codebase uses symlinks as a workaround for some inconveniences in the `here

First you'll need to enable "Developer Mode" in your Windows settings.

See https://consumer.huawei.com/en/support/content/en-us15594140/
See https://consumer.huawei.com/en/support/content/en-us15594140/

Then you'll need to enable symlink support in your `git` configuration, e.g.

Expand All @@ -113,8 +113,6 @@ Stack doesn't work deterministically in Windows due to mismatched expectations a

## Building with Nix

## Building package components with nix

### Build the unison executable
```
nix build
Expand All @@ -133,28 +131,21 @@ nix build '.#component-unison-cli:exe:transcripts'

### Development environments

#### Get into a development environment for building with stack
#### Get into a development environment for building with stack or cabal
This gets you into a development environment with the preferred
versions of the compiler and other development tools. These
include:

- cabal
- ghc
- stack
- ormolu
- haskell-language-server

```
nix develop
```

#### Get into a development environment for building with cabal
This gets you into a development environment with the preferred
versions of the compiler and other development tools. Additionally,
all non-local haskell dependencies (including profiling dependencies)
are provided in the nix shell.
Additionally, all non-local haskell dependencies (including profiling dependencies) are provided in the nix shell.

```
nix develop '.#cabal-local'
nix develop
```

#### Get into a development environment for building a specific package
Expand Down
24 changes: 12 additions & 12 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

99 changes: 27 additions & 72 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@

inputs = {
haskellNix.url = "github:input-output-hk/haskell.nix";
nixpkgs.follows = "haskellNix/nixpkgs-unstable";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
nixpkgs-haskellNix.follows = "haskellNix/nixpkgs-unstable";
nixpkgs-release.url = "github:NixOS/nixpkgs/release-23.11";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = {
self,
nixpkgs,
flake-utils,
haskellNix,
nixpkgs-unstable,
nixpkgs-haskellNix,
nixpkgs-release,
flake-utils,
}:
flake-utils.lib.eachSystem [
"x86_64-linux"
Expand All @@ -27,99 +27,55 @@
]
(system: let
versions = {
ghc = "928";
ormolu = "0.5.2.0";
hls = "2.4.0.0";
stack = "2.13.1";
hpack = "0.35.2";
};
overlays = [
haskellNix.overlay
(import ./nix/haskell-nix-overlay.nix)
(import ./nix/unison-overlay.nix)
];
pkgs = import nixpkgs {
inherit system overlays;
inherit (haskellNix) config;
};
haskell-nix-flake = import ./nix/haskell-nix-flake.nix {
inherit pkgs versions;
inherit (nixpkgs-packages) stack hpack;
};
unstable = import nixpkgs-unstable {
pkgs = import nixpkgs-haskellNix {
inherit system;
inherit (haskellNix) config;
overlays = [
(import ./nix/unison-overlay.nix)
(import ./nix/nixpkgs-overlay.nix {inherit versions;})
haskellNix.overlay
(import ./nix/dependencies.nix {inherit nixpkgs-release;})
];
};
nixpkgs-packages = let
hpkgs = unstable.haskell.packages.ghcunison;
exe = unstable.haskell.lib.justStaticExecutables;
in {
ghc = unstable.haskell.compiler."ghc${versions.ghc}";
ormolu = exe hpkgs.ormolu;
hls = unstable.unison-hls;
stack = unstable.unison-stack;
unwrapped-stack = unstable.stack;
hpack = unstable.hpack;
unison-project = import ./nix/unison-project.nix {
inherit (nixpkgs-haskellNix) lib;
inherit (pkgs) haskell-nix;
};
nixpkgs-devShells = {
only-tools-nixpkgs = unstable.mkShell {
name = "only-tools-nixpkgs";
buildInputs = let
build-tools = with nixpkgs-packages; [
ghc
ormolu
hls
stack
hpack
];
native-packages =
pkgs.lib.optionals pkgs.stdenv.isDarwin
(with unstable.darwin.apple_sdk.frameworks; [Cocoa]);
c-deps = with unstable; [pkg-config zlib glibcLocales];
in
build-tools ++ c-deps ++ native-packages;
shellHook = ''
export LD_LIBRARY_PATH=${pkgs.zlib}/lib:$LD_LIBRARY_PATH
'';
};
haskell-nix-flake = import ./nix/haskell-nix-flake.nix {
inherit pkgs unison-project versions;
inherit (nixpkgs-haskellNix) lib;
};

renameAttrs = fn:
nixpkgs.lib.mapAttrs' (name: value: {
nixpkgs-haskellNix.lib.mapAttrs' (name: value: {
inherit value;
name = fn name;
});
in
assert nixpkgs-packages.ormolu.version == versions.ormolu;
assert nixpkgs-packages.hls.version == versions.hls;
assert nixpkgs-packages.unwrapped-stack.version == versions.stack;
assert nixpkgs-packages.hpack.version == versions.hpack; {
assert pkgs.stack.version == versions.stack;
assert pkgs.hpack.version == versions.hpack; {
packages =
nixpkgs-packages
// renameAttrs (name: "component-${name}") haskell-nix-flake.packages
renameAttrs (name: "component-${name}") haskell-nix-flake.packages
// renameAttrs (name: "docker-${name}") (import ./nix/docker.nix {
inherit pkgs;
haskell-nix = haskell-nix-flake.packages;
})
// {
default = haskell-nix-flake.defaultPackage;
build-tools = pkgs.symlinkJoin {
name = "build-tools";
paths = self.devShells."${system}".only-tools-nixpkgs.buildInputs;
};
all = pkgs.symlinkJoin {
name = "all";
paths = let
all-other-packages = builtins.attrValues (builtins.removeAttrs self.packages."${system}" ["all" "build-tools"]);
all-other-packages =
builtins.attrValues (builtins.removeAttrs self.packages."${system}" [
"all"
"docker-ucm" # this package doesn’t produce a directory
]);
devshell-inputs =
builtins.concatMap
(devShell: devShell.buildInputs ++ devShell.nativeBuildInputs)
[
self.devShells."${system}".only-tools-nixpkgs
];
(builtins.attrValues self.devShells."${system}");
in
all-other-packages ++ devshell-inputs;
};
Expand All @@ -130,9 +86,8 @@
// {default = self.apps."${system}"."component-unison-cli-main:exe:unison";};

devShells =
nixpkgs-devShells
// renameAttrs (name: "cabal-${name}") haskell-nix-flake.devShells
// {default = self.devShells."${system}".only-tools-nixpkgs;};
renameAttrs (name: "cabal-${name}") haskell-nix-flake.devShells
// {default = self.devShells."${system}".cabal-local;};

checks = renameAttrs (name: "component-${name}") haskell-nix-flake.checks;

Expand Down
21 changes: 21 additions & 0 deletions nix/dependencies.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{nixpkgs-release}: final: prev: let
pinned-pkgs = import nixpkgs-release {inherit (final) system;};
in {
stack = pinned-pkgs.stack;

## See https://docs.haskellstack.org/en/stable/nix_integration/#supporting-both-nix-and-non-nix-developers for an
## explanation of this package.
stack-wrapped = final.symlinkJoin {
name = "stack"; # will be available as the usual `stack` in terminal
paths = [final.stack];
buildInputs = [final.makeWrapper];
postBuild = ''
wrapProgram $out/bin/stack \
--add-flags "\
--no-nix \
--system-ghc \
--no-install-ghc \
"
'';
};
}
Loading
Loading