From a5870ba1d65487ceef7f2fb7525022d17d4e087f Mon Sep 17 00:00:00 2001 From: Kaleb Debre Date: Fri, 3 Oct 2025 12:57:57 +0200 Subject: [PATCH] nixos module - allow for setting only the user or group under which the service runs + readme.md --- README.md | 10 ++++++++++ contrib/nixos/modules/copyparty.nix | 17 ++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 06a35efb..97232c9c 100644 --- a/README.md +++ b/README.md @@ -2466,6 +2466,10 @@ copyparty on NixOS is configured via `services.copyparty` options, for example: ```nix services.copyparty = { enable = true; + # the user to run the service as + user = "copyparty"; + # the group to run the service as + group = "copyparty"; # directly maps to values in the [global] section of the copyparty config. # see `copyparty --help` for available options settings = { @@ -2490,6 +2494,12 @@ services.copyparty = { k.passwordFile = "/run/keys/copyparty/k_password"; }; + # create a group + groups = { + # users "ed" and "k" are part of the group g1 + g1 = [ "ed" "k" ]; + }; + # create a volume volumes = { # create a volume at "/" (the webroot), which will diff --git a/contrib/nixos/modules/copyparty.nix b/contrib/nixos/modules/copyparty.nix index 2a553003..ed183fb9 100644 --- a/contrib/nixos/modules/copyparty.nix +++ b/contrib/nixos/modules/copyparty.nix @@ -370,12 +370,16 @@ in ) cfg.volumes ); - users.groups.copyparty = lib.mkIf (cfg.user == "copyparty" && cfg.group == "copyparty") { }; - users.users.copyparty = lib.mkIf (cfg.user == "copyparty" && cfg.group == "copyparty") { - description = "Service user for copyparty"; - group = "copyparty"; - home = externalStateDir; - isSystemUser = true; + users.groups = lib.mkIf (cfg.group == "copyparty") { + copyparty = { }; + }; + users.users = lib.mkIf (cfg.user == "copyparty") { + copyparty = { + description = "Service user for copyparty"; + group = cfg.group; + home = externalStateDir; + isSystemUser = true; + }; }; environment.systemPackages = lib.mkIf cfg.mkHashWrapper [ (pkgs.writeShellScriptBin "copyparty-hash" '' @@ -394,4 +398,3 @@ in } ); } -