refactor(copyparty): separate deployment and service policy
Move Copyparty rendering into shared dotfiles utilities, keep guest wiring focused on host/container plumbing, and let the service module derive effective volume policy.
This commit was merged in pull request #182.
This commit is contained in:
@@ -14,7 +14,7 @@ let
|
||||
registry = registry.collected;
|
||||
};
|
||||
|
||||
util = import ./util.nix { inherit lib; };
|
||||
util = import ./util { inherit lib; };
|
||||
|
||||
registry = import ./registry.nix {
|
||||
inherit lib util;
|
||||
|
||||
@@ -21,8 +21,9 @@ let
|
||||
value: entries: builtins.length (lib.unique (map value entries)) == builtins.length entries;
|
||||
in
|
||||
{
|
||||
inherit collectNixFiles;
|
||||
formats.copyparty = import ./format-copyparty.nix { inherit lib; };
|
||||
|
||||
inherit collectNixFiles;
|
||||
removeNixSuffix = path: lib.removeSuffix ".nix" (builtins.baseNameOf path);
|
||||
|
||||
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