From 26eee6ca61dc7560d674db38e2fde4af8c8716a7 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 7 Nov 2024 19:39:55 -0600 Subject: [PATCH] refactor: improved readability --- config/default.nix | 188 ++++++++++++++++++++++----------------------- 1 file changed, 92 insertions(+), 96 deletions(-) diff --git a/config/default.nix b/config/default.nix index dc0e048..febcc4a 100755 --- a/config/default.nix +++ b/config/default.nix @@ -21,24 +21,6 @@ (builtins.genList (i: i) numOptions) ); in let - peopleSubmodule = lib.types.submodule { - options = - builtins.listToAttrs ( - map (name: { - inherit name; - value = stringType; - }) - [ - "user0" - "user1" - ] - ) - // { - users = lib.mkOption { - type = lib.types.attrsOf userSubmodule; - }; - }; - }; userSubmodule = lib.types.submodule { options = { name = stringType; @@ -49,41 +31,6 @@ in let paths = genOptions stringType "path"; }; }; - serviceSubmodule = lib.types.submodule { - options = - builtins.listToAttrs (map (name: { - inherit name; - value = stringType; - }) - [ - "acme" - "caddy" - "castopod" - "forgejo" - "jellyfin" - "mastodon" - "matrix" - "minecraft" - "nextcloud" - "nginx" - "ollama" - "owncast" - "peertube" - "postgresql" - "samba" - "syncthing" - "synology" - "vaultwarden" - "web" - "wiki" - "writefreely" - ]) - // { - instances = lib.mkOption { - type = lib.types.attrsOf instanceSubmodule; - }; - }; - }; instanceSubmodule = lib.types.submodule { options = { subdomain = stringType; @@ -102,58 +49,107 @@ in let }; }; }; - machineSubmodule = lib.types.submodule { - options = - builtins.listToAttrs (map (name: { - inherit name; - value = stringType; - }) - [ - "desktop" - "laptop" - "nas" - "phone" - "printer0" - "printer1" - "server" - "tablet" - ]) - // { - devices = lib.mkOption { - type = lib.types.attrsOf deviceSubmodule; - }; + deviceSubmodule = lib.types.submodule { + options = let + mountConfig = { + mount = stringType; + device = stringType; + options = listType; }; + in + { + boot = mountConfig; + ip = genOptions stringType "address"; + label = stringType; + name = stringType; + sync = stringType; + } + // genOptions mountConfig "folder" + // genOptions mountConfig "samba" + // genOptions mountConfig "storage"; }; - deviceSubmodule = let - mountConfig = { - mount = stringType; - device = stringType; - options = listType; - }; - in - lib.types.submodule { - options = - { - boot = mountConfig; - ip = genOptions stringType "address"; - label = stringType; - name = stringType; - sync = stringType; - } - // genOptions mountConfig "folder" - // genOptions mountConfig "samba" - // genOptions mountConfig "storage"; - }; in { options = { services = lib.mkOption { - type = serviceSubmodule; + type = lib.types.submodule { + options = + builtins.listToAttrs (map (name: { + inherit name; + value = stringType; + }) + [ + "acme" + "caddy" + "castopod" + "forgejo" + "jellyfin" + "mastodon" + "matrix" + "minecraft" + "nextcloud" + "nginx" + "ollama" + "owncast" + "peertube" + "postgresql" + "samba" + "syncthing" + "synology" + "vaultwarden" + "web" + "wiki" + "writefreely" + ]) + // { + instances = lib.mkOption { + type = lib.types.attrsOf instanceSubmodule; + }; + }; + }; }; machines = lib.mkOption { - type = machineSubmodule; + type = lib.types.submodule { + options = + builtins.listToAttrs (map (name: { + inherit name; + value = stringType; + }) + [ + "desktop" + "laptop" + "nas" + "phone" + "printer0" + "printer1" + "server" + "tablet" + ]) + // { + devices = lib.mkOption { + type = lib.types.attrsOf deviceSubmodule; + }; + }; + }; }; people = lib.mkOption { - type = peopleSubmodule; + type = lib.types.submodule { + options = + builtins.listToAttrs ( + map (name: { + inherit name; + value = stringType; + }) + [ + "user0" + "user1" + ] + ) + // { + users = lib.mkOption { + type = lib.types.attrsOf userSubmodule; + }; + }; + }; }; };