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
cfg = config.guests.copyparty; # NOLINT(let_order)
accountName = config.user.name;
volumeType = lib.types.submodule (
{ config, ... }:
{
options = {
hostPath = lib.mkOption {
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.";
};
volumeType = lib.types.submodule {
options = {
hostPath = lib.mkOption {
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 = { };
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";
in
{
@@ -108,14 +96,17 @@ in
enable = cfg.reverseProxy.enable;
inherit (cfg.reverseProxy) trustedSources;
};
volumes = lib.mapAttrs (_urlPath: volume: {
inherit (volume)
path
access
flags
readOnly
;
}) cfg.volumes;
volumes = lib.mapAttrs (
_urlPath: volume:
{
inherit (volume)
path
readOnly
;
}
// lib.optionalAttrs (volume.access != { }) { inherit (volume) access; }
// lib.optionalAttrs (volume.flags != { }) { inherit (volume) flags; }
) cfg.volumes;
};
mounts = {

View File

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

View File

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