refactor(copyparty): simplify module helpers #182
@@ -5,8 +5,31 @@
|
|||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
cfg = config.guests.copyparty; # NOLINT(let_order)
|
cfg = config.guests.copyparty; # NOLINT(let_order)
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.guests.copyparty = {
|
||||||
|
passwordSecret = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "services/copyparty/users/${config.user.name}/password";
|
||||||
|
description = "SOPS secret name that contains the Copyparty account password.";
|
||||||
|
};
|
||||||
|
|
||||||
volumeType = lib.types.submodule {
|
statePath = lib.mkOption {
|
||||||
|
type = lib.types.nullOr lib.types.str;
|
||||||
|
default = null;
|
||||||
|
example = "/srv/copyparty";
|
||||||
|
description = "Host path bind-mounted as Copyparty's state directory.";
|
||||||
|
};
|
||||||
|
|
||||||
|
reverseProxy.trustedSources = lib.mkOption {
|
||||||
|
type = lib.types.listOf lib.types.str;
|
||||||
|
default = [ ];
|
||||||
|
description = "IP ranges that may supply Copyparty's forwarded client IP header.";
|
||||||
|
};
|
||||||
|
|
||||||
|
volumes = lib.mkOption {
|
||||||
|
type = lib.types.attrsOf (
|
||||||
|
lib.types.submodule {
|
||||||
options = {
|
options = {
|
||||||
hostPath = lib.mkOption {
|
hostPath = lib.mkOption {
|
||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
@@ -31,48 +54,13 @@ let
|
|||||||
};
|
};
|
||||||
|
|
||||||
flags = lib.mkOption {
|
flags = lib.mkOption {
|
||||||
type = lib.types.listOf lib.types.str;
|
type = lib.types.attrs;
|
||||||
default = [ ];
|
default = { };
|
||||||
description = "Copyparty volume flags.";
|
description = "Copyparty volume flags.";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
in
|
);
|
||||||
{
|
|
||||||
options.guests.copyparty = {
|
|
||||||
accountName = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
default = "alexion";
|
|
||||||
description = "Copyparty account name configured for password authentication.";
|
|
||||||
};
|
|
||||||
|
|
||||||
passwordSecret = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
default = "services/copyparty/users/alexion/password";
|
|
||||||
description = "SOPS secret name containing the Copyparty account password.";
|
|
||||||
};
|
|
||||||
|
|
||||||
stateDir = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
default = "/var/lib/copyparty";
|
|
||||||
description = "Guest path where Copyparty stores service state.";
|
|
||||||
};
|
|
||||||
|
|
||||||
statePath = lib.mkOption {
|
|
||||||
type = lib.types.nullOr lib.types.str;
|
|
||||||
default = null;
|
|
||||||
example = "/srv/copyparty";
|
|
||||||
description = "Host path bind-mounted as Copyparty's state directory.";
|
|
||||||
};
|
|
||||||
|
|
||||||
reverseProxy.trustedSources = lib.mkOption {
|
|
||||||
type = lib.types.listOf lib.types.str;
|
|
||||||
default = [ ];
|
|
||||||
description = "IP ranges that may supply Copyparty's forwarded client IP header.";
|
|
||||||
};
|
|
||||||
|
|
||||||
volumes = lib.mkOption {
|
|
||||||
type = lib.types.attrsOf volumeType;
|
|
||||||
default = { };
|
default = { };
|
||||||
description = "Copyparty volumes keyed by their URL path.";
|
description = "Copyparty volumes keyed by their URL path.";
|
||||||
};
|
};
|
||||||
@@ -102,24 +90,26 @@ in
|
|||||||
guests.copyparty = {
|
guests.copyparty = {
|
||||||
interior.modules.services.copyparty = {
|
interior.modules.services.copyparty = {
|
||||||
enable = true;
|
enable = true;
|
||||||
inherit (cfg) accountName stateDir;
|
|
||||||
passwordFile = "/run/secrets/${cfg.passwordSecret}";
|
passwordFile = "/run/secrets/${cfg.passwordSecret}";
|
||||||
reverseProxy = {
|
reverseProxy = {
|
||||||
enable = cfg.reverseProxy.enable;
|
enable = cfg.reverseProxy.enable;
|
||||||
inherit (cfg.reverseProxy) trustedSources;
|
inherit (cfg.reverseProxy) trustedSources;
|
||||||
};
|
};
|
||||||
volumes = lib.mapAttrs (_urlPath: volume: {
|
volumes = lib.mapAttrs (
|
||||||
|
_urlPath: volume:
|
||||||
|
{
|
||||||
inherit (volume)
|
inherit (volume)
|
||||||
path
|
path
|
||||||
access
|
|
||||||
flags
|
|
||||||
readOnly
|
readOnly
|
||||||
;
|
;
|
||||||
}) cfg.volumes;
|
}
|
||||||
|
// lib.optionalAttrs (volume.access != { }) { inherit (volume) access; }
|
||||||
|
// lib.optionalAttrs (volume.flags != { }) { inherit (volume) flags; }
|
||||||
|
) cfg.volumes;
|
||||||
};
|
};
|
||||||
|
|
||||||
mounts = {
|
mounts = {
|
||||||
${cfg.stateDir} = {
|
"/var/lib/copyparty" = {
|
||||||
directory = cfg.statePath;
|
directory = cfg.statePath;
|
||||||
owner = config.registry."stable-uid".${config.networking.hostName}.copyparty;
|
owner = config.registry."stable-uid".${config.networking.hostName}.copyparty;
|
||||||
group = "storage";
|
group = "storage";
|
||||||
|
|||||||
@@ -129,35 +129,21 @@
|
|||||||
"/" = {
|
"/" = {
|
||||||
hostPath = "/pikachu/data/copyparty/root";
|
hostPath = "/pikachu/data/copyparty/root";
|
||||||
path = "/srv";
|
path = "/srv";
|
||||||
access.r = [ "alexion" ];
|
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
};
|
};
|
||||||
"/inbox" = {
|
"/inbox" = {
|
||||||
hostPath = "/pikachu/__inbox";
|
hostPath = "/pikachu/__inbox";
|
||||||
path = "/pikachu/__inbox";
|
path = "/pikachu/__inbox";
|
||||||
access.A = [ "alexion" ];
|
|
||||||
flags = [
|
|
||||||
"d2d"
|
|
||||||
"d2t"
|
|
||||||
"dthumb"
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
"/media" = {
|
"/media" = {
|
||||||
hostPath = "/pikachu/media";
|
hostPath = "/pikachu/media";
|
||||||
path = "/pikachu/media";
|
path = "/pikachu/media";
|
||||||
access.A = [ "alexion" ];
|
|
||||||
flags = [
|
|
||||||
"d2d"
|
|
||||||
"d2t"
|
|
||||||
"dthumb"
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
"/opds" = {
|
"/opds" = {
|
||||||
hostPath = "/pikachu/data/opds";
|
hostPath = "/pikachu/data/opds";
|
||||||
path = "/pikachu/data/opds";
|
path = "/pikachu/data/opds";
|
||||||
access.r = [ "alexion" ];
|
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
flags = [ "opds" ];
|
flags.opds = true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,16 +2,105 @@
|
|||||||
config,
|
config,
|
||||||
lib,
|
lib,
|
||||||
pkgs,
|
pkgs,
|
||||||
|
util,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
cfg = config.modules.services.copyparty; # NOLINT(let_order)
|
cfg = config.modules.services.copyparty; # NOLINT(let_order)
|
||||||
|
|
||||||
volumeType = lib.types.submodule {
|
accountName = config.user.name;
|
||||||
|
|
||||||
|
serviceGroup = "storage";
|
||||||
|
|
||||||
|
serviceStateDir = "/var/lib/copyparty";
|
||||||
|
|
||||||
|
serviceUser = "copyparty";
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
credentialName = "password-${credentialHash}";
|
||||||
|
|
||||||
|
passwordPlaceholder = "@COPYPARTY_PASSWORD_${credentialHash}@";
|
||||||
|
|
||||||
|
globalSettings = {
|
||||||
|
i = "0.0.0.0";
|
||||||
|
usernames = true;
|
||||||
|
"http-only" = true;
|
||||||
|
"no-crt" = true;
|
||||||
|
"no-thumb" = true;
|
||||||
|
"no-snap" = true;
|
||||||
|
"no-rescan" = true;
|
||||||
|
"ses-db" = "${serviceStateDir}/sessions.db";
|
||||||
|
"chpw-db" = "${serviceStateDir}/chpw.json";
|
||||||
|
"shr-db" = "${serviceStateDir}/shares.db";
|
||||||
|
}
|
||||||
|
// lib.optionalAttrs cfg.reverseProxy.enable {
|
||||||
|
rproxy = 1;
|
||||||
|
"xff-hdr" = "x-forwarded-for";
|
||||||
|
};
|
||||||
|
|
||||||
|
globalExtraConfig = lib.optionalString cfg.reverseProxy.enable (
|
||||||
|
lib.concatMapStringsSep "\n" (source: "xff-src: ${source}") cfg.reverseProxy.trustedSources
|
||||||
|
);
|
||||||
|
|
||||||
|
volumeFlags =
|
||||||
|
flags:
|
||||||
|
lib.optionalAttrs (flags != { }) (
|
||||||
|
{
|
||||||
|
chmod_d = "2770";
|
||||||
|
chmod_f = "660";
|
||||||
|
}
|
||||||
|
// flags
|
||||||
|
);
|
||||||
|
|
||||||
|
renderedVolumes = lib.mapAttrs (_urlPath: volume: {
|
||||||
|
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 {
|
||||||
|
inherit globalExtraConfig;
|
||||||
|
accounts.${accountName} = passwordPlaceholder;
|
||||||
|
global = globalSettings;
|
||||||
|
volumes = renderedVolumes;
|
||||||
|
};
|
||||||
|
|
||||||
|
configFile = pkgs.writeText "copyparty.conf" configText;
|
||||||
|
|
||||||
|
replacePassword = ''
|
||||||
|
${lib.getExe pkgs.replace-secret} ${lib.escapeShellArg passwordPlaceholder} "$CREDENTIALS_DIRECTORY/${credentialName}" /run/copyparty/copyparty.conf
|
||||||
|
'';
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.modules.services.copyparty = {
|
||||||
|
enable = lib.mkEnableOption "Copyparty";
|
||||||
|
|
||||||
|
passwordFile = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
description = "Sets the runtime file that contains the Copyparty account password.";
|
||||||
|
};
|
||||||
|
|
||||||
|
volumes = lib.mkOption {
|
||||||
|
type = lib.types.attrsOf (
|
||||||
|
lib.types.submodule {
|
||||||
options = {
|
options = {
|
||||||
path = lib.mkOption {
|
path = lib.mkOption {
|
||||||
type = lib.types.str;
|
type = lib.types.externalPath;
|
||||||
description = "Filesystem path served by this volume.";
|
description = "Sets the filesystem path served by this volume.";
|
||||||
};
|
};
|
||||||
|
|
||||||
access = lib.mkOption {
|
access = lib.mkOption {
|
||||||
@@ -20,129 +109,28 @@ let
|
|||||||
example = {
|
example = {
|
||||||
A = [ "alexion" ];
|
A = [ "alexion" ];
|
||||||
};
|
};
|
||||||
description = "Copyparty access map from permission string to account names.";
|
description = "Maps Copyparty permission strings to account names.";
|
||||||
};
|
};
|
||||||
|
|
||||||
readOnly = lib.mkOption {
|
readOnly = lib.mkOption {
|
||||||
type = lib.types.bool;
|
type = lib.types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
description = "Serve this volume read-only.";
|
description = "Serves this volume read-only.";
|
||||||
};
|
};
|
||||||
|
|
||||||
flags = lib.mkOption {
|
flags = lib.mkOption {
|
||||||
type = lib.types.listOf lib.types.str;
|
type = lib.types.attrs;
|
||||||
default = [ ];
|
|
||||||
example = [ "dthumb" ];
|
|
||||||
description = "Copyparty volume flags.";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
configScript = pkgs.writeShellScript "copyparty-config" ''
|
|
||||||
set -eu
|
|
||||||
|
|
||||||
umask 077
|
|
||||||
password="$(${pkgs.coreutils}/bin/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
|
|
||||||
'';
|
|
||||||
renderAccess = permission: accounts: " ${permission}: ${lib.concatStringsSep ", " accounts}";
|
|
||||||
|
|
||||||
hasFlag =
|
|
||||||
name: flags: lib.any (flag: lib.hasPrefix "${name}:" flag || lib.hasPrefix "${name}=" flag) flags;
|
|
||||||
|
|
||||||
defaultPermissionFlags =
|
|
||||||
flags:
|
|
||||||
lib.optionals (!(hasFlag "chmod_d" flags)) [ "chmod_d: 2770" ]
|
|
||||||
++ lib.optionals (!(hasFlag "chmod_f" flags)) [ "chmod_f: 660" ];
|
|
||||||
|
|
||||||
renderFlags =
|
|
||||||
flags: lib.concatMapStringsSep "\n" (flag: " ${flag}") (flags ++ defaultPermissionFlags flags);
|
|
||||||
|
|
||||||
renderVolume = urlPath: volume: ''
|
|
||||||
[${urlPath}]
|
|
||||||
${volume.path}
|
|
||||||
accs:
|
|
||||||
${lib.concatStringsSep "\n" (lib.mapAttrsToList renderAccess volume.access)}
|
|
||||||
${lib.optionalString (volume.flags != [ ]) ''
|
|
||||||
flags:
|
|
||||||
${renderFlags volume.flags}
|
|
||||||
''}
|
|
||||||
'';
|
|
||||||
|
|
||||||
renderTrustedSource = source: " xff-src: ${source}";
|
|
||||||
|
|
||||||
renderedReverseProxy = lib.optionalString cfg.reverseProxy.enable ''
|
|
||||||
rproxy: 1
|
|
||||||
xff-hdr: x-forwarded-for
|
|
||||||
${lib.concatStringsSep "\n" (map renderTrustedSource cfg.reverseProxy.trustedSources)}
|
|
||||||
'';
|
|
||||||
|
|
||||||
renderedVolumes = lib.concatStringsSep "\n" (lib.mapAttrsToList renderVolume cfg.volumes);
|
|
||||||
|
|
||||||
in
|
|
||||||
{
|
|
||||||
options.modules.services.copyparty = {
|
|
||||||
enable = lib.mkEnableOption "Copyparty";
|
|
||||||
|
|
||||||
package = lib.mkPackageOption pkgs "copyparty-min" { };
|
|
||||||
|
|
||||||
port = lib.mkOption {
|
|
||||||
type = lib.types.port;
|
|
||||||
default = 3923;
|
|
||||||
description = "Port Copyparty listens on.";
|
|
||||||
};
|
|
||||||
|
|
||||||
user = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
default = "copyparty";
|
|
||||||
description = "User account that runs Copyparty.";
|
|
||||||
};
|
|
||||||
|
|
||||||
group = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
default = "storage";
|
|
||||||
description = "Group account that owns Copyparty's writable state and served files.";
|
|
||||||
};
|
|
||||||
|
|
||||||
accountName = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
default = "alexion";
|
|
||||||
description = "Copyparty account name configured for password authentication.";
|
|
||||||
};
|
|
||||||
|
|
||||||
passwordFile = lib.mkOption {
|
|
||||||
type = lib.types.path;
|
|
||||||
description = "Runtime file containing the Copyparty account password.";
|
|
||||||
};
|
|
||||||
|
|
||||||
stateDir = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
default = "/var/lib/copyparty";
|
|
||||||
description = "Directory where Copyparty stores service state.";
|
|
||||||
};
|
|
||||||
|
|
||||||
volumes = lib.mkOption {
|
|
||||||
type = lib.types.attrsOf volumeType;
|
|
||||||
default = { };
|
default = { };
|
||||||
description = "Copyparty volumes keyed by their URL path.";
|
example = {
|
||||||
|
dthumb = true;
|
||||||
|
};
|
||||||
|
description = "Sets Copyparty volume flags.";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
default = { };
|
||||||
|
description = "Defines Copyparty volumes by URL path.";
|
||||||
};
|
};
|
||||||
|
|
||||||
reverseProxy = {
|
reverseProxy = {
|
||||||
@@ -151,7 +139,7 @@ in
|
|||||||
trustedSources = lib.mkOption {
|
trustedSources = lib.mkOption {
|
||||||
type = lib.types.listOf lib.types.str;
|
type = lib.types.listOf lib.types.str;
|
||||||
default = [ ];
|
default = [ ];
|
||||||
description = "IP ranges that may supply Copyparty's forwarded client IP header.";
|
description = "Lists proxy sources that can set Copyparty's forwarded client IP header.";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -173,46 +161,49 @@ in
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
users.users.${cfg.user} = {
|
users.users.${serviceUser} = {
|
||||||
isSystemUser = true;
|
isSystemUser = true;
|
||||||
uid = config.registry."stable-uid".${config.networking.hostName}.copyparty;
|
uid = config.registry."stable-uid".${config.networking.hostName}.copyparty;
|
||||||
inherit (cfg) group;
|
group = serviceGroup;
|
||||||
home = cfg.stateDir;
|
home = serviceStateDir;
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.services.copyparty = {
|
systemd.services.copyparty = {
|
||||||
description = "Copyparty file server";
|
description = "Copyparty file server";
|
||||||
after = [ "network.target" ];
|
after = [ "network.target" ];
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
preStart = ''
|
||||||
|
${lib.getExe' pkgs.coreutils "install"} -m 600 ${configFile} /run/copyparty/copyparty.conf
|
||||||
|
${replacePassword}
|
||||||
|
'';
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
ReloadSignal = "SIGUSR1";
|
ReloadSignal = "SIGUSR1";
|
||||||
Type = "simple";
|
Type = "simple";
|
||||||
User = cfg.user;
|
User = serviceUser;
|
||||||
Group = cfg.group;
|
Group = serviceGroup;
|
||||||
WorkingDirectory = cfg.stateDir;
|
WorkingDirectory = serviceStateDir;
|
||||||
Environment = [
|
Environment = [
|
||||||
"HOME=${cfg.stateDir}"
|
"HOME=${serviceStateDir}"
|
||||||
"XDG_CONFIG_HOME=${cfg.stateDir}"
|
"XDG_CONFIG_HOME=${serviceStateDir}"
|
||||||
];
|
];
|
||||||
StateDirectory = "copyparty";
|
StateDirectory = "copyparty";
|
||||||
RuntimeDirectory = "copyparty";
|
RuntimeDirectory = "copyparty";
|
||||||
RuntimeDirectoryMode = "0700";
|
RuntimeDirectoryMode = "0700";
|
||||||
LoadCredential = [ "password:${cfg.passwordFile}" ];
|
LoadCredential = [ "${credentialName}:${cfg.passwordFile}" ];
|
||||||
ExecStartPre = configScript;
|
ExecStart = "${lib.getExe pkgs.copyparty-min} -c /run/copyparty/copyparty.conf";
|
||||||
ExecStart = "${lib.getExe cfg.package} -c /run/copyparty/copyparty.conf";
|
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
NoNewPrivileges = true;
|
NoNewPrivileges = true;
|
||||||
PrivateTmp = true;
|
PrivateTmp = true;
|
||||||
ProtectSystem = "strict";
|
ProtectSystem = "strict";
|
||||||
ProtectHome = true;
|
ProtectHome = true;
|
||||||
ReadWritePaths = [
|
ReadWritePaths = [
|
||||||
cfg.stateDir
|
serviceStateDir
|
||||||
]
|
]
|
||||||
++ map (volume: volume.path) (lib.filter (volume: !volume.readOnly) (lib.attrValues cfg.volumes));
|
++ map (volume: volume.path) writableVolumes;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
networking.firewall.allowedTCPPorts = [ cfg.port ];
|
networking.firewall.allowedTCPPorts = [ port ];
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ let
|
|||||||
registry = registry.collected;
|
registry = registry.collected;
|
||||||
};
|
};
|
||||||
|
|
||||||
util = import ./util.nix { inherit lib; };
|
util = import ./util { inherit lib; };
|
||||||
|
|
||||||
registry = import ./registry.nix {
|
registry = import ./registry.nix {
|
||||||
inherit lib util;
|
inherit lib util;
|
||||||
|
|||||||
@@ -21,8 +21,9 @@ let
|
|||||||
value: entries: builtins.length (lib.unique (map value entries)) == builtins.length entries;
|
value: entries: builtins.length (lib.unique (map value entries)) == builtins.length entries;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
inherit collectNixFiles;
|
formats.copyparty = import ./format-copyparty.nix { inherit lib; };
|
||||||
|
|
||||||
|
inherit collectNixFiles;
|
||||||
removeNixSuffix = path: lib.removeSuffix ".nix" (builtins.baseNameOf path);
|
removeNixSuffix = path: lib.removeSuffix ".nix" (builtins.baseNameOf path);
|
||||||
|
|
||||||
glyph =
|
glyph =
|
||||||
58
src/dotfiles/util/format-copyparty.nix
Normal file
58
src/dotfiles/util/format-copyparty.nix
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
{ lib }:
|
||||||
|
let
|
||||||
|
renderLine =
|
||||||
|
indent: name: value:
|
||||||
|
if value == true then
|
||||||
|
"${indent}${name}"
|
||||||
|
else if value == false then
|
||||||
|
null
|
||||||
|
else if lib.isList value then
|
||||||
|
"${indent}${name}: ${lib.concatStringsSep ", " (map toString value)}"
|
||||||
|
else
|
||||||
|
"${indent}${name}: ${toString value}";
|
||||||
|
|
||||||
|
renderAttrs =
|
||||||
|
indent: attrs:
|
||||||
|
lib.pipe attrs [
|
||||||
|
lib.attrsToList
|
||||||
|
(map ({ name, value }: renderLine indent name value))
|
||||||
|
(lib.filter (line: line != null))
|
||||||
|
(lib.concatStringsSep "\n")
|
||||||
|
];
|
||||||
|
|
||||||
|
renderSectionName = name: "[${lib.escape [ "[" "]" ] name}]";
|
||||||
|
|
||||||
|
renderSection = name: attrs: ''
|
||||||
|
${renderSectionName name}
|
||||||
|
${renderAttrs "" attrs}
|
||||||
|
'';
|
||||||
|
|
||||||
|
renderSubsection =
|
||||||
|
name: attrs:
|
||||||
|
lib.optionalString (attrs != { }) ''
|
||||||
|
${name}:
|
||||||
|
${renderAttrs " " attrs}
|
||||||
|
'';
|
||||||
|
|
||||||
|
renderVolume = urlPath: volume: ''
|
||||||
|
${renderSectionName urlPath}
|
||||||
|
${volume.path}
|
||||||
|
${renderSubsection "accs" volume.access}
|
||||||
|
${renderSubsection "flags" volume.flags}
|
||||||
|
'';
|
||||||
|
in
|
||||||
|
{
|
||||||
|
render =
|
||||||
|
{
|
||||||
|
accounts,
|
||||||
|
global,
|
||||||
|
volumes,
|
||||||
|
globalExtraConfig ? "",
|
||||||
|
}:
|
||||||
|
''
|
||||||
|
${renderSection "global" global}
|
||||||
|
${globalExtraConfig}
|
||||||
|
${renderSection "accounts" accounts}
|
||||||
|
${lib.concatStringsSep "\n" (lib.mapAttrsToList renderVolume volumes)}
|
||||||
|
'';
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user