| ... |
... |
@@ -10,33 +10,34 @@ let |
|
10
|
10
|
let
|
|
11
|
11
|
name' = sanitizeName name + "-src";
|
|
12
|
12
|
in
|
|
13
|
|
- if spec.builtin or true then
|
|
14
|
|
- builtins_fetchurl { inherit (spec) url sha256; name = name'; }
|
|
15
|
|
- else
|
|
16
|
|
- pkgs.fetchurl { inherit (spec) url sha256; name = name'; };
|
|
|
13
|
+ if spec.builtin or true then
|
|
|
14
|
+ builtins_fetchurl { inherit (spec) url sha256; name = name'; }
|
|
|
15
|
+ else
|
|
|
16
|
+ pkgs.fetchurl { inherit (spec) url sha256; name = name'; };
|
|
17
|
17
|
|
|
18
|
18
|
fetch_tarball = pkgs: name: spec:
|
|
19
|
19
|
let
|
|
20
|
20
|
name' = sanitizeName name + "-src";
|
|
21
|
21
|
in
|
|
22
|
|
- if spec.builtin or true then
|
|
23
|
|
- builtins_fetchTarball { name = name'; inherit (spec) url sha256; }
|
|
24
|
|
- else
|
|
25
|
|
- pkgs.fetchzip { name = name'; inherit (spec) url sha256; };
|
|
|
22
|
+ if spec.builtin or true then
|
|
|
23
|
+ builtins_fetchTarball { name = name'; inherit (spec) url sha256; }
|
|
|
24
|
+ else
|
|
|
25
|
+ pkgs.fetchzip { name = name'; inherit (spec) url sha256; };
|
|
26
|
26
|
|
|
27
|
27
|
fetch_git = name: spec:
|
|
28
|
28
|
let
|
|
29
|
29
|
ref =
|
|
30
|
|
- if spec ? ref then spec.ref else
|
|
|
30
|
+ spec.ref or (
|
|
31
|
31
|
if spec ? branch then "refs/heads/${spec.branch}" else
|
|
32
|
|
- if spec ? tag then "refs/tags/${spec.tag}" else
|
|
33
|
|
- abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!";
|
|
34
|
|
- submodules = if spec ? submodules then spec.submodules else false;
|
|
|
32
|
+ if spec ? tag then "refs/tags/${spec.tag}" else
|
|
|
33
|
+ abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"
|
|
|
34
|
+ );
|
|
|
35
|
+ submodules = spec.submodules or false;
|
|
35
|
36
|
submoduleArg =
|
|
36
|
37
|
let
|
|
37
|
38
|
nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0;
|
|
38
|
39
|
emptyArgWithWarning =
|
|
39
|
|
- if submodules == true
|
|
|
40
|
+ if submodules
|
|
40
|
41
|
then
|
|
41
|
42
|
builtins.trace
|
|
42
|
43
|
(
|
| ... |
... |
@@ -44,15 +45,15 @@ let |
|
44
|
45
|
+ "but your nix's (${builtins.nixVersion}) builtins.fetchGit "
|
|
45
|
46
|
+ "does not support them"
|
|
46
|
47
|
)
|
|
47
|
|
- {}
|
|
48
|
|
- else {};
|
|
|
48
|
+ { }
|
|
|
49
|
+ else { };
|
|
49
|
50
|
in
|
|
50
|
|
- if nixSupportsSubmodules
|
|
51
|
|
- then { inherit submodules; }
|
|
52
|
|
- else emptyArgWithWarning;
|
|
|
51
|
+ if nixSupportsSubmodules
|
|
|
52
|
+ then { inherit submodules; }
|
|
|
53
|
+ else emptyArgWithWarning;
|
|
53
|
54
|
in
|
|
54
|
|
- builtins.fetchGit
|
|
55
|
|
- ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg);
|
|
|
55
|
+ builtins.fetchGit
|
|
|
56
|
+ ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg);
|
|
56
|
57
|
|
|
57
|
58
|
fetch_local = spec: spec.path;
|
|
58
|
59
|
|
| ... |
... |
@@ -86,16 +87,16 @@ let |
|
86
|
87
|
hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
|
|
87
|
88
|
hasThisAsNixpkgsPath = <nixpkgs> == ./.;
|
|
88
|
89
|
in
|
|
89
|
|
- if builtins.hasAttr "nixpkgs" sources
|
|
90
|
|
- then sourcesNixpkgs
|
|
91
|
|
- else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
|
|
92
|
|
- import <nixpkgs> {}
|
|
93
|
|
- else
|
|
94
|
|
- abort
|
|
95
|
|
- ''
|
|
96
|
|
- Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
|
|
97
|
|
- add a package called "nixpkgs" to your sources.json.
|
|
98
|
|
- '';
|
|
|
90
|
+ if builtins.hasAttr "nixpkgs" sources
|
|
|
91
|
+ then sourcesNixpkgs
|
|
|
92
|
+ else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
|
|
|
93
|
+ import <nixpkgs> { }
|
|
|
94
|
+ else
|
|
|
95
|
+ abort
|
|
|
96
|
+ ''
|
|
|
97
|
+ Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
|
|
|
98
|
+ add a package called "nixpkgs" to your sources.json.
|
|
|
99
|
+ '';
|
|
99
|
100
|
|
|
100
|
101
|
# The actual fetching function.
|
|
101
|
102
|
fetch = pkgs: name: spec:
|
| ... |
... |
@@ -115,13 +116,13 @@ let |
|
115
|
116
|
# the path directly as opposed to the fetched source.
|
|
116
|
117
|
replace = name: drv:
|
|
117
|
118
|
let
|
|
118
|
|
- saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name;
|
|
|
119
|
+ saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name;
|
|
119
|
120
|
ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}";
|
|
120
|
121
|
in
|
|
121
|
|
- if ersatz == "" then drv else
|
|
122
|
|
- # this turns the string into an actual Nix path (for both absolute and
|
|
123
|
|
- # relative paths)
|
|
124
|
|
- if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}";
|
|
|
122
|
+ if ersatz == "" then drv else
|
|
|
123
|
+ # this turns the string into an actual Nix path (for both absolute and
|
|
|
124
|
+ # relative paths)
|
|
|
125
|
+ if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}";
|
|
125
|
126
|
|
|
126
|
127
|
# Ports of functions for older nix versions
|
|
127
|
128
|
|
| ... |
... |
@@ -132,7 +133,7 @@ let |
|
132
|
133
|
);
|
|
133
|
134
|
|
|
134
|
135
|
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
|
|
135
|
|
- range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1);
|
|
|
136
|
+ range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1);
|
|
136
|
137
|
|
|
137
|
138
|
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
|
|
138
|
139
|
stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
|
| ... |
... |
@@ -143,43 +144,46 @@ let |
|
143
|
144
|
concatStrings = builtins.concatStringsSep "";
|
|
144
|
145
|
|
|
145
|
146
|
# https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331
|
|
146
|
|
- optionalAttrs = cond: as: if cond then as else {};
|
|
|
147
|
+ optionalAttrs = cond: as: if cond then as else { };
|
|
147
|
148
|
|
|
148
|
149
|
# fetchTarball version that is compatible between all the versions of Nix
|
|
149
|
150
|
builtins_fetchTarball = { url, name ? null, sha256 }@attrs:
|
|
150
|
151
|
let
|
|
151
|
152
|
inherit (builtins) lessThan nixVersion fetchTarball;
|
|
152
|
153
|
in
|
|
153
|
|
- if lessThan nixVersion "1.12" then
|
|
154
|
|
- fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
|
|
155
|
|
- else
|
|
156
|
|
- fetchTarball attrs;
|
|
|
154
|
+ if lessThan nixVersion "1.12" then
|
|
|
155
|
+ fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; }))
|
|
|
156
|
+ else
|
|
|
157
|
+ fetchTarball attrs;
|
|
157
|
158
|
|
|
158
|
159
|
# fetchurl version that is compatible between all the versions of Nix
|
|
159
|
160
|
builtins_fetchurl = { url, name ? null, sha256 }@attrs:
|
|
160
|
161
|
let
|
|
161
|
162
|
inherit (builtins) lessThan nixVersion fetchurl;
|
|
162
|
163
|
in
|
|
163
|
|
- if lessThan nixVersion "1.12" then
|
|
164
|
|
- fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
|
|
165
|
|
- else
|
|
166
|
|
- fetchurl attrs;
|
|
|
164
|
+ if lessThan nixVersion "1.12" then
|
|
|
165
|
+ fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; }))
|
|
|
166
|
+ else
|
|
|
167
|
+ fetchurl attrs;
|
|
167
|
168
|
|
|
168
|
169
|
# Create the final "sources" from the config
|
|
169
|
170
|
mkSources = config:
|
|
170
|
|
- mapAttrs (
|
|
171
|
|
- name: spec:
|
|
172
|
|
- if builtins.hasAttr "outPath" spec
|
|
173
|
|
- then abort
|
|
174
|
|
- "The values in sources.json should not have an 'outPath' attribute"
|
|
175
|
|
- else
|
|
176
|
|
- spec // { outPath = replace name (fetch config.pkgs name spec); }
|
|
177
|
|
- ) config.sources;
|
|
|
171
|
+ mapAttrs
|
|
|
172
|
+ (
|
|
|
173
|
+ name: spec:
|
|
|
174
|
+ if builtins.hasAttr "outPath" spec
|
|
|
175
|
+ then
|
|
|
176
|
+ abort
|
|
|
177
|
+ "The values in sources.json should not have an 'outPath' attribute"
|
|
|
178
|
+ else
|
|
|
179
|
+ spec // { outPath = replace name (fetch config.pkgs name spec); }
|
|
|
180
|
+ )
|
|
|
181
|
+ config.sources;
|
|
178
|
182
|
|
|
179
|
183
|
# The "config" used by the fetchers
|
|
180
|
184
|
mkConfig =
|
|
181
|
185
|
{ sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null
|
|
182
|
|
- , sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile)
|
|
|
186
|
+ , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile)
|
|
183
|
187
|
, system ? builtins.currentSystem
|
|
184
|
188
|
, pkgs ? mkPkgs sources system
|
|
185
|
189
|
}: rec {
|
| ... |
... |
@@ -191,4 +195,4 @@ let |
|
191
|
195
|
};
|
|
192
|
196
|
|
|
193
|
197
|
in
|
|
194
|
|
-mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } |
|
|
198
|
+mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } |