1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 02:21:16 +02:00

Merge branch 'master' into lfs

This commit is contained in:
Brian Camacho 2024-12-02 15:06:28 -05:00
commit 169d62a382
154 changed files with 1859 additions and 844 deletions

View 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" ]]

View file

@ -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

View file

@ -122,7 +122,7 @@ expectStderr 1 nix develop --unset-env-var FOO --set-env-var FOO 'BAR' --no-writ
grepQuiet "error: Cannot set environment variable 'FOO' that is unset with '--unset-env-var'"
# Check that multiple `--ignore-env`'s are okay.
expectStderr 0 nix develop --ignore-env --set-env-var FOO 'BAR' --ignore-env .#hello
expectStderr 0 nix develop --ignore-env --set-env-var FOO 'BAR' --ignore-env .#hello < /dev/null
# Determine the bashInteractive executable.
nix build --no-write-lock-file './nixpkgs#bashInteractive' --out-link ./bash-interactive

View file

@ -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"

View file

@ -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

View file

@ -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" ]]

View file

@ -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(),
}

View 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

View 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?'

View file

@ -0,0 +1,5 @@
error: undefined variable 'd'
at /pwd/lang/eval-fail-attrset-merge-drops-later-rec.nix:1:26:
1| { a.b = 1; a = rec { c = d + 2; d = 3; }; }.c
| ^
2|

View file

@ -0,0 +1 @@
{ a.b = 1; a = rec { c = d + 2; d = 3; }; }.c

View file

@ -0,0 +1,3 @@
# This is for backwards compatibility, not because we like it.
# See https://github.com/NixOS/nix/issues/9020.
{ a = rec { b = c + 1; d = 2; }; a.c = d + 3; }.a.b

View file

@ -1,6 +1,6 @@
error: attribute 'z' already defined at «stdin»:3:16
at «stdin»:2:3:
1| {
error: attribute 'x.z' already defined at «stdin»:2:3
at «stdin»:3:16:
2| x.z = 3;
| ^
3| x = { y = 3; z = 3; };
| ^
4| }

View file

@ -1,6 +1,6 @@
error: attribute 'y' already defined at «stdin»:3:9
at «stdin»:2:3:
1| {
error: attribute 'x.y.y' already defined at «stdin»:2:3
at «stdin»:3:9:
2| x.y.y = 3;
| ^
3| x = { y.y= 3; z = 3; };
| ^
4| }

View file

@ -17,12 +17,10 @@ fs = import('fs')
nix = find_program('nix')
bash = find_program('bash', native : true)
busybox = find_program('busybox', native : true, required : false)
if host_machine.system() == 'windows'
# Because of the state of symlinks on Windows, coreutils.exe doesn't usually exist, but things like ls.exe will
coreutils = find_program('ls', native : true)
else
coreutils = find_program('coreutils', native : true)
endif
# Look up `coreutils` package by searching for `ls` binary.
# Previously we looked up `coreutils` on `linux`, but that is not
# guaranteed to exist either.
coreutils = find_program('ls', native : true)
dot = find_program('dot', native : true, required : false)
nix_bin_dir = fs.parent(nix.full_path())

View file

@ -167,6 +167,35 @@ EOF
chmod a+x $TEST_ROOT/marco/polo/default.nix
(cd $TEST_ROOT/marco && ./polo/default.nix | grepQuiet "Polo")
# https://github.com/NixOS/nix/issues/11892
mkdir $TEST_ROOT/issue-11892
cat >$TEST_ROOT/issue-11892/shebangscript <<EOF
#!$(type -P env) nix-shell
#! nix-shell -I nixpkgs=$shellDotNix
#! nix-shell -p 'callPackage (import ./my_package.nix) {}'
#! nix-shell -i bash
set -euxo pipefail
my_package
EOF
cat >$TEST_ROOT/issue-11892/my_package.nix <<EOF
{ stdenv, shell, ... }:
stdenv.mkDerivation {
name = "my_package";
buildCommand = ''
mkdir -p \$out/bin
( echo "#!\${shell}"
echo "echo 'ok' 'baz11892'"
) > \$out/bin/my_package
cat \$out/bin/my_package
chmod a+x \$out/bin/my_package
'';
}
EOF
chmod a+x $TEST_ROOT/issue-11892/shebangscript
$TEST_ROOT/issue-11892/shebangscript \
| tee /dev/stderr \
| grepQuiet "ok baz11892"
#####################
# Flake equivalents #

View file

@ -23,7 +23,7 @@ nix-instantiate --restrict-eval ./simple.nix -I src1=./simple.nix -I src2=./conf
(! nix-instantiate --restrict-eval --eval -E 'builtins.readFile ./simple.nix')
nix-instantiate --restrict-eval --eval -E 'builtins.readFile ./simple.nix' -I src=../..
expectStderr 1 nix-instantiate --restrict-eval --eval -E 'let __nixPath = [ { prefix = "foo"; path = ./.; } ]; in builtins.readFile <foo/simple.nix>' | grepQuiet "forbidden in restricted mode"
expectStderr 1 nix-instantiate --restrict-eval --eval -E 'let __nixPath = [ { prefix = "foo"; path = ./.; } ]; in builtins.readFile <foo/simple.nix>' | grepQuiet "was not found in the Nix search path"
nix-instantiate --restrict-eval --eval -E 'let __nixPath = [ { prefix = "foo"; path = ./.; } ]; in builtins.readFile <foo/simple.nix>' -I src=.
p=$(nix eval --raw --expr "builtins.fetchurl file://${_NIX_TEST_SOURCE_DIR}/restricted.sh" --impure --restrict-eval --allowed-uris "file://${_NIX_TEST_SOURCE_DIR}")

