From 96006c7236ea7242117979ac38f1b845f062e765 Mon Sep 17 00:00:00 2001 From: alexion Date: Tue, 13 Oct 2026 11:27:47 -0400 Subject: [PATCH] refactor(copyparty): move volume defaults to service --- configs/nixos/guests/copyparty.nix | 91 +++++++++----------- configs/nixos/hosts/pikachu/default.nix | 2 - configs/nixos/modules/services/copyparty.nix | 71 ++++++++------- 3 files changed, 82 insertions(+), 82 deletions(-) diff --git a/configs/nixos/guests/copyparty.nix b/configs/nixos/guests/copyparty.nix index 69305a5..ae38370 100644 --- a/configs/nixos/guests/copyparty.nix +++ b/configs/nixos/guests/copyparty.nix @@ -5,50 +5,38 @@ }: let cfg = config.guests.copyparty; # NOLINT(let_order) - accountName = config.user.name; - volumeType = lib.types.submodule ( - { config, ... }: - { - options = { - hostPath = lib.mkOption { - type = lib.types.str; - description = "Host path bind-mounted into the Copyparty guest for this volume."; - }; - - path = lib.mkOption { - type = lib.types.str; - description = "Guest path served by this Copyparty volume."; - }; - - access = lib.mkOption { - type = lib.types.attrsOf (lib.types.listOf lib.types.str); - default.A = [ accountName ]; - description = "Copyparty access map from permission string to account names."; - }; - - readOnly = lib.mkOption { - type = lib.types.bool; - default = false; - description = "Serve this Copyparty volume read-only."; - }; - - flags = lib.mkOption { - type = lib.types.attrs; - default = - if config.readOnly then - { } - else - { - d2d = true; - d2t = true; - dthumb = true; - }; - description = "Copyparty volume flags."; - }; + volumeType = lib.types.submodule { + options = { + hostPath = lib.mkOption { + type = lib.types.str; + description = "Host path bind-mounted into the Copyparty guest for this volume."; }; - } - ); + + path = lib.mkOption { + type = lib.types.str; + description = "Guest path served by this Copyparty volume."; + }; + + access = lib.mkOption { + type = lib.types.attrsOf (lib.types.listOf lib.types.str); + default = { }; + description = "Copyparty access map from permission string to account names."; + }; + + readOnly = lib.mkOption { + type = lib.types.bool; + default = false; + description = "Serve this Copyparty volume read-only."; + }; + + flags = lib.mkOption { + type = lib.types.attrs; + default = { }; + description = "Copyparty volume flags."; + }; + }; + }; stateDir = "/var/lib/copyparty"; in { @@ -108,14 +96,17 @@ in enable = cfg.reverseProxy.enable; inherit (cfg.reverseProxy) trustedSources; }; - volumes = lib.mapAttrs (_urlPath: volume: { - inherit (volume) - path - access - flags - readOnly - ; - }) cfg.volumes; + volumes = lib.mapAttrs ( + _urlPath: volume: + { + inherit (volume) + path + readOnly + ; + } + // lib.optionalAttrs (volume.access != { }) { inherit (volume) access; } + // lib.optionalAttrs (volume.flags != { }) { inherit (volume) flags; } + ) cfg.volumes; }; mounts = { diff --git a/configs/nixos/hosts/pikachu/default.nix b/configs/nixos/hosts/pikachu/default.nix index 866f7f8..b7bdf4d 100644 --- a/configs/nixos/hosts/pikachu/default.nix +++ b/configs/nixos/hosts/pikachu/default.nix @@ -129,7 +129,6 @@ "/" = { hostPath = "/pikachu/data/copyparty/root"; path = "/srv"; - access.r = [ config.user.name ]; readOnly = true; }; "/inbox" = { @@ -143,7 +142,6 @@ "/opds" = { hostPath = "/pikachu/data/opds"; path = "/pikachu/data/opds"; - access.r = [ config.user.name ]; readOnly = true; flags.opds = true; }; diff --git a/configs/nixos/modules/services/copyparty.nix b/configs/nixos/modules/services/copyparty.nix index 27b2540..7b2dcd7 100644 --- a/configs/nixos/modules/services/copyparty.nix +++ b/configs/nixos/modules/services/copyparty.nix @@ -8,6 +8,8 @@ let cfg = config.modules.services.copyparty; # NOLINT(let_order) + accountName = config.user.name; + serviceGroup = "storage"; serviceStateDir = "/var/lib/copyparty"; @@ -18,8 +20,6 @@ let port = 3923; - accountName = config.user.name; - credentialName = "password-${builtins.substring 0 16 (builtins.hashString "sha256" accountName)}"; passwordPlaceholder = "@COPYPARTY_PASSWORD_${ @@ -89,38 +89,49 @@ in volumes = lib.mkOption { type = lib.types.attrsOf ( - lib.types.submodule { - options = { - path = lib.mkOption { - type = lib.types.externalPath; - description = "Sets the filesystem path served by this volume."; - }; - - access = lib.mkOption { - type = lib.types.attrsOf (lib.types.listOf lib.types.str); - default = { }; - example = { - A = [ "alexion" ]; + lib.types.submodule ( + { config, ... }: + { + options = { + path = lib.mkOption { + type = lib.types.externalPath; + description = "Sets the filesystem path served by this volume."; }; - description = "Maps Copyparty permission strings to account names."; - }; - readOnly = lib.mkOption { - type = lib.types.bool; - default = false; - description = "Serves this volume read-only."; - }; - - flags = lib.mkOption { - type = lib.types.attrs; - default = { }; - example = { - dthumb = true; + access = lib.mkOption { + type = lib.types.attrsOf (lib.types.listOf lib.types.str); + default = if config.readOnly then { r = [ accountName ]; } else { A = [ accountName ]; }; + example = { + A = [ "alexion" ]; + }; + description = "Maps Copyparty permission strings to account names."; + }; + + readOnly = lib.mkOption { + type = lib.types.bool; + default = false; + description = "Serves this volume read-only."; + }; + + flags = lib.mkOption { + type = lib.types.attrs; + default = + if config.readOnly then + { } + else + { + d2d = true; + d2t = true; + dthumb = true; + }; + example = { + dthumb = true; + }; + description = "Sets Copyparty volume flags."; }; - description = "Sets Copyparty volume flags."; }; - }; - } + } + ) ); default = { }; description = "Defines Copyparty volumes by URL path.";