Skip to content

Commit

Permalink
Test against stable versions
Browse files Browse the repository at this point in the history
Add 2.3 to the flake, and adapt the test to also work with 2.3. Tests
fail, which is expected.
  • Loading branch information
Ericson2314 committed Nov 23, 2021
1 parent 01f2a6a commit 5f7f49c
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 41 deletions.
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 @@ -3,8 +3,10 @@

inputs.nixpkgs.url = "nixpkgs/nixos-21.05-small";
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, lowdown-src }:
outputs = { self, nixpkgs, lowdown-src, nix-2_3-src, nix-2_4 }:

let

Expand Down Expand Up @@ -156,12 +158,7 @@
testNixVersions = pkgs: client: daemon: with commonDeps 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 @@ -496,26 +493,45 @@
'';
*/

installTests = forAllSystems (system:
let pkgs = nixpkgsFor.${system}; 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;
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; };
};

checks = forAllSystems (system: {
binaryTarball = self.hydraJobs.binaryTarball.${system};
perlBindings = self.hydraJobs.perlBindings.${system};
installTests = self.hydraJobs.installTests.${system};
installTests = self.hydraJobs.installTests.all.${system};
});

packages = forAllSystems (system: {
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

sed -i 's/experimental-features .*/& ca-derivations ca-references/' "$NIX_CONF_DIR"/nix.conf

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"

sed -i 's/experimental-features .*/& ca-derivations ca-references/' "$NIX_CONF_DIR"/nix.conf

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"

sed -i 's/experimental-features .*/& ca-derivations ca-references nix-command flakes/' "$NIX_CONF_DIR"/nix.conf

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"

sed -i 's/experimental-features .*/& ca-derivations ca-references nix-command flakes/' "$NIX_CONF_DIR"/nix.conf

Expand Down
14 changes: 10 additions & 4 deletions tests/common.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ startDaemon() {
# Start the daemon, wait for the socket to appear. !!!
# ‘nix-daemon’ should have an option to fork into the background.
rm -f $NIX_DAEMON_SOCKET_PATH
PATH=$DAEMON_PATH nix daemon &
local daemonVersion=$($NIX_DAEMON_PACKAGE/bin/nix-daemon --version | cut -d' ' -f3)
if isDaemonVersionAtleast 2.4; then
PATH=$DAEMON_PATH nix daemon &
else
PATH=$DAEMON_PATH nix-daemon &
fi
for ((i = 0; i < 30; i++)); do
if [[ -S $NIX_DAEMON_SOCKET_PATH ]]; then break; fi
sleep 1
Expand Down Expand Up @@ -125,15 +130,16 @@ 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 ]]
}

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

canUseSandbox() {
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
22 changes: 14 additions & 8 deletions tests/recursive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ 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 '
requiredSystemFeatures=()
if isDaemonVersionAtleast "2.4pre"; then
requiredSystemFeatures+=(recursive-nix)
fi

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 All @@ -24,7 +30,7 @@ NIX_BIN_DIR=$(dirname $(type -p nix)) nix --extra-experimental-features 'nix-com
NIX_TESTS_CA_BY_DEFAULT = builtins.getEnv "NIX_TESTS_CA_BY_DEFAULT";
requiredSystemFeatures = [ "recursive-nix" ];
requiredSystemFeatures = [ '"$(printf '"%s" ' "${requiredSystemFeatures[@]}")"'];
buildCommand = '\'\''
mkdir $out
Expand Down Expand Up @@ -70,9 +76,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
2 changes: 1 addition & 1 deletion tests/structured-attrs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ source common.sh

# 27ce722638 required some incompatible changes to the nix file, so skip this
# tests for the older versions
requireDaemonNewerThan "2.4pre20210712"
requireDaemonVersionAtleast "2.4pre20210712"

clearStore

Expand Down

0 comments on commit 5f7f49c

Please sign in to comment.