diff --git a/nixos/modules/misc/ids.nix b/nixos/modules/misc/ids.nix index 2cbbbc522e1d..858c7ee53dbb 100644 --- a/nixos/modules/misc/ids.nix +++ b/nixos/modules/misc/ids.nix @@ -229,7 +229,7 @@ in grafana = 196; skydns = 197; # ripple-rest = 198; # unused, removed 2017-08-12 - nix-serve = 199; + # nix-serve = 199; # unused, removed 2020-12-12 tvheadend = 200; uwsgi = 201; gitit = 202; diff --git a/nixos/modules/services/networking/nix-serve.nix b/nixos/modules/services/networking/nix-serve.nix index b17f35c769bb..7fc145f2303d 100644 --- a/nixos/modules/services/networking/nix-serve.nix +++ b/nixos/modules/services/networking/nix-serve.nix @@ -69,13 +69,9 @@ in ExecStart = "${pkgs.nix-serve}/bin/nix-serve " + "--listen ${cfg.bindAddress}:${toString cfg.port} ${cfg.extraParams}"; User = "nix-serve"; - Group = "nogroup"; + Group = "nix-serve"; + DynamicUser = true; }; }; - - users.users.nix-serve = { - description = "Nix-serve user"; - uid = config.ids.uids.nix-serve; - }; }; } diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 76e5077f42d5..b018bd6c1317 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -295,6 +295,7 @@ in nginx-sandbox = handleTestOn ["x86_64-linux"] ./nginx-sandbox.nix {}; nginx-sso = handleTest ./nginx-sso.nix {}; nginx-variants = handleTest ./nginx-variants.nix {}; + nix-serve = handleTest ./nix-ssh-serve.nix {}; nix-ssh-serve = handleTest ./nix-ssh-serve.nix {}; nixos-generate-config = handleTest ./nixos-generate-config.nix {}; nomad = handleTest ./nomad.nix {}; diff --git a/nixos/tests/nix-serve.nix b/nixos/tests/nix-serve.nix new file mode 100644 index 000000000000..ab82f4be43e6 --- /dev/null +++ b/nixos/tests/nix-serve.nix @@ -0,0 +1,22 @@ +import ./make-test-python.nix ({ pkgs, ... }: +{ + name = "nix-serve"; + machine = { pkgs, ... }: { + services.nix-serve.enable = true; + environment.systemPackages = [ + pkgs.hello + ]; + }; + testScript = let + pkgHash = builtins.head ( + builtins.match "${builtins.storeDir}/([^-]+).+" (toString pkgs.hello) + ); + in '' + start_all() + machine.wait_for_unit("nix-serve.service") + machine.wait_for_open_port(5000) + machine.succeed( + "curl --fail -g http://0.0.0.0:5000/nar/${pkgHash}.nar -o /tmp/hello.nar" + ) + ''; +}) diff --git a/pkgs/tools/package-management/nix-serve/default.nix b/pkgs/tools/package-management/nix-serve/default.nix index f85adee4917f..a1edfdd1367f 100644 --- a/pkgs/tools/package-management/nix-serve/default.nix +++ b/pkgs/tools/package-management/nix-serve/default.nix @@ -1,5 +1,11 @@ -{ lib, stdenv, fetchFromGitHub, - bzip2, nix, perl, makeWrapper, +{ lib +, stdenv +, fetchFromGitHub +, bzip2 +, nix +, perl +, makeWrapper +, nixosTests }: with lib; @@ -30,6 +36,8 @@ stdenv.mkDerivation { --add-flags $out/libexec/nix-serve/nix-serve.psgi ''; + passthru.tests.nix-serve = nixosTests.nix-serve; + meta = { homepage = "https://github.com/edolstra/nix-serve"; description = "A utility for sharing a Nix store as a binary cache";