mirror of
https://github.com/NixOS/nix.git
synced 2025-11-29 05:31:00 +01:00
Merge remote-tracking branch 'origin/master' into lazy-trees
This commit is contained in:
commit
bb421ac80b
108 changed files with 1242 additions and 452 deletions
|
|
@ -67,4 +67,11 @@ rec {
|
|||
disallowedReferences = [test5];
|
||||
};
|
||||
|
||||
test11 = makeTest 11 {
|
||||
__structuredAttrs = true;
|
||||
unsafeDiscardReferences.out = true;
|
||||
outputChecks.out.allowedReferences = [];
|
||||
buildCommand = ''echo ${dep} > "''${outputs[out]}"'';
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,3 +40,12 @@ nix-build -o $RESULT check-refs.nix -A test7
|
|||
|
||||
# test10 should succeed (no disallowed references).
|
||||
nix-build -o $RESULT check-refs.nix -A test10
|
||||
|
||||
if isDaemonNewer 2.12pre20230103; then
|
||||
enableFeatures discard-references
|
||||
restartDaemon
|
||||
|
||||
# test11 should succeed.
|
||||
test11=$(nix-build -o $RESULT check-refs.nix -A test11)
|
||||
[[ -z $(nix-store -q --references "$test11") ]]
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ readLink() {
|
|||
}
|
||||
|
||||
clearProfiles() {
|
||||
profiles="$NIX_STATE_DIR"/profiles
|
||||
profiles="$HOME"/.local/share/nix/profiles
|
||||
rm -rf $profiles
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,10 @@ writeSimpleFlake() {
|
|||
foo = import ./simple.nix;
|
||||
default = foo;
|
||||
};
|
||||
packages.someOtherSystem = rec {
|
||||
foo = import ./simple.nix;
|
||||
default = foo;
|
||||
};
|
||||
|
||||
# To test "nix flake init".
|
||||
legacyPackages.x86_64-linux.hello = import ./simple.nix;
|
||||
|
|
|
|||
|
|
@ -41,8 +41,8 @@ cat > $templatesDir/trivial/flake.nix <<EOF
|
|||
description = "A flake for building Hello World";
|
||||
|
||||
outputs = { self, nixpkgs }: {
|
||||
packages.x86_64-linux = rec {
|
||||
hello = nixpkgs.legacyPackages.x86_64-linux.hello;
|
||||
packages.$system = rec {
|
||||
hello = nixpkgs.legacyPackages.$system.hello;
|
||||
default = hello;
|
||||
};
|
||||
};
|
||||
|
|
|
|||
66
tests/flakes/show.sh
Normal file
66
tests/flakes/show.sh
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
source ./common.sh
|
||||
|
||||
flakeDir=$TEST_ROOT/flake
|
||||
mkdir -p "$flakeDir"
|
||||
|
||||
writeSimpleFlake "$flakeDir"
|
||||
cd "$flakeDir"
|
||||
|
||||
|
||||
# By default: Only show the packages content for the current system and no
|
||||
# legacyPackages at all
|
||||
nix flake show --json > show-output.json
|
||||
nix eval --impure --expr '
|
||||
let show_output = builtins.fromJSON (builtins.readFile ./show-output.json);
|
||||
in
|
||||
assert show_output.packages.someOtherSystem.default == {};
|
||||
assert show_output.packages.${builtins.currentSystem}.default.name == "simple";
|
||||
assert show_output.legacyPackages.${builtins.currentSystem} == {};
|
||||
true
|
||||
'
|
||||
|
||||
# With `--all-systems`, show the packages for all systems
|
||||
nix flake show --json --all-systems > show-output.json
|
||||
nix eval --impure --expr '
|
||||
let show_output = builtins.fromJSON (builtins.readFile ./show-output.json);
|
||||
in
|
||||
assert show_output.packages.someOtherSystem.default.name == "simple";
|
||||
assert show_output.legacyPackages.${builtins.currentSystem} == {};
|
||||
true
|
||||
'
|
||||
|
||||
# With `--legacy`, show the legacy packages
|
||||
nix flake show --json --legacy > show-output.json
|
||||
nix eval --impure --expr '
|
||||
let show_output = builtins.fromJSON (builtins.readFile ./show-output.json);
|
||||
in
|
||||
assert show_output.legacyPackages.${builtins.currentSystem}.hello.name == "simple";
|
||||
true
|
||||
'
|
||||
|
||||
# Test that attributes are only reported when they have actual content
|
||||
cat >flake.nix <<EOF
|
||||
{
|
||||
description = "Bla bla";
|
||||
|
||||
outputs = inputs: rec {
|
||||
apps.$system = { };
|
||||
checks.$system = { };
|
||||
devShells.$system = { };
|
||||
legacyPackages.$system = { };
|
||||
packages.$system = { };
|
||||
packages.someOtherSystem = { };
|
||||
|
||||
formatter = { };
|
||||
nixosConfigurations = { };
|
||||
nixosModules = { };
|
||||
};
|
||||
}
|
||||
EOF
|
||||
nix flake show --json --all-systems > show-output.json
|
||||
nix eval --impure --expr '
|
||||
let show_output = builtins.fromJSON (builtins.readFile ./show-output.json);
|
||||
in
|
||||
assert show_output == { };
|
||||
true
|
||||
'
|
||||
|
|
@ -18,6 +18,7 @@ nix_tests = \
|
|||
fetchMercurial.sh \
|
||||
gc-auto.sh \
|
||||
user-envs.sh \
|
||||
user-envs-migration.sh \
|
||||
binary-cache.sh \
|
||||
multiple-outputs.sh \
|
||||
ca/build.sh \
|
||||
|
|
@ -114,6 +115,7 @@ nix_tests = \
|
|||
store-ping.sh \
|
||||
fetchClosure.sh \
|
||||
completions.sh \
|
||||
flakes/show.sh \
|
||||
impure-derivations.sh \
|
||||
path-from-hash-part.sh \
|
||||
toString-path.sh
|
||||
|
|
|
|||
|
|
@ -12,3 +12,8 @@ nix-instantiate --eval -E '<by-relative-path/simple.nix>' --restrict-eval
|
|||
|
||||
[[ $(nix-instantiate --find-file by-absolute-path/simple.nix) = $PWD/simple.nix ]]
|
||||
[[ $(nix-instantiate --find-file by-relative-path/simple.nix) = $PWD/simple.nix ]]
|
||||
|
||||
unset NIX_PATH
|
||||
|
||||
[[ $(nix-instantiate --option nix-path by-relative-path=. --find-file by-relative-path/simple.nix) = "$PWD/simple.nix" ]]
|
||||
[[ $(NIX_PATH= nix-instantiate --option nix-path by-relative-path=. --find-file by-relative-path/simple.nix) = "$PWD/simple.nix" ]]
|
||||
|
|
|
|||
|
|
@ -1,12 +1,7 @@
|
|||
# Test whether we can run a NixOS container inside a Nix build using systemd-nspawn.
|
||||
{ nixpkgs, system, overlay }:
|
||||
{ lib, nixpkgs, ... }:
|
||||
|
||||
with import (nixpkgs + "/nixos/lib/testing-python.nix") {
|
||||
inherit system;
|
||||
extraConfigurations = [ { nixpkgs.overlays = [ overlay ]; } ];
|
||||
};
|
||||
|
||||
makeTest ({
|
||||
{
|
||||
name = "containers";
|
||||
|
||||
nodes =
|
||||
|
|
@ -65,4 +60,4 @@ makeTest ({
|
|||
host.succeed("[[ $(cat ./result/msg) = 'Hello World' ]]")
|
||||
'';
|
||||
|
||||
})
|
||||
}
|
||||
|
|
@ -1,14 +1,9 @@
|
|||
{ nixpkgs, system, overlay }:
|
||||
|
||||
with import (nixpkgs + "/nixos/lib/testing-python.nix") {
|
||||
inherit system;
|
||||
extraConfigurations = [ { nixpkgs.overlays = [ overlay ]; } ];
|
||||
};
|
||||
|
||||
{ lib, config, nixpkgs, ... }:
|
||||
let
|
||||
pkgs = config.nodes.client.nixpkgs.pkgs;
|
||||
|
||||
# Generate a fake root CA and a fake api.github.com / github.com / channels.nixos.org certificate.
|
||||
cert = pkgs.runCommand "cert" { buildInputs = [ pkgs.openssl ]; }
|
||||
cert = pkgs.runCommand "cert" { nativeBuildInputs = [ pkgs.openssl ]; }
|
||||
''
|
||||
mkdir -p $out
|
||||
|
||||
|
|
@ -92,8 +87,6 @@ let
|
|||
'';
|
||||
in
|
||||
|
||||
makeTest (
|
||||
|
||||
{
|
||||
name = "github-flakes";
|
||||
|
||||
|
|
@ -207,4 +200,4 @@ makeTest (
|
|||
client.succeed("nix build nixpkgs#fuse --tarball-ttl 0")
|
||||
'';
|
||||
|
||||
})
|
||||
}
|
||||
|
|
@ -1,13 +1,16 @@
|
|||
# Test ‘nix-copy-closure’.
|
||||
|
||||
{ nixpkgs, system, overlay }:
|
||||
{ lib, config, nixpkgs, hostPkgs, ... }:
|
||||
|
||||
with import (nixpkgs + "/nixos/lib/testing-python.nix") {
|
||||
inherit system;
|
||||
extraConfigurations = [ { nixpkgs.overlays = [ overlay ]; } ];
|
||||
};
|
||||
let
|
||||
pkgs = config.nodes.client.nixpkgs.pkgs;
|
||||
|
||||
makeTest (let pkgA = pkgs.cowsay; pkgB = pkgs.wget; pkgC = pkgs.hello; pkgD = pkgs.tmux; in {
|
||||
pkgA = pkgs.cowsay;
|
||||
pkgB = pkgs.wget;
|
||||
pkgC = pkgs.hello;
|
||||
pkgD = pkgs.tmux;
|
||||
|
||||
in {
|
||||
name = "nix-copy-closure";
|
||||
|
||||
nodes =
|
||||
|
|
@ -74,4 +77,4 @@ makeTest (let pkgA = pkgs.cowsay; pkgB = pkgs.wget; pkgC = pkgs.hello; pkgD = pk
|
|||
# )
|
||||
# client.succeed("nix-store --check-validity ${pkgC}")
|
||||
'';
|
||||
})
|
||||
}
|
||||
|
|
@ -1,11 +1,9 @@
|
|||
{ nixpkgs, system, overlay }:
|
||||
|
||||
with import (nixpkgs + "/nixos/lib/testing-python.nix") {
|
||||
inherit system;
|
||||
extraConfigurations = [ { nixpkgs.overlays = [ overlay ]; } ];
|
||||
};
|
||||
{ lib, config, nixpkgs, ... }:
|
||||
|
||||
let
|
||||
|
||||
pkgs = config.nodes.client.nixpkgs.pkgs;
|
||||
|
||||
nix-fetch = pkgs.writeText "fetch.nix" ''
|
||||
derivation {
|
||||
# This derivation is an copy from what is available over at
|
||||
|
|
@ -41,9 +39,7 @@ let
|
|||
'';
|
||||
in
|
||||
|
||||
makeTest (
|
||||
|
||||
rec {
|
||||
{
|
||||
name = "nss-preload";
|
||||
|
||||
nodes = {
|
||||
|
|
@ -122,4 +118,4 @@ rec {
|
|||
nix-build ${nix-fetch} >&2
|
||||
""")
|
||||
'';
|
||||
})
|
||||
}
|
||||
|
|
@ -1,15 +1,9 @@
|
|||
# Test Nix's remote build feature.
|
||||
|
||||
{ nixpkgs, system, overlay }:
|
||||
|
||||
with import (nixpkgs + "/nixos/lib/testing-python.nix") {
|
||||
inherit system;
|
||||
extraConfigurations = [ { nixpkgs.overlays = [ overlay ]; } ];
|
||||
};
|
||||
|
||||
makeTest (
|
||||
{ config, lib, hostPkgs, ... }:
|
||||
|
||||
let
|
||||
pkgs = config.nodes.client.nixpkgs.pkgs;
|
||||
|
||||
# The configuration of the remote builders.
|
||||
builder =
|
||||
|
|
@ -75,7 +69,7 @@ in
|
|||
|
||||
# Create an SSH key on the client.
|
||||
subprocess.run([
|
||||
"${pkgs.openssh}/bin/ssh-keygen", "-t", "ed25519", "-f", "key", "-N", ""
|
||||
"${hostPkgs.openssh}/bin/ssh-keygen", "-t", "ed25519", "-f", "key", "-N", ""
|
||||
], capture_output=True, check=True)
|
||||
client.succeed("mkdir -p -m 700 /root/.ssh")
|
||||
client.copy_from_host("key", "/root/.ssh/id_ed25519")
|
||||
|
|
@ -109,4 +103,4 @@ in
|
|||
builder1.block()
|
||||
client.succeed("nix-build ${expr nodes.client.config 4}")
|
||||
'';
|
||||
})
|
||||
}
|
||||
|
|
@ -1,13 +1,12 @@
|
|||
# Verify that Linux builds cannot create setuid or setgid binaries.
|
||||
|
||||
{ nixpkgs, system, overlay }:
|
||||
{ lib, config, nixpkgs, ... }:
|
||||
|
||||
with import (nixpkgs + "/nixos/lib/testing-python.nix") {
|
||||
inherit system;
|
||||
extraConfigurations = [ { nixpkgs.overlays = [ overlay ]; } ];
|
||||
};
|
||||
let
|
||||
pkgs = config.nodes.machine.nixpkgs.pkgs;
|
||||
|
||||
makeTest {
|
||||
in
|
||||
{
|
||||
name = "setuid";
|
||||
|
||||
nodes.machine =
|
||||
|
|
@ -1,12 +1,8 @@
|
|||
{ nixpkgs, system, overlay }:
|
||||
|
||||
with import (nixpkgs + "/nixos/lib/testing-python.nix")
|
||||
{
|
||||
inherit system;
|
||||
extraConfigurations = [{ nixpkgs.overlays = [ overlay ]; }];
|
||||
};
|
||||
{ lib, config, hostPkgs, nixpkgs, ... }:
|
||||
|
||||
let
|
||||
pkgs = config.nodes.sourcehut.nixpkgs.pkgs;
|
||||
|
||||
# Generate a fake root CA and a fake git.sr.ht certificate.
|
||||
cert = pkgs.runCommand "cert" { buildInputs = [ pkgs.openssl ]; }
|
||||
''
|
||||
|
|
@ -64,8 +60,6 @@ let
|
|||
|
||||
in
|
||||
|
||||
makeTest (
|
||||
|
||||
{
|
||||
name = "sourcehut-flakes";
|
||||
|
||||
|
|
@ -164,4 +158,4 @@ makeTest (
|
|||
client.succeed("nix build nixpkgs#fuse --tarball-ttl 0")
|
||||
'';
|
||||
|
||||
})
|
||||
}
|
||||
|
|
@ -30,7 +30,3 @@ NIX_REMOTE= nix-store --dump-db > $TEST_ROOT/d2
|
|||
cmp $TEST_ROOT/d1 $TEST_ROOT/d2
|
||||
|
||||
killDaemon
|
||||
|
||||
user=$(whoami)
|
||||
[ -e $NIX_STATE_DIR/gcroots/per-user/$user ]
|
||||
[ -e $NIX_STATE_DIR/profiles/per-user/$user ]
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@ nix-instantiate --restrict-eval --eval -E 'builtins.readDir ../src/nix-channel'
|
|||
(! nix-instantiate --restrict-eval --eval -E 'let __nixPath = [ { prefix = "foo"; path = ./.; } ]; in builtins.readFile <foo/simple.nix>')
|
||||
nix-instantiate --restrict-eval --eval -E 'let __nixPath = [ { prefix = "foo"; path = ./.; } ]; in builtins.readFile <foo/simple.nix>' -I src=.
|
||||
|
||||
# no default NIX_PATH
|
||||
(unset NIX_PATH; ! nix-instantiate --restrict-eval --find-file .)
|
||||
|
||||
p=$(nix eval --raw --expr "builtins.fetchurl file://$(pwd)/restricted.sh" --impure --restrict-eval --allowed-uris "file://$(pwd)")
|
||||
cmp $p restricted.sh
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,17 @@
|
|||
source common.sh
|
||||
|
||||
STORE_INFO=$(nix store ping 2>&1)
|
||||
STORE_INFO_JSON=$(nix store ping --json)
|
||||
|
||||
echo "$STORE_INFO" | grep "Store URL: ${NIX_REMOTE}"
|
||||
|
||||
if [[ -v NIX_DAEMON_PACKAGE ]] && isDaemonNewer "2.7.0pre20220126"; then
|
||||
DAEMON_VERSION=$($NIX_DAEMON_PACKAGE/bin/nix-daemon --version | cut -d' ' -f3)
|
||||
echo "$STORE_INFO" | grep "Version: $DAEMON_VERSION"
|
||||
[[ "$(echo "$STORE_INFO_JSON" | jq -r ".version")" == "$DAEMON_VERSION" ]]
|
||||
fi
|
||||
|
||||
expect 127 NIX_REMOTE=unix:$PWD/store nix store ping || \
|
||||
fail "nix store ping on a non-existent store should fail"
|
||||
|
||||
[[ "$(echo "$STORE_INFO_JSON" | jq -r ".url")" == "${NIX_REMOTE:-local}" ]]
|
||||
|
|
|
|||
35
tests/user-envs-migration.sh
Normal file
35
tests/user-envs-migration.sh
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# Test that the migration of user environments
|
||||
# (https://github.com/NixOS/nix/pull/5226) does preserve everything
|
||||
|
||||
source common.sh
|
||||
|
||||
if isDaemonNewer "2.4pre20211005"; then
|
||||
exit 99
|
||||
fi
|
||||
|
||||
|
||||
killDaemon
|
||||
unset NIX_REMOTE
|
||||
|
||||
clearStore
|
||||
clearProfiles
|
||||
rm -rf ~/.nix-profile
|
||||
|
||||
# Fill the environment using the older Nix
|
||||
PATH_WITH_NEW_NIX="$PATH"
|
||||
export PATH="$NIX_DAEMON_PACKAGE/bin:$PATH"
|
||||
|
||||
nix-env -f user-envs.nix -i foo-1.0
|
||||
nix-env -f user-envs.nix -i bar-0.1
|
||||
|
||||
# Migrate to the new profile dir, and ensure that everything’s there
|
||||
export PATH="$PATH_WITH_NEW_NIX"
|
||||
nix-env -q # Trigger the migration
|
||||
( [[ -L ~/.nix-profile ]] && \
|
||||
[[ $(readlink ~/.nix-profile) == ~/.local/share/nix/profiles/profile ]] ) || \
|
||||
fail "The nix profile should point to the new location"
|
||||
|
||||
(nix-env -q | grep foo && nix-env -q | grep bar && \
|
||||
[[ -e ~/.nix-profile/bin/foo ]] && \
|
||||
[[ $(nix-env --list-generations | wc -l) == 2 ]]) ||
|
||||
fail "The nix profile should have the same content as before the migration"
|
||||
Loading…
Add table
Add a link
Reference in a new issue