From 795c26dca5d17874fc0a08899776f48b33e6cf4c Mon Sep 17 00:00:00 2001 From: Artemis Tosini Date: Thu, 19 Feb 2026 16:03:06 -0500 Subject: [PATCH] tests/nix-daemon-unprivileged: Add test for non-root nix daemon --- nixos/tests/all-tests.nix | 1 + nixos/tests/nix-daemon-unprivileged.nix | 38 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 nixos/tests/nix-daemon-unprivileged.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index a4c56e474fba..bff977f16733 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -1099,6 +1099,7 @@ in nix-channel = pkgs.callPackage ../modules/config/nix-channel/test.nix { }; nix-config = runTest ./nix-config.nix; nix-daemon-firewall = runTest ./nix-daemon-firewall.nix; + nix-daemon-unprivileged = runTest ./nix-daemon-unprivileged.nix; nix-ld = runTest ./nix-ld.nix; nix-misc = handleTest ./nix/misc.nix { }; nix-required-mounts = runTest ./nix-required-mounts; diff --git a/nixos/tests/nix-daemon-unprivileged.nix b/nixos/tests/nix-daemon-unprivileged.nix new file mode 100644 index 000000000000..34aa3d8b83ce --- /dev/null +++ b/nixos/tests/nix-daemon-unprivileged.nix @@ -0,0 +1,38 @@ +{ lib, pkgs, ... }: +{ + name = "nix-daemon-unprivileged"; + meta.maintainers = with lib.maintainers; [ artemist ]; + + nodes.machine = { + users.groups.nix-daemon = { }; + users.users.nix-daemon = { + isSystemUser = true; + group = "nix-daemon"; + }; + + nix = { + package = pkgs.nixVersions.git; + daemonUser = "nix-daemon"; + daemonGroup = "nix-daemon"; + settings.experimental-features = [ + "local-overlay-store" + "auto-allocate-uids" + ]; + }; + + # Easiest way to get a file onto the machine + environment.etc."test.nix".text = '' + derivation { + name = "test"; + builder = "/bin/sh"; + args = [ "-c" "echo succeeded > $out" ]; + system = "${pkgs.stdenv.hostPlatform.system}"; + } + ''; + }; + testScript = '' + start_all() + machine.wait_for_unit("sockets.target") + machine.succeed("NIX_REMOTE=daemon nix-build /etc/test.nix") + ''; +}