{ config, lib, pkgs, ... }: let cfg = config.modules.services.copyparty; # NOLINT(let_order) configScript = let renderedReverseProxy = lib.optionalString cfg.reverseProxy.enable '' rproxy: 1 xff-hdr: x-forwarded-for ${lib.concatStringsSep "\n" (map renderTrustedSource cfg.reverseProxy.trustedSources)} ''; renderTrustedSource = source: " xff-src: ${source}"; renderedVolumes = lib.concatStringsSep "\n" (lib.mapAttrsToList renderVolume cfg.volumes); renderVolume = urlPath: volume: '' [${urlPath}] ${volume.path} accs: ${lib.concatStringsSep "\n" (lib.mapAttrsToList renderAccess volume.access)} ${lib.optionalString (volume.flags != [ ]) '' flags: ${renderFlags volume.flags} ''} ''; renderAccess = permission: accounts: " ${permission}: ${lib.concatStringsSep ", " accounts}"; renderFlags = flags: lib.concatMapStringsSep "\n" (flag: " ${flag}") (flags ++ defaultPermissionFlags flags); defaultPermissionFlags = flags: lib.optionals (!(hasFlag "chmod_d" flags)) [ "chmod_d: 2770" ] ++ lib.optionals (!(hasFlag "chmod_f" flags)) [ "chmod_f: 660" ]; hasFlag = name: flags: lib.any (flag: lib.hasPrefix "${name}:" flag || lib.hasPrefix "${name}=" flag) flags; in pkgs.writeShellScript "copyparty-config" '' set -eu umask 077 password="$(${lib.getExe' pkgs.coreutils "tr"} -d '\n' < "$CREDENTIALS_DIRECTORY/password")" cat > /run/copyparty/copyparty.conf <