diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-01-24 22:05:11 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2020-01-24 22:05:11 +0100 |
commit | cc22cf662b6998abbb5a08afce7678c5b149d204 (patch) | |
tree | 27c825e9d03e777442902da8ab1e9b90ecb9e7fc /tests | |
parent | 2b8ca654b058cf18101a5243090706be97930275 (diff) |
Respect lock files of inputs + fine-grained lock file control
When computing a lock file, we now respect the lock files of flake
inputs. This is important for usability / reproducibility. For
example, the 'nixops' flake depends on the 'nixops-aws' and
'nixops-hetzner' repositories. So when the 'nixops' flake is used in
another flake, we want the versions of 'nixops-aws' and
'nixops-hetzner' locked by the the 'nixops' flake because those
presumably have been tested.
This can lead to a proliferation of versions of flakes like 'nixpkgs'
(since every flake's lock file could depend on a different version of
'nixpkgs'). This is not a major issue when using Nixpkgs overlays or
NixOS modules, since then the top-level flake composes those
overlays/modules into *its* version of Nixpkgs and all other versions
are ignored. Lock file computation has been made a bit more lazy so it
won't try to fetch all those versions of 'nixpkgs'.
However, in case it's necessary to minimize flake versions, there now
are two input attributes that allow this. First, you can copy an input
from another flake, as follows:
inputs.nixpkgs.follows = "dwarffs/nixpkgs";
This states that the calling flake's 'nixpkgs' input shall be the same
as the 'nixpkgs' input of the 'dwarffs' input.
Second, you can override inputs of inputs:
inputs.nixpkgs.url = github:edolstra/nixpkgs/<hash>;
inputs.nixops.inputs.nixpkgs.url = github:edolstra/nixpkgs/<hash>;
or equivalently, using 'follows':
inputs.nixpkgs.url = github:edolstra/nixpkgs/<hash>;
inputs.nixops.inputs.nixpkgs.follows = "nixpkgs";
This states that the 'nixpkgs' input of the 'nixops' input shall be
the same as the calling flake's 'nixpkgs' input.
Finally, at '-v' Nix now prints the changes to the lock file, e.g.
$ nix flake update ~/Misc/eelco-configurations/hagbard
inputs of flake 'git+file:///home/eelco/Misc/eelco-configurations?subdir=hagbard' changed:
updated 'nixpkgs': 'github:edolstra/nixpkgs/7845bf5f4b3013df1cf036e9c9c3a55a30331db9' -> 'github:edolstra/nixpkgs/03f3def66a104a221aac8b751eeb7075374848fd'
removed 'nixops'
removed 'nixops/nixops-aws'
removed 'nixops/nixops-hetzner'
removed 'nixops/nixpkgs'
Diffstat (limited to 'tests')
-rw-r--r-- | tests/flakes.sh | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/flakes.sh b/tests/flakes.sh index 337645fb4..f3409647e 100644 --- a/tests/flakes.sh +++ b/tests/flakes.sh @@ -354,7 +354,9 @@ nix flake remove --flake-registry $registry flake1 (cd $flake7Dir && nix flake init) git -C $flake7Dir add flake.nix nix flake --flake-registry $registry check $flake7Dir +git -C $flake7Dir commit -m 'Initial' +# Test 'nix flake clone'. rm -rf $TEST_ROOT/flake1-v2 nix flake clone --flake-registry $registry flake1 --dest $TEST_ROOT/flake1-v2 [ -e $TEST_ROOT/flake1-v2/flake.nix ] @@ -443,3 +445,77 @@ cat > $flake3Dir/flake.nix <<EOF EOF (! nix flake check --flake-registry $registry $flake3Dir) + +# Test 'follows' inputs. +cat > $flake3Dir/flake.nix <<EOF +{ + edition = 201909; + + inputs.foo.url = flake:flake1; + inputs.bar.follows = "foo"; + + outputs = { self, foo, bar }: { + }; +} +EOF + +nix flake update --flake-registry $registry $flake3Dir +[[ $(jq .inputs.foo.url $flake3Dir/flake.lock) = $(jq .inputs.bar.url $flake3Dir/flake.lock) ]] + +cat > $flake3Dir/flake.nix <<EOF +{ + edition = 201909; + + inputs.bar.follows = "flake2/flake1"; + + outputs = { self, flake2, bar }: { + }; +} +EOF + +nix flake update --flake-registry $registry $flake3Dir +[[ $(jq .inputs.bar.url $flake3Dir/flake.lock) =~ flake1 ]] + +cat > $flake3Dir/flake.nix <<EOF +{ + edition = 201909; + + inputs.bar.follows = "flake2"; + + outputs = { self, flake2, bar }: { + }; +} +EOF + +nix flake update --flake-registry $registry $flake3Dir +[[ $(jq .inputs.bar.url $flake3Dir/flake.lock) =~ flake2 ]] + +# Test overriding inputs of inputs. +cat > $flake3Dir/flake.nix <<EOF +{ + edition = 201909; + + inputs.flake2.inputs.flake1.url = git+file://$flake7Dir; + + outputs = { self, flake2 }: { + }; +} +EOF + +nix flake update --flake-registry $registry $flake3Dir +[[ $(jq .inputs.flake2.inputs.flake1.url $flake3Dir/flake.lock) =~ flake7 ]] + +cat > $flake3Dir/flake.nix <<EOF +{ + edition = 201909; + + inputs.flake2.inputs.flake1.follows = "foo"; + inputs.foo.url = git+file://$flake7Dir; + + outputs = { self, flake2 }: { + }; +} +EOF + +nix flake update --flake-registry $registry $flake3Dir --recreate-lock-file +[[ $(jq .inputs.flake2.inputs.flake1.url $flake3Dir/flake.lock) =~ flake7 ]] |