66 lines
1.7 KiB
Nix
66 lines
1.7 KiB
Nix
{
|
|
lib,
|
|
pkgs,
|
|
}:
|
|
cfg:
|
|
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 <<EOF
|
|
[global]
|
|
p: ${toString cfg.port}
|
|
usernames
|
|
http-only
|
|
no-crt
|
|
no-thumb
|
|
no-snap
|
|
no-rescan
|
|
ses-db: ${cfg.stateDir}/sessions.db
|
|
chpw-db: ${cfg.stateDir}/chpw.json
|
|
shr-db: ${cfg.stateDir}/shares.db
|
|
${renderedReverseProxy}
|
|
[accounts]
|
|
${cfg.accountName}: $password
|
|
|
|
${renderedVolumes}
|
|
EOF
|
|
''
|