View file

@ -37,7 +37,7 @@ let pkgs = rec {
mkdir -p $out
ln -s ${setupSh} $out/setup
'';
};
} // { inherit mkDerivation; };
shellDrv = mkDerivation {
name = "shellDrv";
@ -94,5 +94,9 @@ let pkgs = rec {
chmod a+rx $out/bin/ruby
'';
inherit (cfg) shell;
callPackage = f: args: f (pkgs // args);
inherit pkgs;
}; in pkgs

View file

@ -18,7 +18,10 @@ HASH=$(nix hash path "$outPath")
clearStore
clearCacheCache
nix copy --from "$cacheURI" "$outPath" --no-check-sigs
nix copy --from "$cacheURI" "$outPath" --no-check-sigs --profile "$TEST_ROOT/profile" --out-link "$TEST_ROOT/result"
[[ -e $TEST_ROOT/profile ]]
[[ -e $TEST_ROOT/result ]]
if ls "$cacheDir/nar/"*.zst &> /dev/null; then
echo "files do exist"

View file

@ -124,6 +124,8 @@ in
nix-copy = runNixOSTestFor "x86_64-linux" ./nix-copy.nix;
nix-docker = runNixOSTestFor "x86_64-linux" ./nix-docker.nix;
nssPreload = runNixOSTestFor "x86_64-linux" ./nss-preload.nix;
githubFlakes = runNixOSTestFor "x86_64-linux" ./github-flakes.nix;

View file

@ -0,0 +1,47 @@
#!/usr/bin/env bash
# docker.nix test script. Runs inside a built docker.nix container.
set -eEuo pipefail
export NIX_CONFIG='substituters = http://cache:5000?trusted=1'
cd /tmp
# Test getting a fetched derivation
test "$("$(nix-build -E '(import <nixpkgs> {}).hello')"/bin/hello)" = "Hello, world!"
# Test building a simple derivation
# shellcheck disable=SC2016
nix-build -E '
let
pkgs = import <nixpkgs> {};
in
builtins.derivation {
name = "test";
system = builtins.currentSystem;
builder = "${pkgs.bash}/bin/bash";
args = ["-c" "echo OK > $out"];
}'
test "$(cat result)" = OK
# Ensure #!/bin/sh shebang works
echo '#!/bin/sh' > ./shebang-test
echo 'echo OK' >> ./shebang-test
chmod +x ./shebang-test
test "$(./shebang-test)" = OK
# Ensure #!/usr/bin/env shebang works
echo '#!/usr/bin/env bash' > ./shebang-test
echo 'echo OK' >> ./shebang-test
chmod +x ./shebang-test
test "$(./shebang-test)" = OK
# Test nix-shell
{
echo '#!/usr/bin/env nix-shell'
echo '#! nix-shell -i bash'
echo '#! nix-shell -p hello'
echo 'hello'
} > ./nix-shell-test
chmod +x ./nix-shell-test
test "$(./nix-shell-test)" = "Hello, world!"

View file

@ -0,0 +1,53 @@
# Test the container built by ../../docker.nix.
{ lib, config, nixpkgs, hostPkgs, ... }:
let
pkgs = config.nodes.machine.nixpkgs.pkgs;
nixImage = import ../../docker.nix {
inherit (config.nodes.machine.nixpkgs) pkgs;
};
nixUserImage = import ../../docker.nix {
inherit (config.nodes.machine.nixpkgs) pkgs;
name = "nix-user";
uid = 1000;
gid = 1000;
uname = "user";
gname = "user";
};
containerTestScript = ./nix-docker-test.sh;
in {
name = "nix-docker";
nodes =
{ machine =
{ config, lib, pkgs, ... }:
{ virtualisation.diskSize = 4096;
};
cache =
{ config, lib, pkgs, ... }:
{ virtualisation.additionalPaths = [ pkgs.stdenv pkgs.hello ];
services.harmonia.enable = true;
networking.firewall.allowedTCPPorts = [ 5000 ];
};
};
testScript = { nodes }: ''
cache.wait_for_unit("harmonia.service")
machine.succeed("mkdir -p /etc/containers")
machine.succeed("""echo '{"default":[{"type":"insecureAcceptAnything"}]}' > /etc/containers/policy.json""")
machine.succeed("${pkgs.podman}/bin/podman load -i ${nixImage}")
machine.succeed("${pkgs.podman}/bin/podman run --rm nix nix --version")
machine.succeed("${pkgs.podman}/bin/podman run --rm -i nix < ${containerTestScript}")
machine.succeed("${pkgs.podman}/bin/podman load -i ${nixUserImage}")
machine.succeed("${pkgs.podman}/bin/podman run --rm nix-user nix --version")
machine.succeed("${pkgs.podman}/bin/podman run --rm -i nix-user < ${containerTestScript}")
machine.succeed("[[ $(${pkgs.podman}/bin/podman run --rm nix-user stat -c %u /nix/store) = 1000 ]]")
'';
}