Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test against stable versions #5572

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 71 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 38 additions & 22 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11-small";
inputs.nixpkgs-regression.url = "github:NixOS/nixpkgs/215d4d0fd80ca5163643b03a33fde804a29cc1e2";
inputs.lowdown-src = { url = "github:kristapsdz/lowdown"; flake = false; };
inputs.nix-2_3-src = { url = "github:nixos/nix/2.3-maintenance"; flake = false; };
inputs.nix-2_4 = { url = "github:nixos/nix/2.4-maintenance"; };

outputs = { self, nixpkgs, nixpkgs-regression, lowdown-src }:
outputs = { self, nixpkgs, nixpkgs-regression, lowdown-src, nix-2_3-src, nix-2_4 }:

let
inherit (nixpkgs) lib;
Expand Down Expand Up @@ -187,12 +189,7 @@
testNixVersions = pkgs: client: daemon: with commonDeps { inherit pkgs; }; with pkgs.lib; pkgs.stdenv.mkDerivation {
NIX_DAEMON_PACKAGE = daemon;
NIX_CLIENT_PACKAGE = client;
name =
"nix-tests"
+ optionalString
(versionAtLeast daemon.version "2.4pre20211005" &&
versionAtLeast client.version "2.4pre20211005")
"-${client.version}-against-${daemon.version}";
name = "nix-tests-${client.version}-against-${daemon.version}";
inherit version;

src = self;
Expand Down Expand Up @@ -561,31 +558,50 @@
nixpkgs = nixpkgs-regression;
};

installTests = forAllSystems (system:
let pkgs = nixpkgsFor.${system}.native; in
pkgs.runCommand "install-tests" {
againstSelf = testNixVersions pkgs pkgs.nix pkgs.pkgs.nix;
againstCurrentUnstable =
# FIXME: temporarily disable this on macOS because of #3605.
if system == "x86_64-linux"
then testNixVersions pkgs pkgs.nix pkgs.nixUnstable
else null;
# Disabled because the latest stable version doesn't handle
# `NIX_DAEMON_SOCKET_PATH` which is required for the tests to work
# againstLatestStable = testNixVersions pkgs pkgs.nix pkgs.nixStable;
} "touch $out");
installTests = let
inherit (nixpkgs) lib;
forAllPkgs = f: forAllSystems (system: f nixpkgsFor.${system});
allTests = rec {
againstSelf = forAllPkgs (pkgs: testNixVersions pkgs pkgs.nix pkgs.pkgs.nix);

# FIXME: temporarily disable this on macOS because of
# #3605. We used to null platforms other than
# x86_64-linux, but that broke nix flake check when we
# exposed these as standalone hydra jobs.
againstCurrentUnstable.x86_64-linux = let
pkgs = nixpkgsFor.x86_64-linux.native;
in testNixVersions pkgs pkgs.nix pkgs.nixUnstable;

againstStable_2_3 = forAllPkgs (pkgs: testNixVersions pkgs pkgs.nix
(let
pkg = (import "${nix-2_3-src}/release.nix" {
nix = nix-2_3-src;
inherit nixpkgs;
officialRelease = true;
}).build.${pkgs.stdenv.hostPlatform.system};
in pkg // {
inherit (lib.strings.parseDrvName pkg.name) version;
}));
againstStable_2_4 = forAllPkgs (pkgs: testNixVersions pkgs pkgs.nix
nix-2_4.packages.${pkgs.stdenv.hostPlatform.system}.nix);
};
all = forAllSystems (system:
nixpkgsFor.${system}.runCommand
"install-tests"
(lib.mapAttrs (_: v: v.${system} or null) allTests)
"touch $out");
in allTests // { inherit all; };

installerTests = import ./tests/installer {
binaryTarballs = self.hydraJobs.binaryTarball;
inherit nixpkgsFor;
};

};

