66 # The fetchers. fetch_<type> fetches specs of type <type>.
77 #
88
9- fetch_file = pkgs : name : spec :
9+ fetch_file =
10+ pkgs : name : spec :
1011 let
1112 name' = sanitizeName name + "-src" ;
1213 in
1314 if spec . builtin or true then
14- builtins_fetchurl { inherit ( spec ) url sha256 ; name = name' ; }
15+ builtins_fetchurl {
16+ inherit ( spec ) url sha256 ;
17+ name = name' ;
18+ }
1519 else
16- pkgs . fetchurl { inherit ( spec ) url sha256 ; name = name' ; } ;
20+ pkgs . fetchurl {
21+ inherit ( spec ) url sha256 ;
22+ name = name' ;
23+ } ;
1724
18- fetch_tarball = pkgs : name : spec :
25+ fetch_tarball =
26+ pkgs : name : spec :
1927 let
2028 name' = sanitizeName name + "-src" ;
2129 in
2230 if spec . builtin or true then
23- builtins_fetchTarball { name = name' ; inherit ( spec ) url sha256 ; }
31+ builtins_fetchTarball {
32+ name = name' ;
33+ inherit ( spec ) url sha256 ;
34+ }
2435 else
25- pkgs . fetchzip { name = name' ; inherit ( spec ) url sha256 ; } ;
36+ pkgs . fetchzip {
37+ name = name' ;
38+ inherit ( spec ) url sha256 ;
39+ } ;
2640
27- fetch_git = name : spec :
41+ fetch_git =
42+ name : spec :
2843 let
2944 ref =
3045 spec . ref or (
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`!"
46+ if spec ? branch then
47+ "refs/heads/${ spec . branch } "
48+ else if spec ? tag then
49+ "refs/tags/${ spec . tag } "
50+ else
51+ abort "In git source '${ name } ': Please specify `ref`, `tag` or `branch`!"
3452 ) ;
3553 submodules = spec . submodules or false ;
3654 submoduleArg =
3755 let
3856 nixSupportsSubmodules = builtins . compareVersions builtins . nixVersion "2.4" >= 0 ;
3957 emptyArgWithWarning =
40- if submodules
41- then
42- builtins . trace
43- (
44- "The niv input \" ${ name } \" uses submodules "
45- + "but your nix's (${ builtins . nixVersion } ) builtins.fetchGit "
46- + "does not support them"
47- )
48- { }
49- else { } ;
58+ if submodules then
59+ builtins . trace (
60+ "The niv input \" ${ name } \" uses submodules "
61+ + "but your nix's (${ builtins . nixVersion } ) builtins.fetchGit "
62+ + "does not support them"
63+ ) { }
64+ else
65+ { } ;
5066 in
51- if nixSupportsSubmodules
52- then { inherit submodules ; }
53- else emptyArgWithWarning ;
67+ if nixSupportsSubmodules then { inherit submodules ; } else emptyArgWithWarning ;
5468 in
55- builtins . fetchGit
56- ( { url = spec . repo ; inherit ( spec ) rev ; inherit ref ; } // submoduleArg ) ;
69+ builtins . fetchGit (
70+ {
71+ url = spec . repo ;
72+ inherit ( spec ) rev ;
73+ inherit ref ;
74+ }
75+ // submoduleArg
76+ ) ;
5777
5878 fetch_local = spec : spec . path ;
5979
60- fetch_builtin-tarball = name : throw
61- ''[${ name } ] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`.
62- $ niv modify ${ name } -a type=tarball -a builtin=true'' ;
80+ fetch_builtin-tarball =
81+ name :
82+ throw ''
83+ [${ name } ] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`.
84+ $ niv modify ${ name } -a type=tarball -a builtin=true'' ;
6385
64- fetch_builtin-url = name : throw
65- ''[${ name } ] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`.
66- $ niv modify ${ name } -a type=file -a builtin=true'' ;
86+ fetch_builtin-url =
87+ name :
88+ throw ''
89+ [${ name } ] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`.
90+ $ niv modify ${ name } -a type=file -a builtin=true'' ;
6791
6892 #
6993 # Various helpers
7094 #
7195
7296 # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695
73- sanitizeName = name :
74- (
75- concatMapStrings ( s : if builtins . isList s then "-" else s )
76- (
77- builtins . split "[^[:alnum:]+._?=-]+"
78- ( ( x : builtins . elemAt ( builtins . match "\\ .*(.*)" x ) 0 ) name )
79- )
80- ) ;
97+ sanitizeName =
98+ name :
99+ ( concatMapStrings ( s : if builtins . isList s then "-" else s ) (
100+ builtins . split "[^[:alnum:]+._?=-]+" ( ( x : builtins . elemAt ( builtins . match "\\ .*(.*)" x ) 0 ) name )
101+ ) ) ;
81102
82103 # The set of packages used when specs are fetched using non-builtins.
83- mkPkgs = sources : system :
104+ mkPkgs =
105+ sources : system :
84106 let
85- sourcesNixpkgs =
86- import ( builtins_fetchTarball { inherit ( sources . nixpkgs ) url sha256 ; } ) { inherit system ; } ;
107+ sourcesNixpkgs = import ( builtins_fetchTarball { inherit ( sources . nixpkgs ) url sha256 ; } ) {
108+ inherit system ;
109+ } ;
87110 hasNixpkgsPath = builtins . any ( x : x . prefix == "nixpkgs" ) builtins . nixPath ;
88111 hasThisAsNixpkgsPath = <nixpkgs> == ./. ;
89112 in
90- if builtins . hasAttr "nixpkgs" sources
91- then sourcesNixpkgs
92- else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
113+ if builtins . hasAttr "nixpkgs" sources then
114+ sourcesNixpkgs
115+ else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
93116 import <nixpkgs> { }
94117 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- '' ;
118+ abort ''
119+ Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
120+ add a package called "nixpkgs" to your sources.json.
121+ '' ;
100122
101123 # The actual fetching function.
102- fetch = pkgs : name : spec :
124+ fetch =
125+ pkgs : name : spec :
103126
104- if ! builtins . hasAttr "type" spec then
127+ if ! builtins . hasAttr "type" spec then
105128 abort "ERROR: niv spec ${ name } does not have a 'type' attribute"
106- else if spec . type == "file" then fetch_file pkgs name spec
107- else if spec . type == "tarball" then fetch_tarball pkgs name spec
108- else if spec . type == "git" then fetch_git name spec
109- else if spec . type == "local" then fetch_local spec
110- else if spec . type == "builtin-tarball" then fetch_builtin-tarball name
111- else if spec . type == "builtin-url" then fetch_builtin-url name
129+ else if spec . type == "file" then
130+ fetch_file pkgs name spec
131+ else if spec . type == "tarball" then
132+ fetch_tarball pkgs name spec
133+ else if spec . type == "git" then
134+ fetch_git name spec
135+ else if spec . type == "local" then
136+ fetch_local spec
137+ else if spec . type == "builtin-tarball" then
138+ fetch_builtin-tarball name
139+ else if spec . type == "builtin-url" then
140+ fetch_builtin-url name
112141 else
113142 abort "ERROR: niv spec ${ name } has unknown type ${ builtins . toJSON spec . type } " ;
114143
115144 # If the environment variable NIV_OVERRIDE_${name} is set, then use
116145 # the path directly as opposed to the fetched source.
117- replace = name : drv :
146+ replace =
147+ name : drv :
118148 let
119149 saneName = stringAsChars ( c : if ( builtins . match "[a-zA-Z0-9]" c ) == null then "_" else c ) name ;
120150 ersatz = builtins . getEnv "NIV_OVERRIDE_${ saneName } " ;
121151 in
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 } " ;
152+ if ersatz == "" then
153+ drv
154+ else
155+ # this turns the string into an actual Nix path (for both absolute and
156+ # relative paths)
157+ if builtins . substring 0 1 ersatz == "/" then
158+ /. + ersatz
159+ else
160+ /. + builtins . getEnv "PWD" + "/${ ersatz } " ;
126161
127162 # Ports of functions for older nix versions
128163
129164 # a Nix version of mapAttrs if the built-in doesn't exist
130- mapAttrs = builtins . mapAttrs or (
131- f : set : with builtins ;
132- listToAttrs ( map ( attr : { name = attr ; value = f attr set . ${ attr } ; } ) ( attrNames set ) )
133- ) ;
165+ mapAttrs =
166+ builtins . mapAttrs or (
167+ f : set :
168+ with builtins ;
169+ listToAttrs (
170+ map ( attr : {
171+ name = attr ;
172+ value = f attr set . ${ attr } ;
173+ } ) ( attrNames set )
174+ )
175+ ) ;
134176
135177 # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
136- range = first : last : if first > last then [ ] else builtins . genList ( n : first + n ) ( last - first + 1 ) ;
178+ range =
179+ first : last : if first > last then [ ] else builtins . genList ( n : first + n ) ( last - first + 1 ) ;
137180
138181 # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
139182 stringToCharacters = s : map ( p : builtins . substring p 1 s ) ( range 0 ( builtins . stringLength s - 1 ) ) ;
147190 optionalAttrs = cond : as : if cond then as else { } ;
148191
149192 # fetchTarball version that is compatible between all the versions of Nix
150- builtins_fetchTarball = { url , name ? null , sha256 } @attrs :
193+ builtins_fetchTarball =
194+ {
195+ url ,
196+ name ? null ,
197+ sha256 ,
198+ } @attrs :
151199 let
152200 inherit ( builtins ) lessThan nixVersion fetchTarball ;
153201 in
157205 fetchTarball attrs ;
158206
159207 # fetchurl version that is compatible between all the versions of Nix
160- builtins_fetchurl = { url , name ? null , sha256 } @attrs :
208+ builtins_fetchurl =
209+ {
210+ url ,
211+ name ? null ,
212+ sha256 ,
213+ } @attrs :
161214 let
162215 inherit ( builtins ) lessThan nixVersion fetchurl ;
163216 in
@@ -167,26 +220,25 @@ let
167220 fetchurl attrs ;
168221
169222 # Create the final "sources" from the config
170- mkSources = config :
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 ;
223+ mkSources =
224+ config :
225+ mapAttrs (
226+ name : spec :
227+ if builtins . hasAttr "outPath" spec then
228+ abort "The values in sources.json should not have an 'outPath' attribute"
229+ else
230+ spec // { outPath = replace name ( fetch config . pkgs name spec ) ; }
231+ ) config . sources ;
182232
183233 # The "config" used by the fetchers
184234 mkConfig =
185- { sourcesFile ? if builtins . pathExists ./sources.json then ./sources.json else null
186- , sources ? if sourcesFile == null then { } else builtins . fromJSON ( builtins . readFile sourcesFile )
187- , system ? builtins . currentSystem
188- , pkgs ? mkPkgs sources system
189- } : rec {
235+ {
236+ sourcesFile ? if builtins . pathExists ./sources.json then ./sources.json else null ,
237+ sources ? if sourcesFile == null then { } else builtins . fromJSON ( builtins . readFile sourcesFile ) ,
238+ system ? builtins . currentSystem ,
239+ pkgs ? mkPkgs sources system ,
240+ } :
241+ rec {
190242 # The sources, i.e. the attribute set of spec name to spec
191243 inherit sources ;
192244
0 commit comments