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,11 +5,8 @@
}: }:
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 = { options = {
hostPath = lib.mkOption { hostPath = lib.mkOption {
type = lib.types.str; type = lib.types.str;
@@ -23,7 +20,7 @@ let
access = lib.mkOption { access = lib.mkOption {
type = lib.types.attrsOf (lib.types.listOf lib.types.str); type = lib.types.attrsOf (lib.types.listOf lib.types.str);
default.A = [ accountName ]; default = { };
description = "Copyparty access map from permission string to account names."; description = "Copyparty access map from permission string to account names.";
}; };
@@ -35,20 +32,11 @@ let
flags = lib.mkOption { flags = lib.mkOption {
type = lib.types.attrs; type = lib.types.attrs;
default = default = { };
if config.readOnly then
{ }
else
{
d2d = true;
d2t = true;
dthumb = true;
};
description = "Copyparty volume flags."; 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 (
_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 = {

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,7 +89,9 @@ in
volumes = lib.mkOption { volumes = lib.mkOption {
type = lib.types.attrsOf ( type = lib.types.attrsOf (
lib.types.submodule { lib.types.submodule (
{ config, ... }:
{
options = { options = {
path = lib.mkOption { path = lib.mkOption {
type = lib.types.externalPath; type = lib.types.externalPath;
@@ -98,7 +100,7 @@ in
access = lib.mkOption { access = lib.mkOption {
type = lib.types.attrsOf (lib.types.listOf lib.types.str); type = lib.types.attrsOf (lib.types.listOf lib.types.str);
default = { }; default = if config.readOnly then { r = [ accountName ]; } else { A = [ accountName ]; };
example = { example = {
A = [ "alexion" ]; A = [ "alexion" ];
}; };
@@ -113,7 +115,15 @@ in
flags = lib.mkOption { flags = lib.mkOption {
type = lib.types.attrs; type = lib.types.attrs;
default = { }; default =
if config.readOnly then
{ }
else
{
d2d = true;
d2t = true;
dthumb = true;
};
example = { example = {
dthumb = true; dthumb = true;
}; };
@@ -121,6 +131,7 @@ in
}; };
}; };
} }
)
); );
default = { }; default = { };
description = "Defines Copyparty volumes by URL path."; description = "Defines Copyparty volumes by URL path.";