mirror of
https://github.com/nmattia/niv.git
synced 2024-09-18 19:07:19 +03:00
Don't needlessly evaluate <nixpkgs>
This changes the logic to make sure the first `if` branch -- which pulls nixpkgs from sources.json -- is evaluated first. Moreover the `<nixpkgs>` check is changed to avoid actually evaluating `<nixpkgs>`.
This commit is contained in:
parent
c8f74f44b5
commit
13598ef956
@ -49,26 +49,22 @@ let
|
||||
|
||||
# The set of packages used when specs are fetched using non-builtins.
|
||||
mkPkgs = sources:
|
||||
if hasNixpkgsPath
|
||||
then
|
||||
if hasThisAsNixpkgsPath
|
||||
then import (builtins_fetchTarball { inherit (mkNixpkgs sources) url sha256; }) {}
|
||||
else import <nixpkgs> {}
|
||||
else
|
||||
import (builtins_fetchTarball { inherit (mkNixpkgs sources) url sha256; }) {};
|
||||
|
||||
mkNixpkgs = sources:
|
||||
if builtins.hasAttr "nixpkgs" sources
|
||||
then sources.nixpkgs
|
||||
else abort
|
||||
''
|
||||
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
|
||||
add a package called "nixpkgs" to your sources.json.
|
||||
'';
|
||||
|
||||
hasNixpkgsPath = (builtins.tryEval <nixpkgs>).success;
|
||||
hasThisAsNixpkgsPath =
|
||||
(builtins.tryEval <nixpkgs>).success && <nixpkgs> == ./.;
|
||||
let
|
||||
sourcesNixpkgs =
|
||||
import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) {};
|
||||
hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
|
||||
hasThisAsNixpkgsPath = <nixpkgs> == ./.;
|
||||
in
|
||||
if builtins.hasAttr "nixpkgs" sources
|
||||
then sourcesNixpkgs
|
||||
else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
|
||||
import <nixpkgs> {}
|
||||
else
|
||||
abort
|
||||
''
|
||||
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
|
||||
add a package called "nixpkgs" to your sources.json.
|
||||
'';
|
||||
|
||||
# The actual fetching function.
|
||||
fetch = pkgs: name: spec:
|
||||
|
@ -146,6 +146,7 @@ data SourcesNixVersion
|
||||
| V13
|
||||
| V14
|
||||
| V15
|
||||
| V16
|
||||
deriving stock (Bounded, Enum, Eq)
|
||||
|
||||
-- | A user friendly version
|
||||
@ -166,6 +167,7 @@ sourcesVersionToText = \case
|
||||
V13 -> "13"
|
||||
V14 -> "14"
|
||||
V15 -> "15"
|
||||
V16 -> "16"
|
||||
|
||||
latestVersionMD5 :: T.Text
|
||||
latestVersionMD5 = sourcesVersionToMD5 maxBound
|
||||
@ -193,6 +195,7 @@ sourcesVersionToMD5 = \case
|
||||
V13 -> "5e23c56b92eaade4e664cb16dcac1e0a"
|
||||
V14 -> "b470e235e7bcbf106d243fea90b6cfc9"
|
||||
V15 -> "dc11af910773ec9b4e505e0f49ebcfd2"
|
||||
V16 -> "2d93c52cab8e960e767a79af05ca572a"
|
||||
|
||||
-- | The MD5 sum of ./nix/sources.nix
|
||||
sourcesNixMD5 :: IO T.Text
|
||||
|
Loading…
Reference in New Issue
Block a user