From 8544785d6de04106dfc9760ca92dfb33d3966b83 Mon Sep 17 00:00:00 2001 From: alexion Date: Mon, 12 Oct 2026 19:27:45 -0400 Subject: [PATCH] refactor(copyparty): simplify module helpers --- configs/nixos/modules/services/copyparty.nix | 163 ++++++++++--------- 1 file changed, 83 insertions(+), 80 deletions(-) diff --git a/configs/nixos/modules/services/copyparty.nix b/configs/nixos/modules/services/copyparty.nix index 25c1459..64b77c0 100644 --- a/configs/nixos/modules/services/copyparty.nix +++ b/configs/nixos/modules/services/copyparty.nix @@ -7,95 +7,67 @@ let cfg = config.modules.services.copyparty; # NOLINT(let_order) - volumeType = lib.types.submodule { - options = { - path = lib.mkOption { - type = lib.types.str; - description = "Filesystem path served by this volume."; - }; + configScript = + let + renderedReverseProxy = lib.optionalString cfg.reverseProxy.enable '' + rproxy: 1 + xff-hdr: x-forwarded-for + ${lib.concatStringsSep "\n" (map renderTrustedSource cfg.reverseProxy.trustedSources)} + ''; - access = lib.mkOption { - type = lib.types.attrsOf (lib.types.listOf lib.types.str); - default = { }; - example = { - A = [ "alexion" ]; - }; - description = "Copyparty access map from permission string to account names."; - }; + renderTrustedSource = source: " xff-src: ${source}"; - readOnly = lib.mkOption { - type = lib.types.bool; - default = false; - description = "Serve this volume read-only."; - }; + renderedVolumes = lib.concatStringsSep "\n" (lib.mapAttrsToList renderVolume cfg.volumes); - flags = lib.mkOption { - type = lib.types.listOf lib.types.str; - default = [ ]; - example = [ "dthumb" ]; - description = "Copyparty volume flags."; - }; - }; - }; + renderVolume = urlPath: volume: '' + [${urlPath}] + ${volume.path} + accs: + ${lib.concatStringsSep "\n" (lib.mapAttrsToList renderAccess volume.access)} + ${lib.optionalString (volume.flags != [ ]) '' + flags: + ${renderFlags volume.flags} + ''} + ''; - configScript = pkgs.writeShellScript "copyparty-config" '' - set -eu + renderAccess = permission: accounts: " ${permission}: ${lib.concatStringsSep ", " accounts}"; - umask 077 - password="$(${pkgs.coreutils}/bin/tr -d '\n' < "$CREDENTIALS_DIRECTORY/password")" + renderFlags = + flags: lib.concatMapStringsSep "\n" (flag: " ${flag}") (flags ++ defaultPermissionFlags flags); - cat > /run/copyparty/copyparty.conf < /run/copyparty/copyparty.conf <