aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/functional/flakes/flake-registry.sh72
-rw-r--r--tests/functional/meson.build1
-rw-r--r--tests/nixos/coredumps/default.nix15
-rw-r--r--tests/nixos/coredumps/package.nix16
-rw-r--r--tests/nixos/default.nix2
-rw-r--r--tests/nixos/github-flakes.nix2
-rw-r--r--tests/nixos/util.nix7
7 files changed, 114 insertions, 1 deletions
diff --git a/tests/functional/flakes/flake-registry.sh b/tests/functional/flakes/flake-registry.sh
new file mode 100644
index 000000000..73ab353bf
--- /dev/null
+++ b/tests/functional/flakes/flake-registry.sh
@@ -0,0 +1,72 @@
+source ./common.sh
+
+# remove the flake registry from nix.conf, to set to default ("vendored")
+sed -i '/flake-registry/d' "$NIX_CONF_DIR/nix.conf"
+
+# Make sure the vendored registry contains the correct amount.
+[[ $(nix registry list | wc -l) == 37 ]]
+# sanity check, contains the important ones
+nix registry list | grep '^global flake:nixpkgs'
+nix registry list | grep '^global flake:home-manager'
+
+
+# it should work the same if we set to vendored directly.
+echo 'flake-registry = vendored' >> "$NIX_CONF_DIR/nix.conf"
+[[ $(nix registry list | wc -l) == 37 ]]
+# sanity check, contains the important ones
+nix registry list | grep '^global flake:nixpkgs'
+nix registry list | grep '^global flake:home-manager'
+
+
+# the online flake registry should still work, but it is deprecated.
+set -m
+# port 0: auto pick a free port, unbufferred output
+python3 -u -m http.server 0 --bind 127.0.0.1 > server.out &
+# wait for the http server to admit it is working
+while ! grep -qP 'port \d+' server.out ; do
+ echo 'waiting for python http' >&2
+ sleep 0.2
+done
+
+port=$(awk 'match($0,/port ([[:digit:]]+)/, ary) { print ary[1] }' server.out)
+
+sed -i '/flake-registry/d' "$NIX_CONF_DIR/nix.conf"
+echo "flake-registry = http://127.0.0.1:$port/flake-registry.json" >> "$NIX_CONF_DIR/nix.conf"
+cat <<EOF > flake-registry.json
+{
+ "flakes": [
+ {
+ "from": {
+ "type": "indirect",
+ "id": "nixpkgs"
+ },
+ "to": {
+ "type": "github",
+ "owner": "NixOS",
+ "repo": "nixpkgs"
+ }
+ },
+ {
+ "from": {
+ "type": "indirect",
+ "id": "private-flake"
+ },
+ "to": {
+ "type": "github",
+ "owner": "fancy-enterprise",
+ "repo": "private-flake"
+ }
+ }
+ ],
+ "version": 2
+}
+EOF
+
+[[ $(nix registry list | wc -l) == 2 ]]
+nix registry list | grep '^global flake:nixpkgs'
+nix registry list | grep '^global flake:private-flake'
+
+# make sure we have a warning:
+nix registry list 2>&1 | grep "config option flake-registry referring to a URL is deprecated and will be removed"
+
+kill %1
diff --git a/tests/functional/meson.build b/tests/functional/meson.build
index 1e68cfe8c..a13dee001 100644
--- a/tests/functional/meson.build
+++ b/tests/functional/meson.build
@@ -69,6 +69,7 @@ functional_tests_scripts = [
'flakes/unlocked-override.sh',
'flakes/absolute-paths.sh',
'flakes/build-paths.sh',
+ 'flakes/flake-registry.sh',
'flakes/flake-in-submodule.sh',
'gc.sh',
'nix-collect-garbage-d.sh',
diff --git a/tests/nixos/coredumps/default.nix b/tests/nixos/coredumps/default.nix
new file mode 100644
index 000000000..3d0d62945
--- /dev/null
+++ b/tests/nixos/coredumps/default.nix
@@ -0,0 +1,15 @@
+let
+ inherit (import ../util.nix) mkNixBuildTest;
+in mkNixBuildTest rec {
+ name = "coredumps";
+ extraMachineConfig = { pkgs, ... }: {
+ boot.kernel.sysctl."kernel.core_pattern" = "core";
+ };
+
+ expressionFile = ./package.nix;
+
+ testScriptPost = ''
+ # do a test, but this time with coredumps enabled.
+ machine.succeed('nix-build --option enable-core-dumps true --expr "let pkgs = import <nixpkgs> {}; in pkgs.callPackage ${expressionFile} { shouldBePresent = true; }"')
+ '';
+}
diff --git a/tests/nixos/coredumps/package.nix b/tests/nixos/coredumps/package.nix
new file mode 100644
index 000000000..a7f6434ed
--- /dev/null
+++ b/tests/nixos/coredumps/package.nix
@@ -0,0 +1,16 @@
+{ lib, runCommand, shouldBePresent ? false }:
+
+runCommand "core-dump-now" { } ''
+ set -m
+ sleep infinity &
+
+ # make a coredump
+ kill -SIGSEGV %1
+
+ if ${lib.optionalString (shouldBePresent) "!"} test -n "$(find . -maxdepth 1 -name 'core*' -print -quit)"; then
+ echo "core file was in wrong presence state, expected: ${if shouldBePresent then "present" else "missing"}"
+ exit 1
+ fi
+
+ touch $out
+''
diff --git a/tests/nixos/default.nix b/tests/nixos/default.nix
index 987463b07..9dd888916 100644
--- a/tests/nixos/default.nix
+++ b/tests/nixos/default.nix
@@ -166,4 +166,6 @@ in
rootInSandbox = runNixOSTestFor "x86_64-linux" ./root-in-sandbox;
broken-userns = runNixOSTestFor "x86_64-linux" ./broken-userns.nix;
+
+ coredumps = runNixOSTestFor "x86_64-linux" ./coredumps;
}
diff --git a/tests/nixos/github-flakes.nix b/tests/nixos/github-flakes.nix
index 1954208b9..e3437c5e8 100644
--- a/tests/nixos/github-flakes.nix
+++ b/tests/nixos/github-flakes.nix
@@ -146,6 +146,8 @@ in
virtualisation.additionalPaths = [ pkgs.hello pkgs.fuse ];
virtualisation.memorySize = 4096;
nix.settings.substituters = lib.mkForce [ ];
+ # note: URL flake-registries are currently deprecated.
+ nix.settings.flake-registry = "https://channels.nixos.org/flake-registry.json";
nix.extraOptions = "experimental-features = nix-command flakes";
networking.hosts.${(builtins.head nodes.github.networking.interfaces.eth1.ipv4.addresses).address} =
[ "channels.nixos.org" "api.github.com" "github.com" ];
diff --git a/tests/nixos/util.nix b/tests/nixos/util.nix
index 0c51cc075..1b8b4223c 100644
--- a/tests/nixos/util.nix
+++ b/tests/nixos/util.nix
@@ -1,5 +1,6 @@
{
- mkNixBuildTest = { name, expressionFile, extraMachineConfig ? {} }:
+ mkNixBuildTest =
+ { name, expressionFile, extraMachineConfig ? {}, testScriptPre ? "", testScriptPost ? "" }:
{ lib, pkgs, ... }:
{
inherit name;
@@ -17,7 +18,11 @@
testScript = { nodes }: ''
start_all()
+ ${testScriptPre}
+
machine.succeed('nix-build --expr "let pkgs = import <nixpkgs> {}; in pkgs.callPackage ${expressionFile} {}"')
+
+ ${testScriptPost}
'';
};
}