checks = forAllSystems (system: {
binaryTarball = self.hydraJobs.binaryTarball.${system};
perlBindings = self.hydraJobs.perlBindings.${system};
installTests = self.hydraJobs.installTests.${system};
installTests = self.hydraJobs.installTests.all.${system};
nixpkgsLibTests = self.hydraJobs.tests.nixpkgsLibTests.${system};
} // (lib.optionalAttrs (builtins.elem system linux64BitSystems)) {
dockerImage = self.hydraJobs.dockerImage.${system};
Expand Down
6 changes: 6 additions & 0 deletions tests/build-remote.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
if ! canUseSandbox; then exit 99; fi
if ! [[ $busybox =~ busybox ]]; then exit 99; fi

# system-features=... store query param is not supported with 2.3; store
# features is just in the global settings. A bit tricky to feed different
# nix.conf files to these ssh stores which are processes spawned by the outer
# Nix, so maybe we should just backport this feature?
requireDaemonVersionAtleast "2.4pre"

unset NIX_STORE_DIR
unset NIX_STATE_DIR

Expand Down
2 changes: 1 addition & 1 deletion tests/ca/build-with-garbage-path.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

source common.sh

requireDaemonNewerThan "2.4pre20210621"
requireDaemonVersionAtleast "2.4pre20210621"

# Get the output path of `rootCA`, and put some garbage instead
outPath="$(nix-build ./content-addressed.nix -A rootCA --no-out-link)"
Expand Down
2 changes: 2 additions & 0 deletions tests/ca/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ source ../common.sh

enableFeatures "ca-derivations"

requireDaemonVersionAtleast "2.4pre"

restartDaemon
2 changes: 1 addition & 1 deletion tests/ca/duplicate-realisation-in-closure.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source ./common.sh

requireDaemonNewerThan "2.4pre20210625"
requireDaemonVersionAtleast "2.4pre20210625"

export REMOTE_STORE_DIR="$TEST_ROOT/remote_store"
export REMOTE_STORE="file://$REMOTE_STORE_DIR"
Expand Down
2 changes: 1 addition & 1 deletion tests/ca/post-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source common.sh

requireDaemonNewerThan "2.4pre20210626"
requireDaemonVersionAtleast "2.4pre20210626"

export NIX_TESTS_CA_BY_DEFAULT=1
cd ..
Expand Down
2 changes: 1 addition & 1 deletion tests/ca/recursive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source common.sh

requireDaemonNewerThan "2.4pre20210623"
requireDaemonVersionAtleast "2.4pre20210623"

export NIX_TESTS_CA_BY_DEFAULT=1
cd ..
Expand Down
22 changes: 16 additions & 6 deletions tests/common/vars-and-functions.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,15 @@ startDaemon() {
fi
# Start the daemon, wait for the socket to appear.
rm -f $NIX_DAEMON_SOCKET_PATH
PATH=$DAEMON_PATH nix-daemon &
if isDaemonVersionAtleast 2.4; then
local -a daemonProc=(nix daemon)
else
local -a daemonProc=(nix-daemon)
fi
PATH=$DAEMON_PATH "${daemonProc[@]}" \
1> >(tee "$TEST_ROOT/daemon-out" >&1) \
2> >(tee "$TEST_ROOT/daemon-err" >&2) &
_NIX_TEST_DAEMON_PID=$!
export _NIX_TEST_DAEMON_PID
for ((i = 0; i < 300; i++)); do
if [[ -S $NIX_DAEMON_SOCKET_PATH ]]; then
DAEMON_STARTED=1
Expand Down Expand Up @@ -145,15 +151,19 @@ if [[ $(uname) == Linux ]] && [[ -L /proc/self/ns/user ]] && unshare --user true
_canUseSandbox=1
fi

isDaemonNewer () {
isDaemonVersionAtleast () {
[[ -n "${NIX_DAEMON_PACKAGE:-}" ]] || return 0
local requiredVersion="$1"
local daemonVersion=$($NIX_DAEMON_PACKAGE/bin/nix-daemon --version | cut -d' ' -f3)
[[ $(nix eval --expr "builtins.compareVersions ''$daemonVersion'' ''$requiredVersion''") -ge 0 ]]
# N.B. We might have have written nix.conf to have nix-command yet.
[[ $(nix eval \
--extra-experimental-features 'nix-command' \
--expr "builtins.compareVersions ''$daemonVersion'' ''$requiredVersion''") -ge 0 ]]
}

requireDaemonNewerThan () {
isDaemonNewer "$1" || exit 99
requireDaemonVersionAtleast () {
echo "Daemon is too old for this test, skipping..."
isDaemonVersionAtleast "$1" || exit 99
}

canUseSandbox() {
Expand Down
20 changes: 12 additions & 8 deletions tests/fetchurl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,24 @@ outPath=$(nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url file:

cmp $outPath fetchurl.sh

# Test that we can substitute from a different store dir.
clearStore

other_store=file://$TEST_ROOT/other_store?store=/fnord/store
# In 2.3 we couldn't do this, and had to rely on --hashed-mirrors ad-hoc thing
# instead.
if isDaemonVersionAtleast "2.4pre"; then
# Test that we can substitute from a different store dir.
other_store=file://$TEST_ROOT/other_store?store=/fnord/store

hash=$(nix hash file --type sha256 --base16 ./fetchurl.sh)
hash=$(nix hash file --type sha256 --base16 ./fetchurl.sh)

storePath=$(nix --store $other_store store add-file ./fetchurl.sh)
storePath=$(nix --store $other_store store add-file ./fetchurl.sh)

outPath=$(nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url file:///no-such-dir/fetchurl.sh --argstr sha256 $hash --no-out-link --substituters $other_store)
outPath=$(nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url file:///no-such-dir/fetchurl.sh --argstr sha256 $hash --no-out-link --substituters $other_store)

# Test hashed mirrors with an SRI hash.
nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url file:///no-such-dir/fetchurl.sh --argstr hash $(nix hash to-sri --type sha256 $hash) \
--no-out-link --substituters $other_store
# Test hashed mirrors with an SRI hash.
nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url file:///no-such-dir/fetchurl.sh --argstr hash $(nix hash to-sri --type sha256 $hash) \
--no-out-link --substituters $other_store
fi

# Test unpacking a NAR.
rm -rf $TEST_ROOT/archive
Expand Down
2 changes: 1 addition & 1 deletion tests/fixed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ nix path-info --json $path | grep fixed:md5:2qk15sxzzjlnpjk9brn7j8ppcd
echo 'testing good...'
nix-build fixed.nix -A good --no-out-link

if isDaemonNewer "2.4pre20210927"; then
if isDaemonVersionAtleast "2.4pre20210927"; then
echo 'testing --check...'
nix-build fixed.nix -A check --check && fail "should fail"
fi
Expand Down
2 changes: 2 additions & 0 deletions tests/nix-channel.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
source common.sh

requireDaemonVersionAtleast "2.4pre"

clearProfiles

rm -f $TEST_HOME/.nix-channels $TEST_HOME/.nix-profile
Expand Down
3 changes: 3 additions & 0 deletions tests/pass-as-file.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
source common.sh

# TODO debug failure with 2.3
requireDaemonVersionAtleast "2.4pre"

clearStore

outPath=$(nix-build --no-out-link -E "
Expand Down
5 changes: 4 additions & 1 deletion tests/post-hook.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
source common.sh

# TODO debug failure with 2.3
requireDaemonVersionAtleast "2.4pre"

clearStore

rm -f $TEST_ROOT/result

export REMOTE_STORE=file:$TEST_ROOT/remote_store
export REMOTE_STORE=file://$TEST_ROOT/remote_store
echo 'require-sigs = false' >> $NIX_CONF_DIR/nix.conf

restartDaemon
Expand Down
18 changes: 11 additions & 7 deletions tests/recursive.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
source common.sh

# No recursive Nix prior.
requireDaemonVersionAtleast "2.4pre"

sed -i 's/experimental-features .*/& recursive-nix/' "$NIX_CONF_DIR"/nix.conf
restartDaemon

Expand All @@ -8,11 +11,12 @@ if [[ $(uname) != Linux ]]; then exit 99; fi

clearStore

rm -f $TEST_ROOT/result
rm -f "$TEST_ROOT/result"

export unreachable=$(nix store add-path ./recursive.sh)
export unreachable
unreachable=$(nix store add-path ./recursive.sh)

NIX_BIN_DIR=$(dirname $(type -p nix)) nix --extra-experimental-features 'nix-command recursive-nix' build -o $TEST_ROOT/result -L --impure --expr '
NIX_BIN_DIR=$(dirname "$(type -p nix)") nix --extra-experimental-features 'nix-command recursive-nix' build -o "$TEST_ROOT/result" -L --impure --expr '
with import ./config.nix;
mkDerivation rec {
name = "recursive";
Expand Down Expand Up @@ -70,9 +74,9 @@ NIX_BIN_DIR=$(dirname $(type -p nix)) nix --extra-experimental-features 'nix-com
}
'

[[ $(cat $TEST_ROOT/result/inner1) =~ blaat ]]
[[ "$(cat "$TEST_ROOT/result/inner1")" =~ blaat ]]

# Make sure the recursively created paths are in the closure.
nix path-info -r $TEST_ROOT/result | grep foobar
nix path-info -r $TEST_ROOT/result | grep fnord
nix path-info -r $TEST_ROOT/result | grep inner1
nix path-info -r "$TEST_ROOT/result" | grep foobar
nix path-info -r "$TEST_ROOT/result" | grep fnord
nix path-info -r "$TEST_ROOT/result" | grep inner1
Loading