Skip to content

Commit eb15db0

Browse files
authored
Expose our nixpkgs pins by restructuring default.nix (#514)
* Remove unused (and broken) test files * Make default.nix expose pinned nixpkgs Also make `nixpkgs/default.nix` just an attribute set of sources. This is simpler, and consistent with what e.g. `niv` does. * Add backwards compatibility shim, and version argument to allow evolution in future * Fix some missed things * Fix and improve quickstart
1 parent b4823ea commit eb15db0

31 files changed

+203
-174
lines changed

README.org

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,26 @@ For the documentation, see https://input-output-hk.github.io/haskell.nix/.
2020
For =cabal.project= project add a =default.nix=:
2121

2222
#+begin_src sh
23-
{ pkgs ? import <nixpkgs> (import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz))
23+
let
24+
# Fetch the latest haskell.nix and import its default.nix
25+
haskellNix = import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {};
26+
# haskell.nix provides access to the nixpkgs pins which are used by our CI, hence
27+
# you will be more likely to get cache hits when using these.
28+
# But you can also just use your own, e.g. '<nixpkgs>'
29+
nixpkgsSrc = haskellNix.sources.nixpkgs-1909;
30+
# haskell.nix provides some arguments to be passed to nixpkgs, including some patches
31+
# and also the haskell.nix functionality itself as an overlay.
32+
nixpkgsArgs = haskellNix.nixpkgsArgs;
33+
in
34+
{ pkgs ? import nixpkgsSrc nixpkgsArgs
2435
, haskellCompiler ? "ghc865"
2536
}:
26-
pkgs.haskell-nix.cabalProject {
27-
src = pkgs.haskell-nix.haskellLib.cleanGit { src = ./.; };
28-
ghc = pkgs.buildPackages.pkgs.haskell-nix.compiler.${haskellCompiler};
29-
}
37+
# 'cabalProject' generates a package set based on a cabal.project (and the corresponding .cabal files)
38+
pkgs.haskell-nix.cabalProject {
39+
# 'cleanGit' cleans a source directory based on the files known by git
40+
src = pkgs.haskell-nix.haskellLib.cleanGit { src = ./.; };
41+
ghc = pkgs.buildPackages.pkgs.haskell-nix.compiler.${haskellCompiler};
42+
}
3043
#+end_src
3144

3245
Note that you'll need to add a comment specifying the expected sha256
@@ -45,11 +58,16 @@ source-repository-package
4558
For a =stack.yaml= project add a =default.nix=:
4659

4760
#+begin_src sh
48-
{ pkgs ? import <nixpkgs> (import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz))
61+
let
62+
haskellNix = import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {};
63+
nixpkgsSrc = haskellNix.sources.nixpkgs-1909;
64+
nixpkgsArgs = haskellNix.nixpkgsArgs;
65+
in
66+
{ pkgs ? import nixpkgsSrc nixpkgsArgs
4967
}:
50-
pkgs.haskell-nix.stackProject {
51-
src = pkgs.haskell-nix.haskellLib.cleanGit { src = ./.; };
52-
}
68+
pkgs.haskell-nix.stackProject {
69+
src = pkgs.haskell-nix.haskellLib.cleanGit { src = ./.; };
70+
}
5371
#+end_src
5472

5573
To build the library component of a package in the project run:

build.nix

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
#
33
# It is separate from default.nix because that file is the public API
44
# of Haskell.nix, which shouldn't have tests, etc.
5-
6-
{ nixpkgs ? (import ./nixpkgs/default.nix)
7-
, nixpkgsArgs ? (import ./default.nix)
8-
, pkgs ? (nixpkgs nixpkgsArgs)
5+
let
6+
haskellNix = (import ./default.nix {});
7+
in
8+
{ nixpkgs ? haskellNix.sources.nixpkgs-default
9+
, nixpkgsArgs ? haskellNix.nixpkgsArgs
10+
, pkgs ? import nixpkgs nixpkgsArgs
911
, ifdLevel ? 1000
1012
}:
1113

@@ -27,7 +29,7 @@ in rec {
2729
# nixpkgs 19.09 changes "Option has no description" from an
2830
# error into a warning. That is quite helpful when hardly any
2931
# of our options are documented, thanks @oxij.
30-
pkgs = import ./nixpkgs { nixpkgs-pin = "release-19.09"; };
32+
pkgs = import (import ./nixpkgs/default.nix).nixpkgs-1909 {};
3133
};
3234
};
3335
# Because this is going to be used to test caching on hydra, it must not

builder/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ let
4040

4141
hoogleLocal = let
4242
# Use the latest default nixpkgs hoogle.nix, as the 19.03 one does not work with cross compilers
43-
nixpkgsHoogleLocal = import ((import ../nixpkgs {}).path + /pkgs/development/haskell-modules/hoogle.nix);
43+
nixpkgsHoogleLocal = import ((import (import ../nixpkgs).nixpkgs-default {}).path + /pkgs/development/haskell-modules/hoogle.nix);
4444
in { packages ? [], hoogle ? pkgs.buildPackages.haskell-nix.haskellPackages.hoogle.components.exes.hoogle }:
4545
haskellLib.weakCallPackage pkgs nixpkgsHoogleLocal {
4646
# For musl we can use haddock from the buildGHC

ci-lib.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
let
22
# Generic nixpkgs, use *only* for lib functions that are stable across versions
3-
pkgs = import ./nixpkgs/default.nix {};
3+
pkgs = import (import ./nixpkgs/default.nix).nixpkgs-default {};
44
lib = pkgs.lib;
55
in rec {
66
inherit (import ./dimension.nix) dimension;

ci.nix

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
, restrictEval ? false }:
77
let
88
inherit (import ./ci-lib.nix) dimension platformFilterGeneric filterAttrsOnlyRecursive;
9+
inherit (import ./default.nix {}) sources nixpkgsArgs;
910
nixpkgsVersions = {
10-
"R1903" = "release-19.03";
11-
"R1909" = "release-19.09";
11+
"R1903" = "nixpkgs-1903";
12+
"R1909" = "nixpkgs-1909";
1213
};
1314
systems = nixpkgs: nixpkgs.lib.filterAttrs (_: v: builtins.elem v supportedSystems) {
1415
# I wanted to take these from 'lib.systems.examples', but apparently there isn't one for linux!
@@ -27,13 +28,13 @@ let
2728
# aarch64 cross only works on linux
2829
inherit (lib.systems.examples) musl64 aarch64-multiplatform;
2930
};
30-
haskellNixArgs = import ./.;
3131
in
3232
dimension "Nixpkgs version" nixpkgsVersions (nixpkgsName: nixpkgs-pin:
33-
# We need this for generic nixpkgs stuff at the right version
34-
let genericPkgs = import ./nixpkgs { inherit nixpkgs-pin; };
33+
let pinnedNixpkgsSrc = sources.${nixpkgs-pin};
34+
# We need this for generic nixpkgs stuff at the right version
35+
genericPkgs = import pinnedNixpkgsSrc {};
3536
in dimension "System" (systems genericPkgs) (systemName: system:
36-
let pkgs = import ./nixpkgs (haskellNixArgs // { inherit nixpkgs-pin system; });
37+
let pkgs = import pinnedNixpkgsSrc (nixpkgsArgs // { inherit system; });
3738
build = import ./build.nix { inherit pkgs ifdLevel; };
3839
platformFilter = platformFilterGeneric pkgs system;
3940
in filterAttrsOnlyRecursive (_: v: platformFilter v) {
@@ -49,7 +50,7 @@ dimension "Nixpkgs version" nixpkgsVersions (nixpkgsName: nixpkgs-pin:
4950
//
5051
dimension "Cross system" (crossSystems nixpkgsName genericPkgs system) (crossSystemName: crossSystem:
5152
# Cross builds
52-
let pkgs = import ./nixpkgs (haskellNixArgs // { inherit nixpkgs-pin system crossSystem; });
53+
let pkgs = import pinnedNixpkgsSrc (nixpkgsArgs // { inherit system crossSystem; });
5354
build = import ./build.nix { inherit pkgs ifdLevel; };
5455
in pkgs.recurseIntoAttrs {
5556
hello = (pkgs.haskell-nix.hackage-package { name = "hello"; version = "1.0.0.2"; }).components.exes.hello;

default.nix

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
1-
# This default.nix is designed to be passed directly nixpkgs with something like:
2-
# import <nixpkgs> (import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz))
3-
{ config = import ./config.nix;
4-
overlays = import ./overlays;
5-
}
1+
let haskellNix = rec {
2+
sources = {
3+
inherit (import ./nixpkgs/default.nix) nixpkgs-1903 nixpkgs-1909 nixpkgs-default;
4+
};
5+
6+
config = import ./config.nix;
7+
overlays = import ./overlays;
8+
nixpkgsArgs = { inherit overlays config; };
9+
};
10+
11+
haskellNixV1 = haskellNix.nixpkgsArgs;
12+
haskellNixV2 = haskellNix;
13+
14+
v1DeprecationMessage = "Version 1 is deprecated: use version 2 (nixpkgs arguments are available as the `nixpkgsArgs` attribute of version 2)";
15+
# If no arguments, then you get V1
16+
# I'd like to make importing directly issue a warning, but I couldn't figure out a way to make it happen
17+
in haskellNixV1 // {
18+
__functor = _: { version ? 2 }:
19+
if version == 1
20+
then builtins.trace v1DeprecationMessage haskellNixV1
21+
else if version == 2
22+
then haskellNixV2
23+
else builtins.throw ("haskell.nix: unknown version: " + (builtins.toString version));
24+
}

docs/user-guide.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@
77
To build a package, say [lens][], from a stackage snapshot, say [lts-13.28][],
88
you could run
99
```bash
10-
nix build '(with import <nixpkgs> (import ./.); haskell-nix.snapshots."lts-13.28").lens.components.library'
10+
nix build '(with import <nixpkgs> (import ./. {}).nixpkgsArgs; haskell-nix.snapshots."lts-13.28").lens.components.library'
1111
```
1212
which would build the [lens][] library component from the lens package as fixed
1313
by the [lts-13.28][] stackage snapshot.
1414

1515
To build any package from hackage, say [lens][], in version, say 4.17.1, you
1616
could run
1717
```bash
18-
nix build '(with import <nixpkgs> (import ./.); (haskell-nix.hackage-package { name = "lens"; version = "4.17.1"; })).components.library'
18+
nix build '(with import <nixpkgs> (import ./. {}).nixpkgsArgs; (haskell-nix.hackage-package { name = "lens"; version = "4.17.1"; })).components.library'
1919
```
2020
which would build the [lens][] library component from the [lens-4.17.1][] package
2121
from hackage. The dependencies would be solved against the most recent
2222
[hackage-index-state][] that comes via the [hackage.nix][] pin with your
2323
[haskell.nix][] checkout. A specific one can be specified as well:
2424
```bash
25-
nix build '(with import <nixpkgs> (import ./.); (haskell-nix.hackage-package { name = "lens"; version = "4.17.1"; index-state = "2019-07-14T00:00:00Z"; })).components.library'
25+
nix build '(with import <nixpkgs> (import ./. {}).nixpkgsArgs; (haskell-nix.hackage-package { name = "lens"; version = "4.17.1"; index-state = "2019-07-14T00:00:00Z"; })).components.library'
2626
```
2727
which would use the hackage index as of `2019-07-14T00:00:00Z` to produce a build plan
2828
for the [lens-4.17.1][] package.
@@ -49,7 +49,7 @@ produce derivations that we can `nix build`.
4949
To build the latest `nix-tools` and store the result at `./nt`, run:
5050

5151
```bash
52-
nix build '(with import <nixpkgs> (import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz)); haskell-nix.nix-tools)' --out-link nt
52+
nix build '(with import <nixpkgs> (import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {}).nixpkgsArgs; haskell-nix.nix-tools)' --out-link nt
5353
```
5454

5555
If you would like to then install `nix-tools` into your profile, run:
@@ -85,15 +85,15 @@ The easiest way to get a hold of [Haskell.nix][] is with
8585
[`fetchTarball`](https://nixos.org/nix/manual/#ssec-builtins).
8686

8787
```nix
88-
import <nixpkgs> (import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz))
88+
import <nixpkgs> (import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {}).nixpkgsArgs
8989
```
9090

9191
### Using your cabal.project file
9292

9393
If your project has a `cabal.project` you can add a `default.nix` like this:
9494

9595
```nix
96-
{ pkgs ? import <nixpkgs> (import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz))
96+
{ pkgs ? import <nixpkgs> (import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {}).nixpkgsArgs
9797
, haskellCompiler ? "ghc865"
9898
}:
9999
pkgs.haskell-nix.cabalProject {
@@ -173,7 +173,7 @@ or one of the constraints in your local `.cabal` files).
173173
If your project has a `stack.yaml` you can add a `default.nix` like this:
174174

175175
```nix
176-
{ pkgs ? import <nixpkgs> (import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz))
176+
{ pkgs ? import <nixpkgs> (import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {}).nixpkgsArgs
177177
}:
178178
pkgs.haskell-nix.stackProject {
179179
src = pkgs.haskell-nix.haskellLib.cleanGit { src = ./.; };
@@ -269,7 +269,7 @@ these Git repositories correspond to the actual Hackage and Stackage.
269269
stackageSourceJSON = ./stackage-src.json;
270270
};
271271
})]; })
272-
, haskellNixArgs ? import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz)
272+
, haskellNixArgs ? (import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {}).nixpkgsArgs
273273
}:
274274
pkgs
275275
```
@@ -283,7 +283,7 @@ attrsets and try examples.
283283
# example.nix
284284
{ nixpkgs ? <nixpkgs> }:
285285
rec {
286-
haskell = import nixpkgs (import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz));
286+
haskell = import nixpkgs (import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {}).nixpkgsArgs;
287287
pkgNames = haskell.pkgs.lib.attrNames haskell.haskell-nix.snapshots."lts-13.18";
288288
}
289289
```

docs/user-guide/cabal-projects.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ instantiate a package set.
8181
# default.nix
8282
let
8383
# Import the Haskell.nix library,
84-
src = builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz;
85-
nixpkgs = import (src + "/nixpkgs") (import src);
84+
haskellNix = import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {};
85+
nixpkgs = haskellNix.sources.nixpgs-1909 haskellNix.nixpkgsArgs;
8686
haskell = nixpkgs.haskell-nix;
8787
8888
# Instantiate a package set using the generated file.

docs/user-guide/development.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ selects packages from the larger package set.
108108
```nix
109109
# shell.nix
110110
let
111-
src = builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz;
112-
nixpkgs = import (src + "/nixpkgs") (import src);
111+
haskellNix = import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {};
112+
nixpkgs = haskellNix.sources.nixpkgs-1909 haskellNix.nixpkgsArgs;
113113
haskell = nixpkgs.haskell-nix;
114114
in
115115
haskell.haskellPackages.ghcWithPackages (ps: with ps;
@@ -127,8 +127,8 @@ project.
127127

128128
```nix
129129
let
130-
src = builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz;
131-
nixpkgs = import (src + "/nixpkgs") (import src);
130+
haskellNix = import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {};
131+
nixpkgs = haskellNix.sources.nixpkgs-1909 haskellNix.nixpkgsArgs;
132132
haskell = nixpkgs.haskell-nix;
133133
in
134134
haskell.snapshots."lts-13.18".alex.components.exes.alex

0 commit comments

Comments
 (0)