refactor(copyparty): move volume defaults to service

This commit is contained in:
2026-10-13 11:27:47 -04:00
parent 161103ad7c
commit 96006c7236
3 changed files with 82 additions and 82 deletions

View File

@@ -5,50 +5,38 @@
}: }:
let let
cfg = config.guests.copyparty; # NOLINT(let_order) cfg = config.guests.copyparty; # NOLINT(let_order)
accountName = config.user.name;
volumeType = lib.types.submodule ( volumeType = lib.types.submodule {
{ config, ... }: options = {
{ hostPath = lib.mkOption {
options = { type = lib.types.str;
hostPath = lib.mkOption { description = "Host path bind-mounted into the Copyparty guest for this volume.";
type = lib.types.str;
description = "Host path bind-mounted into the Copyparty guest for this volume.";
};
path = lib.mkOption {
type = lib.types.str;
description = "Guest path served by this Copyparty volume.";
};
access = lib.mkOption {
type = lib.types.attrsOf (lib.types.listOf lib.types.str);
default.A = [ accountName ];
description = "Copyparty access map from permission string to account names.";
};
readOnly = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Serve this Copyparty volume read-only.";
};
flags = lib.mkOption {
type = lib.types.attrs;
default =
if config.readOnly then
{ }
else
{
d2d = true;
d2t = true;
dthumb = true;
};
description = "Copyparty volume flags.";
};
}; };
}
); path = lib.mkOption {
type = lib.types.str;
description = "Guest path served by this Copyparty volume.";
};
access = lib.mkOption {
type = lib.types.attrsOf (lib.types.listOf lib.types.str);
default = { };
description = "Copyparty access map from permission string to account names.";
};
readOnly = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Serve this Copyparty volume read-only.";
};
flags = lib.mkOption {
type = lib.types.attrs;
default = { };
description = "Copyparty volume flags.";
};
};
};
stateDir = "/var/lib/copyparty"; stateDir = "/var/lib/copyparty";
in in
{ {
@@ -108,14 +96,17 @@ in
enable = cfg.reverseProxy.enable; enable = cfg.reverseProxy.enable;
inherit (cfg.reverseProxy) trustedSources; inherit (cfg.reverseProxy) trustedSources;
}; };
volumes = lib.mapAttrs (_urlPath: volume: { volumes = lib.mapAttrs (
inherit (volume) _urlPath: volume:
path {
access inherit (volume)
flags path
readOnly readOnly
; ;
}) cfg.volumes; }
// lib.optionalAttrs (volume.access != { }) { inherit (volume) access; }
// lib.optionalAttrs (volume.flags != { }) { inherit (volume) flags; }
) cfg.volumes;
}; };
mounts = { mounts = {

View File

@@ -129,7 +129,6 @@
"/" = { "/" = {
hostPath = "/pikachu/data/copyparty/root"; hostPath = "/pikachu/data/copyparty/root";
path = "/srv"; path = "/srv";
access.r = [ config.user.name ];
readOnly = true; readOnly = true;
}; };
"/inbox" = { "/inbox" = {
@@ -143,7 +142,6 @@
"/opds" = { "/opds" = {
hostPath = "/pikachu/data/opds"; hostPath = "/pikachu/data/opds";
path = "/pikachu/data/opds"; path = "/pikachu/data/opds";
access.r = [ config.user.name ];
readOnly = true; readOnly = true;
flags.opds = true; flags.opds = true;
}; };

View File

@@ -8,6 +8,8 @@
let let
cfg = config.modules.services.copyparty; # NOLINT(let_order) cfg = config.modules.services.copyparty; # NOLINT(let_order)
accountName = config.user.name;
serviceGroup = "storage"; serviceGroup = "storage";
serviceStateDir = "/var/lib/copyparty"; serviceStateDir = "/var/lib/copyparty";
@@ -18,8 +20,6 @@ let
port = 3923; port = 3923;
accountName = config.user.name;
credentialName = "password-${builtins.substring 0 16 (builtins.hashString "sha256" accountName)}"; credentialName = "password-${builtins.substring 0 16 (builtins.hashString "sha256" accountName)}";
passwordPlaceholder = "@COPYPARTY_PASSWORD_${ passwordPlaceholder = "@COPYPARTY_PASSWORD_${
@@ -89,38 +89,49 @@ in
volumes = lib.mkOption { volumes = lib.mkOption {
type = lib.types.attrsOf ( type = lib.types.attrsOf (
lib.types.submodule { lib.types.submodule (
options = { { config, ... }:
path = lib.mkOption { {
type = lib.types.externalPath; options = {
description = "Sets the filesystem path served by this volume."; 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 { access = lib.mkOption {
type = lib.types.bool; type = lib.types.attrsOf (lib.types.listOf lib.types.str);
default = false; default = if config.readOnly then { r = [ accountName ]; } else { A = [ accountName ]; };
description = "Serves this volume read-only."; example = {
}; A = [ "alexion" ];
};
flags = lib.mkOption { description = "Maps Copyparty permission strings to account names.";
type = lib.types.attrs; };
default = { };
example = { readOnly = lib.mkOption {
dthumb = true; 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.";
}; };
description = "Sets Copyparty volume flags.";
}; };
}; }
} )
); );
default = { }; default = { };
description = "Defines Copyparty volumes by URL path."; description = "Defines Copyparty volumes by URL path.";