on iko/ghcjs-patch-master help sign in
Add niv sources at haskell-nix.sources (#622)
commit74915fa817b1d9f2e48da7ec9190ba82cf9f884e authorHamish Mackenzie <Hamish.Mackenzie@iohk.io> dateThu 21 May 2020, 15:39 (6 years ago) parent66e40b0
10 files changed+217−58
default.nix+4−5 nix/sources.json+50 nix/sources.nix+134 nixpkgs/default.nix+2−14 nixpkgs/github.json−9 nixpkgs/hackage-src.json nixpkgs/release-19.09.json−9 nixpkgs/release-20.03.json−9 overlays/default.nix+3−1 overlays/haskell.nix+24−11
default.nix+4−5
@@ -2,10 +2,9 @@ let haskellNix = {
22 checkMaterialization ? false, # Allows us to easily switch on materialization checking
33 defaultCompilerNixName ? null, # Quick way to override the default compiler e.g. "ghc883"
44 system ? builtins.currentSystem,
5− ... }: rec {
6− sources = {
7− inherit (import ./nixpkgs/default.nix) nixpkgs-1909 nixpkgs-2003 nixpkgs-default;
8− };
5+ sourcesOverride ? {},
6+ ... }@args: rec {
7+ sources = (import ./nix/sources.nix) // sourcesOverride;
98
109 config = import ./config.nix;
1110 overlays = [ allOverlays.combined ] ++ (
@@ -29,7 +28,7 @@ let haskellNix = {
2928 )]
3029 else []
3130 );
32− allOverlays = import ./overlays;
31+ allOverlays = import ./overlays args;
3332 nixpkgsArgs = { inherit config overlays system; };
3433 pkgs = import sources.nixpkgs-default nixpkgsArgs;
3534 };
nix/sources.jsonnew file+50
@@ -0,0 +1,50 @@
1+{
2+ "niv": {
3+ "branch": "master",
4+ "description": "Easy dependency management for Nix projects",
5+ "homepage": "https://github.com/nmattia/niv",
6+ "owner": "nmattia",
7+ "repo": "niv",
8+ "rev": "f73bf8d584148677b01859677a63191c31911eae",
9+ "sha256": "0jlmrx633jvqrqlyhlzpvdrnim128gc81q5psz2lpp2af8p8q9qs",
10+ "type": "tarball",
11+ "url": "https://github.com/nmattia/niv/archive/f73bf8d584148677b01859677a63191c31911eae.tar.gz",
12+ "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
13+ },
14+ "nixpkgs-1909": {
15+ "branch": "nixpkgs-19.09-darwin",
16+ "description": "Nix Packages collection",
17+ "homepage": null,
18+ "owner": "NixOS",
19+ "repo": "nixpkgs",
20+ "rev": "9237a09d8edbae9951a67e9a3434a07ef94035b7",
21+ "sha256": "05bizymljzzd665bpsjbhxamcgzq7bkjjzjfapkl2nicy774ak4x",
22+ "type": "tarball",
23+ "url": "https://github.com/NixOS/nixpkgs/archive/9237a09d8edbae9951a67e9a3434a07ef94035b7.tar.gz",
24+ "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
25+ },
26+ "nixpkgs-2003": {
27+ "branch": "nixpkgs-20.03-darwin",
28+ "description": "Nix Packages collection",
29+ "homepage": null,
30+ "owner": "NixOS",
31+ "repo": "nixpkgs",
32+ "rev": "cac363c661817666e43d047addfaa722610d425f",
33+ "sha256": "0fi8hgddy8qh2jrsa40jw7jxnr5lrhq2ji6a2xbndllivhzc31kf",
34+ "type": "tarball",
35+ "url": "https://github.com/NixOS/nixpkgs/archive/cac363c661817666e43d047addfaa722610d425f.tar.gz",
36+ "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
37+ },
38+ "nixpkgs-default": {
39+ "branch": "nixpkgs-20.03-darwin",
40+ "description": "Nix Packages collection",
41+ "homepage": null,
42+ "owner": "NixOS",
43+ "repo": "nixpkgs",
44+ "rev": "cac363c661817666e43d047addfaa722610d425f",
45+ "sha256": "0fi8hgddy8qh2jrsa40jw7jxnr5lrhq2ji6a2xbndllivhzc31kf",
46+ "type": "tarball",
47+ "url": "https://github.com/NixOS/nixpkgs/archive/cac363c661817666e43d047addfaa722610d425f.tar.gz",
48+ "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
49+ }
50+}
nix/sources.nixnew file+134
@@ -0,0 +1,134 @@
1+# This file has been generated by Niv.
2+
3+let
4+
5+ #
6+ # The fetchers. fetch_<type> fetches specs of type <type>.
7+ #
8+
9+ fetch_file = pkgs: spec:
10+ if spec.builtin or true then
11+ builtins_fetchurl { inherit (spec) url sha256; }
12+ else
13+ pkgs.fetchurl { inherit (spec) url sha256; };
14+
15+ fetch_tarball = pkgs: spec:
16+ if spec.builtin or true then
17+ builtins_fetchTarball { inherit (spec) url sha256; }
18+ else
19+ pkgs.fetchzip { inherit (spec) url sha256; };
20+
21+ fetch_git = spec:
22+ builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; };
23+
24+ fetch_builtin-tarball = spec:
25+ builtins.trace
26+ ''
27+ WARNING:
28+ The niv type "builtin-tarball" will soon be deprecated. You should
29+ instead use `builtin = true`.
30+
31+ $ niv modify <package> -a type=tarball -a builtin=true
32+ ''
33+ builtins_fetchTarball { inherit (spec) url sha256; };
34+
35+ fetch_builtin-url = spec:
36+ builtins.trace
37+ ''
38+ WARNING:
39+ The niv type "builtin-url" will soon be deprecated. You should
40+ instead use `builtin = true`.
41+
42+ $ niv modify <package> -a type=file -a builtin=true
43+ ''
44+ (builtins_fetchurl { inherit (spec) url sha256; });
45+
46+ #
47+ # Various helpers
48+ #
49+
50+ # The set of packages used when specs are fetched using non-builtins.
51+ mkPkgs = sources:
52+ let
53+ sourcesNixpkgs =
54+ import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) {};
55+ hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
56+ hasThisAsNixpkgsPath = <nixpkgs> == ./.;
57+ in
58+ if builtins.hasAttr "nixpkgs" sources
59+ then sourcesNixpkgs
60+ else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
61+ import <nixpkgs> {}
62+ else
63+ abort
64+ ''
65+ Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
66+ add a package called "nixpkgs" to your sources.json.
67+ '';
68+
69+ # The actual fetching function.
70+ fetch = pkgs: name: spec:
71+
72+ if ! builtins.hasAttr "type" spec then
73+ abort "ERROR: niv spec ${name} does not have a 'type' attribute"
74+ else if spec.type == "file" then fetch_file pkgs spec
75+ else if spec.type == "tarball" then fetch_tarball pkgs spec
76+ else if spec.type == "git" then fetch_git spec
77+ else if spec.type == "builtin-tarball" then fetch_builtin-tarball spec
78+ else if spec.type == "builtin-url" then fetch_builtin-url spec
79+ else
80+ abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}";
81+
82+ # Ports of functions for older nix versions
83+
84+ # a Nix version of mapAttrs if the built-in doesn't exist
85+ mapAttrs = builtins.mapAttrs or (
86+ f: set: with builtins;
87+ listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))
88+ );
89+
90+ # fetchTarball version that is compatible between all the versions of Nix
91+ builtins_fetchTarball = { url, sha256 }@attrs:
92+ let
93+ inherit (builtins) lessThan nixVersion fetchTarball;
94+ in
95+ if lessThan nixVersion "1.12" then
96+ fetchTarball { inherit url; }
97+ else
98+ fetchTarball attrs;
99+
100+ # fetchurl version that is compatible between all the versions of Nix
101+ builtins_fetchurl = { url, sha256 }@attrs:
102+ let
103+ inherit (builtins) lessThan nixVersion fetchurl;
104+ in
105+ if lessThan nixVersion "1.12" then
106+ fetchurl { inherit url; }
107+ else
108+ fetchurl attrs;
109+
110+ # Create the final "sources" from the config
111+ mkSources = config:
112+ mapAttrs (
113+ name: spec:
114+ if builtins.hasAttr "outPath" spec
115+ then abort
116+ "The values in sources.json should not have an 'outPath' attribute"
117+ else
118+ spec // { outPath = fetch config.pkgs name spec; }
119+ ) config.sources;
120+
121+ # The "config" used by the fetchers
122+ mkConfig =
123+ { sourcesFile ? ./sources.json
124+ , sources ? builtins.fromJSON (builtins.readFile sourcesFile)
125+ , pkgs ? mkPkgs sources
126+ }: rec {
127+ # The sources, i.e. the attribute set of spec name to spec
128+ inherit sources;
129+
130+ # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers
131+ inherit pkgs;
132+ };
133+in
134+mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }
nixpkgs/default.nix+2−14
@@ -1,16 +1,4 @@
1−# see ../docs/dev/nixpkgs-pin.md
2−let
3− fetch = jsonFile:
4− with builtins;
5− let spec = fromJSON (readFile jsonFile);
6− in fetchTarball {
7− name = "nixpkgs";
8− inherit (spec) sha256;
9− url = "${spec.url}/archive/${spec.rev}.tar.gz";
10− };
11−in
1+# This file is for backwards compatibility only
122{
13− nixpkgs-2003 = fetch (./. + "/release-20.03.json");
14− nixpkgs-1909 = fetch (./. + "/release-19.09.json");
15− nixpkgs-default = fetch (./. + "/github.json");
3+ inherit (import ../nix/sources.nix) nixpkgs-2003 nixpkgs-1909 nixpkgs-default;
164}
nixpkgs/github.jsondeleted−9
@@ -1,9 +0,0 @@
1−{
2− "url": "https://github.com/NixOS/nixpkgs",
3− "rev": "cac363c661817666e43d047addfaa722610d425f",
4− "date": "2020-03-24T13:44:58+01:00",
5− "sha256": "0fi8hgddy8qh2jrsa40jw7jxnr5lrhq2ji6a2xbndllivhzc31kf",
6− "fetchSubmodules": false,
7− "deepClone": false,
8− "leaveDotGit": false
9−}
nixpkgs/hackage-src.jsondeleted

