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
30
if spec ? ref then spec . ref else
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`!" ;
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
34
submodules = if spec ? submodules then spec . submodules else false ;
35
35
submoduleArg =
36
36
let
44
44
+ "but your nix's (${ builtins . nixVersion } ) builtins.fetchGit "
45
45
+ "does not support them"
46
46
)
47
- { }
48
- else { } ;
47
+ { }
48
+ else { } ;
49
49
in
50
- if nixSupportsSubmodules
51
- then { inherit submodules ; }
52
- else emptyArgWithWarning ;
50
+ if nixSupportsSubmodules
51
+ then { inherit submodules ; }
52
+ else emptyArgWithWarning ;
53
53
in
54
- builtins . fetchGit
55
- ( { url = spec . repo ; inherit ( spec ) rev ; inherit ref ; } // submoduleArg ) ;
54
+ builtins . fetchGit
55
+ ( { url = spec . repo ; inherit ( spec ) rev ; inherit ref ; } // submoduleArg ) ;
56
56
57
57
fetch_local = spec : spec . path ;
58
58
86
86
hasNixpkgsPath = builtins . any ( x : x . prefix == "nixpkgs" ) builtins . nixPath ;
87
87
hasThisAsNixpkgsPath = <nixpkgs> == ./. ;
88
88
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
- '' ;
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
+ '' ;
99
99
100
100
# The actual fetching function.
101
101
fetch = pkgs : name : spec :
@@ -118,10 +118,10 @@ let
118
118
saneName = stringAsChars ( c : if isNull ( builtins . match "[a-zA-Z0-9]" c ) then "_" else c ) name ;
119
119
ersatz = builtins . getEnv "NIV_OVERRIDE_${ saneName } " ;
120
120
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 } " ;
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 } " ;
125
125
126
126
# Ports of functions for older nix versions
127
127
132
132
) ;
133
133
134
134
# 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 ) ;
135
+ range = first : last : if first > last then [ ] else builtins . genList ( n : first + n ) ( last - first + 1 ) ;
136
136
137
137
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
138
138
stringToCharacters = s : map ( p : builtins . substring p 1 s ) ( range 0 ( builtins . stringLength s - 1 ) ) ;
@@ -143,43 +143,46 @@ let
143
143
concatStrings = builtins . concatStringsSep "" ;
144
144
145
145
# https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331
146
- optionalAttrs = cond : as : if cond then as else { } ;
146
+ optionalAttrs = cond : as : if cond then as else { } ;
147
147
148
148
# fetchTarball version that is compatible between all the versions of Nix
149
149
builtins_fetchTarball = { url , name ? null , sha256 } @attrs :
150
150
let
151
151
inherit ( builtins ) lessThan nixVersion fetchTarball ;
152
152
in
153
- if lessThan nixVersion "1.12" then
154
- fetchTarball ( { inherit url ; } // ( optionalAttrs ( ! isNull name ) { inherit name ; } ) )
155
- else
156
- fetchTarball attrs ;
153
+ if lessThan nixVersion "1.12" then
154
+ fetchTarball ( { inherit url ; } // ( optionalAttrs ( ! isNull name ) { inherit name ; } ) )
155
+ else
156
+ fetchTarball attrs ;
157
157
158
158
# fetchurl version that is compatible between all the versions of Nix
159
159
builtins_fetchurl = { url , name ? null , sha256 } @attrs :
160
160
let
161
161
inherit ( builtins ) lessThan nixVersion fetchurl ;
162
162
in
163
- if lessThan nixVersion "1.12" then
164
- fetchurl ( { inherit url ; } // ( optionalAttrs ( ! isNull name ) { inherit name ; } ) )
165
- else
166
- fetchurl attrs ;
163
+ if lessThan nixVersion "1.12" then
164
+ fetchurl ( { inherit url ; } // ( optionalAttrs ( ! isNull name ) { inherit name ; } ) )
165
+ else
166
+ fetchurl attrs ;
167
167
168
168
# Create the final "sources" from the config
169
169
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 ;
170
+ mapAttrs
171
+ (
172
+ name : spec :
173
+ if builtins . hasAttr "outPath" spec
174
+ then
175
+ abort
176
+ "The values in sources.json should not have an 'outPath' attribute"
177
+ else
178
+ spec // { outPath = replace name ( fetch config . pkgs name spec ) ; }
179
+ )
180
+ config . sources ;
178
181
179
182
# The "config" used by the fetchers
180
183
mkConfig =
181
184
{ sourcesFile ? if builtins . pathExists ./sources.json then ./sources.json else null
182
- , sources ? if isNull sourcesFile then { } else builtins . fromJSON ( builtins . readFile sourcesFile )
185
+ , sources ? if isNull sourcesFile then { } else builtins . fromJSON ( builtins . readFile sourcesFile )
183
186
, system ? builtins . currentSystem
184
187
, pkgs ? mkPkgs sources system
185
188
} : rec {
191
194
} ;
192
195
193
196
in
194
- mkSources ( mkConfig { } ) // { __functor = _ : settings : mkSources ( mkConfig settings ) ; }
197
+ mkSources ( mkConfig { } ) // { __functor = _ : settings : mkSources ( mkConfig settings ) ; }
0 commit comments