diff options
Diffstat (limited to 'tests/flakes.sh')
-rw-r--r-- | tests/flakes.sh | 150 |
1 files changed, 100 insertions, 50 deletions
diff --git a/tests/flakes.sh b/tests/flakes.sh index 26cdf27b7..ea629ae70 100644 --- a/tests/flakes.sh +++ b/tests/flakes.sh @@ -5,11 +5,6 @@ if [[ -z $(type -p git) ]]; then exit 99 fi -if [[ -z $(type -p hg) ]]; then - echo "Mercurial not installed; skipping flake tests" - exit 99 -fi - clearStore rm -rf $TEST_HOME/.cache $TEST_HOME/.config @@ -46,8 +41,10 @@ cat > $flake1Dir/flake.nix <<EOF description = "Bla bla"; outputs = inputs: rec { - packages.$system.foo = import ./simple.nix; - defaultPackage.$system = packages.$system.foo; + packages.$system = rec { + foo = import ./simple.nix; + default = foo; + }; # To test "nix flake init". legacyPackages.x86_64-linux.hello = import ./simple.nix; @@ -133,7 +130,7 @@ hash2=$(nix flake metadata flake1 --json --refresh | jq -r .revision) nix build -o $TEST_ROOT/result flake1#foo [[ -e $TEST_ROOT/result/hello ]] -# Test defaultPackage. +# Test packages.default. nix build -o $TEST_ROOT/result flake1 [[ -e $TEST_ROOT/result/hello ]] @@ -145,11 +142,11 @@ nix build -o $flake1Dir/result git+file://$flake1Dir nix path-info $flake1Dir/result # 'getFlake' on a mutable flakeref should fail in pure mode, but succeed in impure mode. -(! nix build -o $TEST_ROOT/result --expr "(builtins.getFlake \"$flake1Dir\").defaultPackage.$system") -nix build -o $TEST_ROOT/result --expr "(builtins.getFlake \"$flake1Dir\").defaultPackage.$system" --impure +(! nix build -o $TEST_ROOT/result --expr "(builtins.getFlake \"$flake1Dir\").packages.$system.default") +nix build -o $TEST_ROOT/result --expr "(builtins.getFlake \"$flake1Dir\").packages.$system.default" --impure # 'getFlake' on an immutable flakeref should succeed even in pure mode. -nix build -o $TEST_ROOT/result --expr "(builtins.getFlake \"git+file://$flake1Dir?rev=$hash2\").defaultPackage.$system" +nix build -o $TEST_ROOT/result --expr "(builtins.getFlake \"git+file://$flake1Dir?rev=$hash2\").packages.$system.default" # Building a flake with an unlocked dependency should fail in pure mode. (! nix build -o $TEST_ROOT/result flake2#bar --no-registries) @@ -254,6 +251,14 @@ cat > $flake3Dir/flake.nix <<EOF url = git+file://$nonFlakeDir; flake = false; }; + nonFlakeFile = { + url = path://$nonFlakeDir/README.md; + flake = false; + }; + nonFlakeFile2 = { + url = "$nonFlakeDir/README.md"; + flake = false; + }; }; description = "Fnord"; @@ -266,8 +271,12 @@ cat > $flake3Dir/flake.nix <<EOF mkDerivation { inherit system; name = "fnord"; + dummy = builtins.readFile (builtins.path { name = "source"; path = ./.; filter = path: type: baseNameOf path == "config.nix"; } + "/config.nix"); + dummy2 = builtins.readFile (builtins.path { name = "source"; path = inputs.flake1; filter = path: type: baseNameOf path == "simple.nix"; } + "/simple.nix"); buildCommand = '' cat \${inputs.nonFlake}/README.md > \$out + [[ \$(cat \${inputs.nonFlake}/README.md) = \$(cat \${inputs.nonFlakeFile}) ]] + [[ \${inputs.nonFlakeFile} = \${inputs.nonFlakeFile2} ]] ''; }; }; @@ -363,13 +372,13 @@ cat > $templatesDir/flake.nix <<EOF description = "Some templates"; outputs = { self }: { - templates = { + templates = rec { trivial = { path = ./trivial; description = "A trivial flake"; }; + default = trivial; }; - defaultTemplate = self.templates.trivial; }; } EOF @@ -381,8 +390,10 @@ cat > $templatesDir/trivial/flake.nix <<EOF description = "A flake for building Hello World"; outputs = { self, nixpkgs }: { - packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello; - defaultPackage.x86_64-linux = self.packages.x86_64-linux.hello; + packages.x86_64-linux = rec { + hello = nixpkgs.legacyPackages.x86_64-linux.hello; + default = hello; + }; }; } EOF @@ -489,17 +500,15 @@ EOF cat > $flake3Dir/flake.nix <<EOF { outputs = { flake1, self }: { - defaultPackage = { - system-1 = "foo"; - system-2 = "bar"; - }; + packages.system-1.default = "foo"; + packages.system-2.default = "bar"; }; } EOF checkRes=$(nix flake check --keep-going $flake3Dir 2>&1 && fail "nix flake check should have failed" || true) -echo "$checkRes" | grep -q "defaultPackage.system-1" -echo "$checkRes" | grep -q "defaultPackage.system-2" +echo "$checkRes" | grep -q "packages.system-1.default" +echo "$checkRes" | grep -q "packages.system-2.default" # Test 'follows' inputs. cat > $flake3Dir/flake.nix <<EOF @@ -579,45 +588,52 @@ nix build -o $TEST_ROOT/result git+file://$flakeGitBare # Test Mercurial flakes. rm -rf $flake5Dir -hg init $flake5Dir +mkdir $flake5Dir cat > $flake5Dir/flake.nix <<EOF { outputs = { self, flake1 }: { - defaultPackage.$system = flake1.defaultPackage.$system; - + packages.$system.default = flake1.packages.$system.default; expr = assert builtins.pathExists ./flake.lock; 123; }; } EOF -hg add $flake5Dir/flake.nix -hg commit --config ui.username=foobar@example.org $flake5Dir -m 'Initial commit' +if [[ -n $(type -p hg) ]]; then + hg init $flake5Dir -nix build -o $TEST_ROOT/result hg+file://$flake5Dir -[[ -e $TEST_ROOT/result/hello ]] + hg add $flake5Dir/flake.nix + hg commit --config ui.username=foobar@example.org $flake5Dir -m 'Initial commit' + + nix build -o $TEST_ROOT/result hg+file://$flake5Dir + [[ -e $TEST_ROOT/result/hello ]] -(! nix flake metadata --json hg+file://$flake5Dir | jq -e -r .revision) + (! nix flake metadata --json hg+file://$flake5Dir | jq -e -r .revision) -nix eval hg+file://$flake5Dir#expr + nix eval hg+file://$flake5Dir#expr -nix eval hg+file://$flake5Dir#expr + nix eval hg+file://$flake5Dir#expr -(! nix eval hg+file://$flake5Dir#expr --no-allow-dirty) + (! nix eval hg+file://$flake5Dir#expr --no-allow-dirty) -(! nix flake metadata --json hg+file://$flake5Dir | jq -e -r .revision) + (! nix flake metadata --json hg+file://$flake5Dir | jq -e -r .revision) -hg commit --config ui.username=foobar@example.org $flake5Dir -m 'Add lock file' + hg commit --config ui.username=foobar@example.org $flake5Dir -m 'Add lock file' -nix flake metadata --json hg+file://$flake5Dir --refresh | jq -e -r .revision -nix flake metadata --json hg+file://$flake5Dir -[[ $(nix flake metadata --json hg+file://$flake5Dir | jq -e -r .revCount) = 1 ]] + nix flake metadata --json hg+file://$flake5Dir --refresh | jq -e -r .revision + nix flake metadata --json hg+file://$flake5Dir + [[ $(nix flake metadata --json hg+file://$flake5Dir | jq -e -r .revCount) = 1 ]] -nix build -o $TEST_ROOT/result hg+file://$flake5Dir --no-registries --no-allow-dirty -nix build -o $TEST_ROOT/result hg+file://$flake5Dir --no-use-registries --no-allow-dirty + nix build -o $TEST_ROOT/result hg+file://$flake5Dir --no-registries --no-allow-dirty + nix build -o $TEST_ROOT/result hg+file://$flake5Dir --no-use-registries --no-allow-dirty +fi -# Test tarball flakes -tar cfz $TEST_ROOT/flake.tar.gz -C $TEST_ROOT --exclude .hg flake5 +# Test path flakes. +rm -rf $flake5Dir/.hg $flake5Dir/flake.lock +nix flake lock path://$flake5Dir + +# Test tarball flakes. +tar cfz $TEST_ROOT/flake.tar.gz -C $TEST_ROOT flake5 nix build -o $TEST_ROOT/result file://$TEST_ROOT/flake.tar.gz @@ -632,8 +648,8 @@ nix build -o $TEST_ROOT/result "file://$TEST_ROOT/flake.tar.gz?narHash=sha256-qQ # Test --override-input. git -C $flake3Dir reset --hard -nix flake lock $flake3Dir --override-input flake2/flake1 flake5 -vvvvv -[[ $(jq .nodes.flake1_2.locked.url $flake3Dir/flake.lock) =~ flake5 ]] +nix flake lock $flake3Dir --override-input flake2/flake1 file://$TEST_ROOT/flake.tar.gz -vvvvv +[[ $(jq .nodes.flake1_2.locked.url $flake3Dir/flake.lock) =~ flake.tar.gz ]] nix flake lock $flake3Dir --override-input flake2/flake1 flake1 [[ $(jq -r .nodes.flake1_2.locked.rev $flake3Dir/flake.lock) =~ $hash2 ]] @@ -702,11 +718,10 @@ cat > $flakeFollowsA/flake.nix <<EOF inputs = { B = { url = "path:./flakeB"; - inputs.foobar.follows = "D"; + inputs.foobar.follows = "foobar"; }; - D.url = "path:./flakeD"; - foobar.url = "path:./flakeE"; + foobar.url = "path:$flakeFollowsA/flakeE"; }; outputs = { ... }: {}; } @@ -716,7 +731,8 @@ cat > $flakeFollowsB/flake.nix <<EOF { description = "Flake B"; inputs = { - foobar.url = "path:./../flakeE"; + foobar.url = "path:$flakeFollowsA/flakeE"; + goodoo.follows = "C/goodoo"; C = { url = "path:./flakeC"; inputs.foobar.follows = "foobar"; @@ -730,7 +746,8 @@ cat > $flakeFollowsC/flake.nix <<EOF { description = "Flake C"; inputs = { - foobar.url = "path:./../../flakeE"; + foobar.url = "path:$flakeFollowsA/flakeE"; + goodoo.follows = "foobar"; }; outputs = { ... }: {}; } @@ -746,7 +763,7 @@ EOF cat > $flakeFollowsE/flake.nix <<EOF { - description = "Flake D"; + description = "Flake E"; inputs = {}; outputs = { ... }: {}; } @@ -755,12 +772,45 @@ EOF git -C $flakeFollowsA add flake.nix flakeB/flake.nix \ flakeB/flakeC/flake.nix flakeD/flake.nix flakeE/flake.nix +nix flake metadata $flakeFollowsA + +nix flake update $flakeFollowsA + +oldLock="$(cat "$flakeFollowsA/flake.lock")" + +# Ensure that locking twice doesn't change anything + nix flake lock $flakeFollowsA +newLock="$(cat "$flakeFollowsA/flake.lock")" + +diff <(echo "$newLock") <(echo "$oldLock") + [[ $(jq -c .nodes.B.inputs.C $flakeFollowsA/flake.lock) = '"C"' ]] -[[ $(jq -c .nodes.B.inputs.foobar $flakeFollowsA/flake.lock) = '["D"]' ]] +[[ $(jq -c .nodes.B.inputs.foobar $flakeFollowsA/flake.lock) = '["foobar"]' ]] [[ $(jq -c .nodes.C.inputs.foobar $flakeFollowsA/flake.lock) = '["B","foobar"]' ]] +# Ensure removing follows from flake.nix removes them from the lockfile + +cat > $flakeFollowsA/flake.nix <<EOF +{ + description = "Flake A"; + inputs = { + B = { + url = "path:./flakeB"; + inputs.nonFlake.follows = "D"; + }; + D.url = "path:./flakeD"; + }; + outputs = { ... }: {}; +} +EOF + +nix flake lock $flakeFollowsA + +[[ $(jq -c .nodes.B.inputs.foobar $flakeFollowsA/flake.lock) = '"foobar"' ]] +jq -r -c '.nodes | keys | .[]' $flakeFollowsA/flake.lock | grep "^foobar$" + # Ensure a relative path is not allowed to go outside the store path cat > $flakeFollowsA/flake.nix <<EOF { |