From 13598ef9568e49fb926c9fe38a6d4af847a7924b Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Fri, 17 Jan 2020 10:59:09 +0100 Subject: [PATCH] Don't needlessly evaluate This changes the logic to make sure the first `if` branch -- which pulls nixpkgs from sources.json -- is evaluated first. Moreover the `` check is changed to avoid actually evaluating ``. --- nix/sources.nix | 36 ++++++++++++++++-------------------- src/Niv/Sources.hs | 3 +++ 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/nix/sources.nix b/nix/sources.nix index 6e2bf23..8a725cb 100644 --- a/nix/sources.nix +++ b/nix/sources.nix @@ -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 {} - else - import (builtins_fetchTarball { inherit (mkNixpkgs sources) url sha256; }) {}; - - mkNixpkgs = sources: - if builtins.hasAttr "nixpkgs" sources - then sources.nixpkgs - else abort - '' - Please specify either (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; - - hasNixpkgsPath = (builtins.tryEval ).success; - hasThisAsNixpkgsPath = - (builtins.tryEval ).success && == ./.; + let + sourcesNixpkgs = + import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) {}; + hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; + hasThisAsNixpkgsPath = == ./.; + in + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import {} + else + abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; # The actual fetching function. fetch = pkgs: name: spec: diff --git a/src/Niv/Sources.hs b/src/Niv/Sources.hs index d16eee2..1386d3a 100644 --- a/src/Niv/Sources.hs +++ b/src/Niv/Sources.hs @@ -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