mirror of
https://github.com/NixOS/nix.git
synced 2024-11-21 14:22:29 +00:00
Merge pull request #11926 from DeterminateSystems/split-flake-tests
Break up tests/functional/flakes/flakes.sh
This commit is contained in:
commit
b767987942
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -220,4 +220,4 @@ jobs:
|
||||
path: flake-regressions/tests
|
||||
- uses: DeterminateSystems/nix-installer-action@main
|
||||
- uses: DeterminateSystems/magic-nix-cache-action@main
|
||||
- run: nix build --out-link ./new-nix && PATH=$(pwd)/new-nix/bin:$PATH MAX_FLAKES=25 flake-regressions/eval-all.sh
|
||||
- run: nix build -L --out-link ./new-nix && PATH=$(pwd)/new-nix/bin:$PATH MAX_FLAKES=25 flake-regressions/eval-all.sh
|
||||
|
44
tests/functional/flakes/commit-lock-file-summary.sh
Normal file
44
tests/functional/flakes/commit-lock-file-summary.sh
Normal file
@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
source ./common.sh
|
||||
|
||||
TODO_NixOS
|
||||
|
||||
createFlake1
|
||||
|
||||
lockfileSummaryFlake=$TEST_ROOT/lockfileSummaryFlake
|
||||
createGitRepo "$lockfileSummaryFlake" "--initial-branch=main"
|
||||
|
||||
# Test that the --commit-lock-file-summary flag and its alias work
|
||||
cat > "$lockfileSummaryFlake/flake.nix" <<EOF
|
||||
{
|
||||
inputs = {
|
||||
flake1.url = "git+file://$flake1Dir";
|
||||
};
|
||||
|
||||
description = "lockfileSummaryFlake";
|
||||
|
||||
outputs = inputs: rec {
|
||||
packages.$system.default = inputs.flake1.packages.$system.foo;
|
||||
};
|
||||
}
|
||||
EOF
|
||||
|
||||
git -C "$lockfileSummaryFlake" add flake.nix
|
||||
git -C "$lockfileSummaryFlake" commit -m 'Add lockfileSummaryFlake'
|
||||
|
||||
testSummary="test summary 1"
|
||||
nix flake lock "$lockfileSummaryFlake" --commit-lock-file --commit-lock-file-summary "$testSummary"
|
||||
[[ -e "$lockfileSummaryFlake/flake.lock" ]]
|
||||
[[ -z $(git -C "$lockfileSummaryFlake" diff main || echo failed) ]]
|
||||
[[ "$(git -C "$lockfileSummaryFlake" log --format=%s -n 1)" = "$testSummary" ]]
|
||||
|
||||
git -C "$lockfileSummaryFlake" rm :/:flake.lock
|
||||
git -C "$lockfileSummaryFlake" commit -m "remove flake.lock"
|
||||
testSummary="test summary 2"
|
||||
# NOTE(cole-h): We use `--option` here because Nix settings do not currently support flag-ifying the
|
||||
# alias of a setting: https://github.com/NixOS/nix/issues/10989
|
||||
nix flake lock "$lockfileSummaryFlake" --commit-lock-file --option commit-lockfile-summary "$testSummary"
|
||||
[[ -e "$lockfileSummaryFlake/flake.lock" ]]
|
||||
[[ -z $(git -C "$lockfileSummaryFlake" diff main || echo failed) ]]
|
||||
[[ "$(git -C "$lockfileSummaryFlake" log --format=%s -n 1)" = "$testSummary" ]]
|
@ -38,12 +38,44 @@ EOF
|
||||
}
|
||||
|
||||
createSimpleGitFlake() {
|
||||
requireGit
|
||||
local flakeDir="$1"
|
||||
writeSimpleFlake "$flakeDir"
|
||||
git -C "$flakeDir" add flake.nix simple.nix shell.nix simple.builder.sh config.nix
|
||||
git -C "$flakeDir" commit -m 'Initial'
|
||||
}
|
||||
|
||||
# Create a simple Git flake and add it to the registry as "flake1".
|
||||
createFlake1() {
|
||||
flake1Dir="$TEST_ROOT/flake1"
|
||||
createGitRepo "$flake1Dir" ""
|
||||
createSimpleGitFlake "$flake1Dir"
|
||||
nix registry add --registry "$registry" flake1 "git+file://$flake1Dir"
|
||||
}
|
||||
|
||||
createFlake2() {
|
||||
flake2Dir="$TEST_ROOT/flake 2"
|
||||
percentEncodedFlake2Dir="$TEST_ROOT/flake%202"
|
||||
|
||||
# Give one repo a non-main initial branch.
|
||||
createGitRepo "$flake2Dir" "--initial-branch=main"
|
||||
|
||||
cat > "$flake2Dir/flake.nix" <<EOF
|
||||
{
|
||||
description = "Fnord";
|
||||
|
||||
outputs = { self, flake1 }: rec {
|
||||
packages.$system.bar = flake1.packages.$system.foo;
|
||||
};
|
||||
}
|
||||
EOF
|
||||
|
||||
git -C "$flake2Dir" add flake.nix
|
||||
git -C "$flake2Dir" commit -m 'Initial'
|
||||
|
||||
nix registry add --registry "$registry" flake2 "git+file://$percentEncodedFlake2Dir"
|
||||
}
|
||||
|
||||
writeDependentFlake() {
|
||||
local flakeDir="$1"
|
||||
cat > "$flakeDir/flake.nix" <<EOF
|
||||
|
@ -2,11 +2,8 @@
|
||||
|
||||
source ./common.sh
|
||||
|
||||
requireGit
|
||||
|
||||
repoDir="$TEST_ROOT/repo"
|
||||
createGitRepo "$repoDir"
|
||||
createSimpleGitFlake "$repoDir"
|
||||
createFlake1
|
||||
repoDir="$flake1Dir"
|
||||
|
||||
# Check that a flakeref without a query is accepted correctly.
|
||||
expectStderr 0 nix --offline build --dry-run "git+file://$repoDir#foo"
|
||||
|
@ -2,12 +2,7 @@
|
||||
|
||||
source ./common.sh
|
||||
|
||||
requireGit
|
||||
|
||||
flake1Dir=$TEST_ROOT/flake1
|
||||
|
||||
createGitRepo "$flake1Dir"
|
||||
createSimpleGitFlake "$flake1Dir"
|
||||
createFlake1
|
||||
|
||||
export EDITOR=cat
|
||||
nix edit "$flake1Dir#" | grepQuiet simple.builder.sh
|
||||
|
@ -9,46 +9,20 @@ requireGit
|
||||
clearStore
|
||||
rm -rf $TEST_HOME/.cache $TEST_HOME/.config
|
||||
|
||||
flake1Dir=$TEST_ROOT/flake1
|
||||
flake2Dir=$TEST_ROOT/flake\ 2
|
||||
percentEncodedFlake2Dir=$TEST_ROOT/flake%202
|
||||
createFlake1
|
||||
createFlake2
|
||||
|
||||
flake3Dir=$TEST_ROOT/flake%20
|
||||
percentEncodedFlake3Dir=$TEST_ROOT/flake%2520
|
||||
flake5Dir=$TEST_ROOT/flake5
|
||||
flake7Dir=$TEST_ROOT/flake7
|
||||
nonFlakeDir=$TEST_ROOT/nonFlake
|
||||
badFlakeDir=$TEST_ROOT/badFlake
|
||||
flakeGitBare=$TEST_ROOT/flakeGitBare
|
||||
lockfileSummaryFlake=$TEST_ROOT/lockfileSummaryFlake
|
||||
|
||||
for repo in "$flake1Dir" "$flake2Dir" "$flake3Dir" "$flake7Dir" "$nonFlakeDir" "$lockfileSummaryFlake"; do
|
||||
# Give one repo a non-main initial branch.
|
||||
extraArgs=
|
||||
if [[ "$repo" == "$flake2Dir" ]]; then
|
||||
extraArgs="--initial-branch=main"
|
||||
fi
|
||||
if [[ "$repo" == "$lockfileSummaryFlake" ]]; then
|
||||
extraArgs="--initial-branch=main"
|
||||
fi
|
||||
|
||||
createGitRepo "$repo" "$extraArgs"
|
||||
for repo in "$flake3Dir" "$flake7Dir"; do
|
||||
createGitRepo "$repo" ""
|
||||
done
|
||||
|
||||
createSimpleGitFlake "$flake1Dir"
|
||||
|
||||
cat > "$flake2Dir/flake.nix" <<EOF
|
||||
{
|
||||
description = "Fnord";
|
||||
|
||||
outputs = { self, flake1 }: rec {
|
||||
packages.$system.bar = flake1.packages.$system.foo;
|
||||
};
|
||||
}
|
||||
EOF
|
||||
|
||||
git -C "$flake2Dir" add flake.nix
|
||||
git -C "$flake2Dir" commit -m 'Initial'
|
||||
|
||||
cat > "$flake3Dir/flake.nix" <<EOF
|
||||
{
|
||||
description = "Fnord";
|
||||
@ -70,113 +44,13 @@ EOF
|
||||
git -C "$flake3Dir" add flake.nix default.nix
|
||||
git -C "$flake3Dir" commit -m 'Initial'
|
||||
|
||||
cat > "$nonFlakeDir/README.md" <<EOF
|
||||
FNORD
|
||||
EOF
|
||||
|
||||
cat > "$nonFlakeDir/shebang.sh" <<EOF
|
||||
#! $(type -P env) nix
|
||||
#! nix --offline shell
|
||||
#! nix flake1#fooScript
|
||||
#! nix --no-write-lock-file --command bash
|
||||
set -ex
|
||||
foo
|
||||
echo "\$@"
|
||||
EOF
|
||||
chmod +x "$nonFlakeDir/shebang.sh"
|
||||
|
||||
git -C "$nonFlakeDir" add README.md shebang.sh
|
||||
git -C "$nonFlakeDir" commit -m 'Initial'
|
||||
|
||||
# this also tests a fairly trivial double backtick quoted string, ``--command``
|
||||
cat > $nonFlakeDir/shebang-comments.sh <<EOF
|
||||
#! $(type -P env) nix
|
||||
# some comments
|
||||
# some comments
|
||||
# some comments
|
||||
#! nix --offline shell
|
||||
#! nix flake1#fooScript
|
||||
#! nix --no-write-lock-file ``--command`` bash
|
||||
foo
|
||||
EOF
|
||||
chmod +x $nonFlakeDir/shebang-comments.sh
|
||||
|
||||
cat > $nonFlakeDir/shebang-different-comments.sh <<EOF
|
||||
#! $(type -P env) nix
|
||||
# some comments
|
||||
// some comments
|
||||
/* some comments
|
||||
* some comments
|
||||
\ some comments
|
||||
% some comments
|
||||
@ some comments
|
||||
-- some comments
|
||||
(* some comments
|
||||
#! nix --offline shell
|
||||
#! nix flake1#fooScript
|
||||
#! nix --no-write-lock-file --command cat
|
||||
foo
|
||||
EOF
|
||||
chmod +x $nonFlakeDir/shebang-different-comments.sh
|
||||
|
||||
cat > $nonFlakeDir/shebang-reject.sh <<EOF
|
||||
#! $(type -P env) nix
|
||||
# some comments
|
||||
# some comments
|
||||
# some comments
|
||||
#! nix --offline shell *
|
||||
#! nix flake1#fooScript
|
||||
#! nix --no-write-lock-file --command bash
|
||||
foo
|
||||
EOF
|
||||
chmod +x $nonFlakeDir/shebang-reject.sh
|
||||
|
||||
cat > $nonFlakeDir/shebang-inline-expr.sh <<EOF
|
||||
#! $(type -P env) nix
|
||||
EOF
|
||||
cat >> $nonFlakeDir/shebang-inline-expr.sh <<"EOF"
|
||||
#! nix --offline shell
|
||||
#! nix --impure --expr ``
|
||||
#! nix let flake = (builtins.getFlake (toString ../flake1)).packages;
|
||||
#! nix fooScript = flake.${builtins.currentSystem}.fooScript;
|
||||
#! nix /* just a comment !@#$%^&*()__+ # */
|
||||
#! nix in fooScript
|
||||
#! nix ``
|
||||
#! nix --no-write-lock-file --command bash
|
||||
set -ex
|
||||
foo
|
||||
echo "$@"
|
||||
EOF
|
||||
chmod +x $nonFlakeDir/shebang-inline-expr.sh
|
||||
|
||||
cat > $nonFlakeDir/fooScript.nix <<"EOF"
|
||||
let flake = (builtins.getFlake (toString ../flake1)).packages;
|
||||
fooScript = flake.${builtins.currentSystem}.fooScript;
|
||||
in fooScript
|
||||
EOF
|
||||
|
||||
cat > $nonFlakeDir/shebang-file.sh <<EOF
|
||||
#! $(type -P env) nix
|
||||
EOF
|
||||
cat >> $nonFlakeDir/shebang-file.sh <<"EOF"
|
||||
#! nix --offline shell
|
||||
#! nix --impure --file ./fooScript.nix
|
||||
#! nix --no-write-lock-file --command bash
|
||||
set -ex
|
||||
foo
|
||||
echo "$@"
|
||||
EOF
|
||||
chmod +x $nonFlakeDir/shebang-file.sh
|
||||
|
||||
# Construct a custom registry, additionally test the --registry flag
|
||||
nix registry add --registry "$registry" flake1 "git+file://$flake1Dir"
|
||||
nix registry add --registry "$registry" flake2 "git+file://$percentEncodedFlake2Dir"
|
||||
nix registry add --registry "$registry" flake3 "git+file://$percentEncodedFlake3Dir"
|
||||
nix registry add --registry "$registry" flake4 flake3
|
||||
nix registry add --registry "$registry" nixpkgs flake1
|
||||
|
||||
# Test 'nix registry list'.
|
||||
[[ $(nix registry list | wc -l) == 5 ]]
|
||||
[[ $(nix registry list | wc -l) == 4 ]]
|
||||
nix registry list | grep '^global'
|
||||
nix registry list | grepInverse '^user' # nothing in user registry
|
||||
|
||||
@ -346,77 +220,8 @@ _NIX_FORCE_HTTP=1 nix build -o "$TEST_ROOT/result" "git+file://$percentEncodedFl
|
||||
mv "$flake1Dir.tmp" "$flake1Dir"
|
||||
mv "$flake2Dir.tmp" "$flake2Dir"
|
||||
|
||||
# Add nonFlakeInputs to flake3.
|
||||
rm "$flake3Dir/flake.nix"
|
||||
|
||||
cat > "$flake3Dir/flake.nix" <<EOF
|
||||
{
|
||||
inputs = {
|
||||
flake1 = {};
|
||||
flake2 = {};
|
||||
nonFlake = {
|
||||
url = git+file://$nonFlakeDir;
|
||||
flake = false;
|
||||
};
|
||||
nonFlakeFile = {
|
||||
url = path://$nonFlakeDir/README.md;
|
||||
flake = false;
|
||||
};
|
||||
nonFlakeFile2 = {
|
||||
url = "$nonFlakeDir/README.md";
|
||||
flake = false;
|
||||
};
|
||||
};
|
||||
|
||||
description = "Fnord";
|
||||
|
||||
outputs = inputs: rec {
|
||||
packages.$system.xyzzy = inputs.flake2.packages.$system.bar;
|
||||
packages.$system.sth = inputs.flake1.packages.$system.foo;
|
||||
packages.$system.fnord =
|
||||
with import ./config.nix;
|
||||
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} ]]
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
EOF
|
||||
|
||||
cp "${config_nix}" "$flake3Dir"
|
||||
|
||||
git -C "$flake3Dir" add flake.nix config.nix
|
||||
git -C "$flake3Dir" commit -m 'Add nonFlakeInputs'
|
||||
|
||||
# Check whether `nix build` works with a lockfile which is missing a
|
||||
# nonFlakeInputs.
|
||||
nix build -o "$TEST_ROOT/result" "$flake3Dir#sth" --commit-lock-file
|
||||
|
||||
nix build -o "$TEST_ROOT/result" flake3#fnord
|
||||
[[ $(cat $TEST_ROOT/result) = FNORD ]]
|
||||
|
||||
# Check whether flake input fetching is lazy: flake3#sth does not
|
||||
# depend on flake2, so this shouldn't fail.
|
||||
rm -rf "$TEST_HOME/.cache"
|
||||
clearStore
|
||||
mv "$flake2Dir" "$flake2Dir.tmp"
|
||||
mv "$nonFlakeDir" "$nonFlakeDir.tmp"
|
||||
nix build -o "$TEST_ROOT/result" flake3#sth
|
||||
(! nix build -o "$TEST_ROOT/result" flake3#xyzzy)
|
||||
(! nix build -o "$TEST_ROOT/result" flake3#fnord)
|
||||
mv "$flake2Dir.tmp" "$flake2Dir"
|
||||
mv "$nonFlakeDir.tmp" "$nonFlakeDir"
|
||||
nix build -o "$TEST_ROOT/result" flake3#xyzzy flake3#fnord
|
||||
|
||||
# Test doing multiple `lookupFlake`s
|
||||
nix build -o "$TEST_ROOT/result" flake4#xyzzy
|
||||
nix build -o "$TEST_ROOT/result" flake3#xyzzy
|
||||
|
||||
# Test 'nix flake update' and --override-flake.
|
||||
nix flake lock "$flake3Dir"
|
||||
@ -425,53 +230,15 @@ nix flake lock "$flake3Dir"
|
||||
nix flake update --flake "$flake3Dir" --override-flake flake2 nixpkgs
|
||||
[[ ! -z $(git -C "$flake3Dir" diff master || echo failed) ]]
|
||||
|
||||
# Make branch "removeXyzzy" where flake3 doesn't have xyzzy anymore
|
||||
git -C "$flake3Dir" checkout -b removeXyzzy
|
||||
rm "$flake3Dir/flake.nix"
|
||||
|
||||
cat > "$flake3Dir/flake.nix" <<EOF
|
||||
{
|
||||
inputs = {
|
||||
nonFlake = {
|
||||
url = "$nonFlakeDir";
|
||||
flake = false;
|
||||
};
|
||||
};
|
||||
|
||||
description = "Fnord";
|
||||
|
||||
outputs = { self, flake1, flake2, nonFlake }: rec {
|
||||
packages.$system.sth = flake1.packages.$system.foo;
|
||||
packages.$system.fnord =
|
||||
with import ./config.nix;
|
||||
mkDerivation {
|
||||
inherit system;
|
||||
name = "fnord";
|
||||
buildCommand = ''
|
||||
cat \${nonFlake}/README.md > \$out
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
EOF
|
||||
nix flake lock "$flake3Dir"
|
||||
git -C "$flake3Dir" add flake.nix flake.lock
|
||||
git -C "$flake3Dir" commit -m 'Remove packages.xyzzy'
|
||||
git -C "$flake3Dir" checkout master
|
||||
|
||||
# Test whether fuzzy-matching works for registry entries.
|
||||
(! nix build -o "$TEST_ROOT/result" flake4/removeXyzzy#xyzzy)
|
||||
nix build -o "$TEST_ROOT/result" flake4/removeXyzzy#sth
|
||||
|
||||
# Testing the nix CLI
|
||||
nix registry add flake1 flake3
|
||||
[[ $(nix registry list | wc -l) == 6 ]]
|
||||
nix registry pin flake1
|
||||
[[ $(nix registry list | wc -l) == 6 ]]
|
||||
nix registry pin flake1 flake3
|
||||
[[ $(nix registry list | wc -l) == 6 ]]
|
||||
nix registry remove flake1
|
||||
[[ $(nix registry list | wc -l) == 5 ]]
|
||||
nix registry pin flake1
|
||||
[[ $(nix registry list | wc -l) == 5 ]]
|
||||
nix registry pin flake1 flake3
|
||||
[[ $(nix registry list | wc -l) == 5 ]]
|
||||
nix registry remove flake1
|
||||
[[ $(nix registry list | wc -l) == 4 ]]
|
||||
|
||||
# Test 'nix registry list' with a disabled global registry.
|
||||
nix registry add user-flake1 git+file://$flake1Dir
|
||||
@ -481,7 +248,7 @@ nix --flake-registry "" registry list | grepQuietInverse '^global' # nothing in
|
||||
nix --flake-registry "" registry list | grepQuiet '^user'
|
||||
nix registry remove user-flake1
|
||||
nix registry remove user-flake2
|
||||
[[ $(nix registry list | wc -l) == 5 ]]
|
||||
[[ $(nix registry list | wc -l) == 4 ]]
|
||||
|
||||
# Test 'nix flake clone'.
|
||||
rm -rf $TEST_ROOT/flake1-v2
|
||||
@ -643,46 +410,3 @@ nix flake metadata "$flake2Dir" --reference-lock-file $TEST_ROOT/flake2-overridd
|
||||
|
||||
# reference-lock-file can only be used if allow-dirty is set.
|
||||
expectStderr 1 nix flake metadata "$flake2Dir" --no-allow-dirty --reference-lock-file $TEST_ROOT/flake2-overridden.lock
|
||||
|
||||
# Test shebang
|
||||
[[ $($nonFlakeDir/shebang.sh) = "foo" ]]
|
||||
[[ $($nonFlakeDir/shebang.sh "bar") = "foo"$'\n'"bar" ]]
|
||||
[[ $($nonFlakeDir/shebang-comments.sh ) = "foo" ]]
|
||||
[[ "$($nonFlakeDir/shebang-different-comments.sh)" = "$(cat $nonFlakeDir/shebang-different-comments.sh)" ]]
|
||||
[[ $($nonFlakeDir/shebang-inline-expr.sh baz) = "foo"$'\n'"baz" ]]
|
||||
[[ $($nonFlakeDir/shebang-file.sh baz) = "foo"$'\n'"baz" ]]
|
||||
expect 1 $nonFlakeDir/shebang-reject.sh 2>&1 | grepQuiet -F 'error: unsupported unquoted character in nix shebang: *. Use double backticks to escape?'
|
||||
|
||||
# Test that the --commit-lock-file-summary flag and its alias work
|
||||
cat > "$lockfileSummaryFlake/flake.nix" <<EOF
|
||||
{
|
||||
inputs = {
|
||||
flake1.url = "git+file://$flake1Dir";
|
||||
};
|
||||
|
||||
description = "lockfileSummaryFlake";
|
||||
|
||||
outputs = inputs: rec {
|
||||
packages.$system.default = inputs.flake1.packages.$system.foo;
|
||||
};
|
||||
}
|
||||
EOF
|
||||
|
||||
git -C "$lockfileSummaryFlake" add flake.nix
|
||||
git -C "$lockfileSummaryFlake" commit -m 'Add lockfileSummaryFlake'
|
||||
|
||||
testSummary="test summary 1"
|
||||
nix flake lock "$lockfileSummaryFlake" --commit-lock-file --commit-lock-file-summary "$testSummary"
|
||||
[[ -e "$lockfileSummaryFlake/flake.lock" ]]
|
||||
[[ -z $(git -C "$lockfileSummaryFlake" diff main || echo failed) ]]
|
||||
[[ "$(git -C "$lockfileSummaryFlake" log --format=%s -n 1)" = "$testSummary" ]]
|
||||
|
||||
git -C "$lockfileSummaryFlake" rm :/:flake.lock
|
||||
git -C "$lockfileSummaryFlake" commit -m "remove flake.lock"
|
||||
testSummary="test summary 2"
|
||||
# NOTE(cole-h): We use `--option` here because Nix settings do not currently support flag-ifying the
|
||||
# alias of a setting: https://github.com/NixOS/nix/issues/10989
|
||||
nix flake lock "$lockfileSummaryFlake" --commit-lock-file --option commit-lockfile-summary "$testSummary"
|
||||
[[ -e "$lockfileSummaryFlake/flake.lock" ]]
|
||||
[[ -z $(git -C "$lockfileSummaryFlake" diff main || echo failed) ]]
|
||||
[[ "$(git -C "$lockfileSummaryFlake" log --format=%s -n 1)" = "$testSummary" ]]
|
||||
|
@ -24,6 +24,9 @@ suites += {
|
||||
'config.sh',
|
||||
'show.sh',
|
||||
'dubious-query.sh',
|
||||
'shebang.sh',
|
||||
'commit-lock-file-summary.sh',
|
||||
'non-flake-inputs.sh',
|
||||
],
|
||||
'workdir': meson.current_source_dir(),
|
||||
}
|
||||
|
128
tests/functional/flakes/non-flake-inputs.sh
Normal file
128
tests/functional/flakes/non-flake-inputs.sh
Normal file
@ -0,0 +1,128 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
source ./common.sh
|
||||
|
||||
TODO_NixOS
|
||||
|
||||
createFlake1
|
||||
createFlake2
|
||||
|
||||
nonFlakeDir=$TEST_ROOT/nonFlake
|
||||
createGitRepo "$nonFlakeDir" ""
|
||||
|
||||
cat > "$nonFlakeDir/README.md" <<EOF
|
||||
FNORD
|
||||
EOF
|
||||
|
||||
git -C "$nonFlakeDir" add README.md
|
||||
git -C "$nonFlakeDir" commit -m 'Initial'
|
||||
|
||||
flake3Dir=$TEST_ROOT/flake3
|
||||
createGitRepo "$flake3Dir" ""
|
||||
|
||||
cat > "$flake3Dir/flake.nix" <<EOF
|
||||
{
|
||||
inputs = {
|
||||
flake1 = {};
|
||||
flake2 = {};
|
||||
nonFlake = {
|
||||
url = git+file://$nonFlakeDir;
|
||||
flake = false;
|
||||
};
|
||||
nonFlakeFile = {
|
||||
url = path://$nonFlakeDir/README.md;
|
||||
flake = false;
|
||||
};
|
||||
nonFlakeFile2 = {
|
||||
url = "$nonFlakeDir/README.md";
|
||||
flake = false;
|
||||
};
|
||||
};
|
||||
|
||||
description = "Fnord";
|
||||
|
||||
outputs = inputs: rec {
|
||||
packages.$system.xyzzy = inputs.flake2.packages.$system.bar;
|
||||
packages.$system.sth = inputs.flake1.packages.$system.foo;
|
||||
packages.$system.fnord =
|
||||
with import ./config.nix;
|
||||
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} ]]
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
EOF
|
||||
|
||||
cp "${config_nix}" "$flake3Dir"
|
||||
|
||||
git -C "$flake3Dir" add flake.nix config.nix
|
||||
git -C "$flake3Dir" commit -m 'Add nonFlakeInputs'
|
||||
|
||||
# Check whether `nix build` works with a lockfile which is missing a
|
||||
# nonFlakeInputs.
|
||||
nix build -o "$TEST_ROOT/result" "$flake3Dir#sth" --commit-lock-file
|
||||
|
||||
nix registry add --registry "$registry" flake3 "git+file://$flake3Dir"
|
||||
|
||||
nix build -o "$TEST_ROOT/result" flake3#fnord
|
||||
[[ $(cat "$TEST_ROOT/result") = FNORD ]]
|
||||
|
||||
# Check whether flake input fetching is lazy: flake3#sth does not
|
||||
# depend on flake2, so this shouldn't fail.
|
||||
rm -rf "$TEST_HOME/.cache"
|
||||
clearStore
|
||||
mv "$flake2Dir" "$flake2Dir.tmp"
|
||||
mv "$nonFlakeDir" "$nonFlakeDir.tmp"
|
||||
nix build -o "$TEST_ROOT/result" flake3#sth
|
||||
(! nix build -o "$TEST_ROOT/result" flake3#xyzzy)
|
||||
(! nix build -o "$TEST_ROOT/result" flake3#fnord)
|
||||
mv "$flake2Dir.tmp" "$flake2Dir"
|
||||
mv "$nonFlakeDir.tmp" "$nonFlakeDir"
|
||||
nix build -o "$TEST_ROOT/result" flake3#xyzzy flake3#fnord
|
||||
|
||||
# Make branch "removeXyzzy" where flake3 doesn't have xyzzy anymore
|
||||
git -C "$flake3Dir" checkout -b removeXyzzy
|
||||
rm "$flake3Dir/flake.nix"
|
||||
|
||||
cat > "$flake3Dir/flake.nix" <<EOF
|
||||
{
|
||||
inputs = {
|
||||
nonFlake = {
|
||||
url = "$nonFlakeDir";
|
||||
flake = false;
|
||||
};
|
||||
};
|
||||
|
||||
description = "Fnord";
|
||||
|
||||
outputs = { self, flake1, flake2, nonFlake }: rec {
|
||||
packages.$system.sth = flake1.packages.$system.foo;
|
||||
packages.$system.fnord =
|
||||
with import ./config.nix;
|
||||
mkDerivation {
|
||||
inherit system;
|
||||
name = "fnord";
|
||||
buildCommand = ''
|
||||
cat \${nonFlake}/README.md > \$out
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
EOF
|
||||
nix flake lock "$flake3Dir"
|
||||
git -C "$flake3Dir" add flake.nix flake.lock
|
||||
git -C "$flake3Dir" commit -m 'Remove packages.xyzzy'
|
||||
git -C "$flake3Dir" checkout master
|
||||
|
||||
# Test whether fuzzy-matching works for registry entries.
|
||||
nix registry add --registry "$registry" flake4 flake3
|
||||
(! nix build -o "$TEST_ROOT/result" flake4/removeXyzzy#xyzzy)
|
||||
nix build -o "$TEST_ROOT/result" flake4/removeXyzzy#sth
|
109
tests/functional/flakes/shebang.sh
Normal file
109
tests/functional/flakes/shebang.sh
Normal file
@ -0,0 +1,109 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
source ./common.sh
|
||||
|
||||
TODO_NixOS
|
||||
|
||||
createFlake1
|
||||
|
||||
scriptDir="$TEST_ROOT/nonFlake"
|
||||
mkdir -p "$scriptDir"
|
||||
|
||||
cat > "$scriptDir/shebang.sh" <<EOF
|
||||
#! $(type -P env) nix
|
||||
#! nix --offline shell
|
||||
#! nix flake1#fooScript
|
||||
#! nix --no-write-lock-file --command bash
|
||||
set -ex
|
||||
foo
|
||||
echo "\$@"
|
||||
EOF
|
||||
chmod +x "$scriptDir/shebang.sh"
|
||||
|
||||
# this also tests a fairly trivial double backtick quoted string, ``--command``
|
||||
cat > "$scriptDir/shebang-comments.sh" <<EOF
|
||||
#! $(type -P env) nix
|
||||
# some comments
|
||||
# some comments
|
||||
# some comments
|
||||
#! nix --offline shell
|
||||
#! nix flake1#fooScript
|
||||
#! nix --no-write-lock-file ``--command`` bash
|
||||
foo
|
||||
EOF
|
||||
chmod +x "$scriptDir/shebang-comments.sh"
|
||||
|
||||
cat > "$scriptDir/shebang-different-comments.sh" <<EOF
|
||||
#! $(type -P env) nix
|
||||
# some comments
|
||||
// some comments
|
||||
/* some comments
|
||||
* some comments
|
||||
\ some comments
|
||||
% some comments
|
||||
@ some comments
|
||||
-- some comments
|
||||
(* some comments
|
||||
#! nix --offline shell
|
||||
#! nix flake1#fooScript
|
||||
#! nix --no-write-lock-file --command cat
|
||||
foo
|
||||
EOF
|
||||
chmod +x "$scriptDir/shebang-different-comments.sh"
|
||||
|
||||
cat > "$scriptDir/shebang-reject.sh" <<EOF
|
||||
#! $(type -P env) nix
|
||||
# some comments
|
||||
# some comments
|
||||
# some comments
|
||||
#! nix --offline shell *
|
||||
#! nix flake1#fooScript
|
||||
#! nix --no-write-lock-file --command bash
|
||||
foo
|
||||
EOF
|
||||
chmod +x "$scriptDir/shebang-reject.sh"
|
||||
|
||||
cat > "$scriptDir/shebang-inline-expr.sh" <<EOF
|
||||
#! $(type -P env) nix
|
||||
EOF
|
||||
cat >> "$scriptDir/shebang-inline-expr.sh" <<"EOF"
|
||||
#! nix --offline shell
|
||||
#! nix --impure --expr ``
|
||||
#! nix let flake = (builtins.getFlake (toString ../flake1)).packages;
|
||||
#! nix fooScript = flake.${builtins.currentSystem}.fooScript;
|
||||
#! nix /* just a comment !@#$%^&*()__+ # */
|
||||
#! nix in fooScript
|
||||
#! nix ``
|
||||
#! nix --no-write-lock-file --command bash
|
||||
set -ex
|
||||
foo
|
||||
echo "$@"
|
||||
EOF
|
||||
chmod +x "$scriptDir/shebang-inline-expr.sh"
|
||||
|
||||
cat > "$scriptDir/fooScript.nix" <<"EOF"
|
||||
let flake = (builtins.getFlake (toString ../flake1)).packages;
|
||||
fooScript = flake.${builtins.currentSystem}.fooScript;
|
||||
in fooScript
|
||||
EOF
|
||||
|
||||
cat > "$scriptDir/shebang-file.sh" <<EOF
|
||||
#! $(type -P env) nix
|
||||
EOF
|
||||
cat >> "$scriptDir/shebang-file.sh" <<"EOF"
|
||||
#! nix --offline shell
|
||||
#! nix --impure --file ./fooScript.nix
|
||||
#! nix --no-write-lock-file --command bash
|
||||
set -ex
|
||||
foo
|
||||
echo "$@"
|
||||
EOF
|
||||
chmod +x "$scriptDir/shebang-file.sh"
|
||||
|
||||
[[ $("$scriptDir/shebang.sh") = "foo" ]]
|
||||
[[ $("$scriptDir/shebang.sh" "bar") = "foo"$'\n'"bar" ]]
|
||||
[[ $("$scriptDir/shebang-comments.sh" ) = "foo" ]]
|
||||
[[ "$("$scriptDir/shebang-different-comments.sh")" = "$(cat "$scriptDir/shebang-different-comments.sh")" ]]
|
||||
[[ $("$scriptDir/shebang-inline-expr.sh" baz) = "foo"$'\n'"baz" ]]
|
||||
[[ $("$scriptDir/shebang-file.sh" baz) = "foo"$'\n'"baz" ]]
|
||||
expect 1 "$scriptDir/shebang-reject.sh" 2>&1 | grepQuiet -F 'error: unsupported unquoted character in nix shebang: *. Use double backticks to escape?'
|
Loading…
Reference in New Issue
Block a user