From 81174a5ad6207278991b7c56004e533459e04c12 Mon Sep 17 00:00:00 2001 From: alexion Date: Tue, 13 Oct 2026 20:32:20 -0400 Subject: [PATCH] refactor(copyparty): derive effective volume defaults --- configs/nixos/modules/services/copyparty.nix | 90 ++++++++++---------- 1 file changed, 43 insertions(+), 47 deletions(-) diff --git a/configs/nixos/modules/services/copyparty.nix b/configs/nixos/modules/services/copyparty.nix index 9e2ce74..0461df3 100644 --- a/configs/nixos/modules/services/copyparty.nix +++ b/configs/nixos/modules/services/copyparty.nix @@ -19,6 +19,15 @@ let writableVolumes = lib.filter (volume: !volume.readOnly) (lib.attrValues cfg.volumes); port = 3923; + defaultAccess = { + A = [ accountName ]; + }; + + defaultWritableFlags = { + d2d = true; + d2t = true; + dthumb = true; + }; credentialHash = builtins.substring 0 16 (builtins.hashString "sha256" accountName); @@ -58,11 +67,9 @@ let ); renderedVolumes = lib.mapAttrs (_urlPath: volume: { - inherit (volume) - access - path - ; - flags = volumeFlags volume.flags; + inherit (volume) path; + access = if volume.readOnly then { r = [ accountName ]; } else defaultAccess // volume.access; + flags = volumeFlags (lib.optionalAttrs (!volume.readOnly) defaultWritableFlags // volume.flags); }) cfg.volumes; configText = util.formats.copyparty.render { @@ -89,49 +96,38 @@ in volumes = lib.mkOption { type = lib.types.attrsOf ( - lib.types.submodule ( - { config, ... }: - { - 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 = 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."; - }; + 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" ]; + }; + 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; + }; + description = "Sets Copyparty volume flags."; + }; + }; + } ); default = { }; description = "Defines Copyparty volumes by URL path.";