···7373 else
7474 abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}";
75757676+ # If the environment variable NIV_OVERRIDE_${name} is set, then use
7777+ # the path directly as opposed to the fetched source.
7878+ replace = name: drv:
7979+ let
8080+ saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name;
8181+ ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}";
8282+ in
8383+ if ersatz == "" then drv else ersatz;
8484+7685 # Ports of functions for older nix versions
77867887 # a Nix version of mapAttrs if the built-in doesn't exist
···119128 then abort
120129 "The values in sources.json should not have an 'outPath' attribute"
121130 else
122122- spec // { outPath = fetch config.pkgs name spec; }
131131+ spec // { outPath = replace name (fetch config.pkgs name spec); }
123132 ) config.sources;
124133125134 # The "config" used by the fetchers
126135 mkConfig =
127127- { sourcesFile ? ./sources.json
128128- , sources ? builtins.fromJSON (builtins.readFile sourcesFile)
136136+ { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null
137137+ , sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile)
129138 , pkgs ? mkPkgs sources
130139 }: rec {
131140 # The sources, i.e. the attribute set of spec name to spec
···134143 # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers
135144 inherit pkgs;
136145 };
146146+137147in
138148mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }