diff options
author | h7x4 <h7x4@nani.wtf> | 2023-11-02 04:48:06 +0100 |
---|---|---|
committer | h7x4 <h7x4@nani.wtf> | 2024-02-09 16:40:22 +0100 |
commit | 39a779e269b012c721b34eee74f76afca3d03d7d (patch) | |
tree | 39df6678f8394c66ce8554963bca77b1d1d3eaae /nixos/modules/services/web-apps/suwayomi-server.nix | |
parent | b6cdfec16ce7ce7c0d837b05ed3ad99aa6223647 (diff) | |
download | nixlib-39a779e269b012c721b34eee74f76afca3d03d7d.tar nixlib-39a779e269b012c721b34eee74f76afca3d03d7d.tar.gz nixlib-39a779e269b012c721b34eee74f76afca3d03d7d.tar.bz2 nixlib-39a779e269b012c721b34eee74f76afca3d03d7d.tar.lz nixlib-39a779e269b012c721b34eee74f76afca3d03d7d.tar.xz nixlib-39a779e269b012c721b34eee74f76afca3d03d7d.tar.zst nixlib-39a779e269b012c721b34eee74f76afca3d03d7d.zip |
treewide: use `formats.hocon`
Diffstat (limited to 'nixos/modules/services/web-apps/suwayomi-server.nix')
-rw-r--r-- | nixos/modules/services/web-apps/suwayomi-server.nix | 55 |
1 files changed, 5 insertions, 50 deletions
diff --git a/nixos/modules/services/web-apps/suwayomi-server.nix b/nixos/modules/services/web-apps/suwayomi-server.nix index c4c1540edbee..94dbe6f99356 100644 --- a/nixos/modules/services/web-apps/suwayomi-server.nix +++ b/nixos/modules/services/web-apps/suwayomi-server.nix @@ -3,6 +3,8 @@ let cfg = config.services.suwayomi-server; inherit (lib) mkOption mdDoc mkEnableOption mkIf types; + + format = pkgs.formats.hocon { }; in { options = { @@ -48,19 +50,7 @@ in settings = mkOption { type = types.submodule { - freeformType = - let - recursiveAttrsType = with types; attrsOf (nullOr (oneOf [ - str - path - int - float - bool - (listOf str) - (recursiveAttrsType // { description = "instances of this type recursively"; }) - ])); - in - recursiveAttrsType; + freeformType = format.type; options = { server = { ip = mkOption { @@ -180,38 +170,7 @@ in systemd.services.suwayomi-server = let - flattenConfig = prefix: config: - lib.foldl' - lib.mergeAttrs - { } - (lib.attrValues - (lib.mapAttrs - (k: v: - if !(lib.isAttrs v) - then { "${prefix}${k}" = v; } - else flattenConfig "${prefix}${k}." v - ) - config - ) - ); - - # HOCON is a JSON superset that suwayomi-server use for configuration - toHOCON = attr: - let - attrType = builtins.typeOf attr; - in - if builtins.elem attrType [ "string" "path" "int" "float" ] - then ''"${toString attr}"'' - else if attrType == "bool" - then lib.boolToString attr - else if attrType == "list" - then "[\n${lib.concatMapStringsSep ",\n" toHOCON attr}\n]" - else # attrs, lambda, null - throw '' - [suwayomi-server]: invalid config value type '${attrType}'. - ''; - - configFile = pkgs.writeText "server.conf" (lib.pipe cfg.settings [ + configFile = format.generate "server.conf" (lib.pipe cfg.settings [ (settings: lib.recursiveUpdate settings { server.basicAuthPasswordFile = null; server.basicAuthPassword = @@ -219,12 +178,8 @@ in then "$TACHIDESK_SERVER_BASIC_AUTH_PASSWORD" else null; }) - (flattenConfig "") - (lib.filterAttrs (_: x: x != null)) - (lib.mapAttrsToList (name: value: ''${name} = ${toHOCON value}'')) - lib.concatLines + (lib.filterAttrsRecursive (_: x: x != null)) ]); - in { description = "A free and open source manga reader server that runs extensions built for Tachiyomi."; |