No changes to the content.

nixpkgs/release-19.09.jsondeleted−9
@@ -1,9 +0,0 @@
1−{
2− "url": "https://github.com/NixOS/nixpkgs",
3− "rev": "9237a09d8edbae9951a67e9a3434a07ef94035b7",
4− "date": "2020-04-19T11:10:38+05:30",
5− "sha256": "05bizymljzzd665bpsjbhxamcgzq7bkjjzjfapkl2nicy774ak4x",
6− "fetchSubmodules": false,
7− "deepClone": false,
8− "leaveDotGit": false
9−}
nixpkgs/release-20.03.jsondeleted−9
@@ -1,9 +0,0 @@
1−{
2− "url": "https://github.com/NixOS/nixpkgs",
3− "rev": "cac363c661817666e43d047addfaa722610d425f",
4− "date": "2020-03-24T13:44:58+01:00",
5− "sha256": "0fi8hgddy8qh2jrsa40jw7jxnr5lrhq2ji6a2xbndllivhzc31kf",
6− "fetchSubmodules": false,
7− "deepClone": false,
8− "leaveDotGit": false
9−}
overlays/default.nix+3−1
@@ -1,9 +1,11 @@
1+args:
2+
13let
24 overlays = {
35 wine = import ./wine.nix;
46 #ghcjs = import ./ghcjs-asterius-triple.nix;
57 #python = import ./python.nix;
6− haskell = import ./haskell.nix;
8+ haskell = import ./haskell.nix args;
79 hackage-quirks = import ./hackage-quirks.nix;
810 bootstrap = import ./bootstrap.nix;
911 ghc = import ./ghc.nix;
overlays/haskell.nix+24−11
@@ -1,3 +1,5 @@
1+{ sourcesOverride ? {}
2+, ... }:
13# The haskell.nix infrastructure
24#
35# for hygenic reasons we'll use haskell-nix as a prefix.
@@ -10,6 +12,26 @@ final: prev: {
1012 # overlays.
1113 defaultModules = [];
1214
15+ # Niv based source pins. See https://github.com/nmattia/niv#niv
16+ # for details on how to update this using the niv tool
17+ # or edit nix/sources.json manually if you prefer.
18+ sources = {
19+ # Hackage and stackage still updated by scripts
20+ # that predate our use of niv. We have moved them
21+ # here though so that you can still use the
22+ # sourcesOverride arg or `niv add` to replace them.
23+ hackage = fetchExternal {
24+ name = "hackage-exprs-source";
25+ specJSON = hackageSourceJSON;
26+ override = "hackage";
27+ };
28+ stackage = fetchExternal {
29+ name = "stackage-snapshot-source";
30+ specJSON = stackageSourceJSON;
31+ override = "stackage";
32+ };
33+ } // (import ../nix/sources.nix) // sourcesOverride;
34+
1335 # We provide a `callPackage` function to consumers for
1436 # convenience. We will however refrain from using it
1537 # here and be explicit about imports and dependencies.
@@ -37,11 +59,7 @@ final: prev: {
3759 cleanSourceHaskell;
3860
3961 # All packages from Hackage as Nix expressions
40− hackageSrc = fetchExternal {
41− name = "hackage-exprs-source";
42− specJSON = hackageSourceJSON;
43− override = "hackage";
44− };
62+ hackageSrc = sources.hackage;
4563 hackage = import hackageSrc;
4664
4765 # Contains the hashes of the cabal 01-index.tar.gz for given
@@ -49,12 +67,7 @@ final: prev: {
4967 indexStateHashesPath = hackageSrc + "/index-state-hashes.nix";
5068
5169 # The set of all Stackage snapshots
52− stackageSrc = fetchExternal {
53− name = "stackage-snapshot-source";
54− specJSON = stackageSourceJSON;
55− override = "stackage";
56− };
57−
70+ stackageSrc = sources.stackage;
5871 stackage = import stackageSrc;
5972
6073 # Utility functions for working with the component builder.