From f794ce0d9e987466902319e2df656f07e84ca30c Mon Sep 17 00:00:00 2001 From: shimun Date: Wed, 7 Dec 2022 11:43:18 +0100 Subject: [PATCH] refactor: move options into own module --- modules/home-manager.nix | 30 +++------------------------- modules/options.nix | 42 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 27 deletions(-) create mode 100644 modules/options.nix diff --git a/modules/home-manager.nix b/modules/home-manager.nix index 06247bb..4776080 100644 --- a/modules/home-manager.nix +++ b/modules/home-manager.nix @@ -1,34 +1,10 @@ { config, pkgs, lib, ... }: with lib; let cfg = config.services.ssh-cert-dist; - directoryModule = { name, ... }: { - options = { - name = mkOption { - type = types.str; - default = last (splitString "/" name); - }; - fetch = mkOption { - type = types.bool; - default = true; - }; - upload = mkOption { - type = types.bool; - default = false; - }; - }; - }; in { - options.services.ssh-cert-dist = { - enable = mkEnableOption "ssh-cert-dist"; - endpoint = mkOption { - type = types.str; - description = "API endpoint url"; - }; - directories = mkOption { - type = with types; attrsOf (submodule directoryModule); - default = { }; - }; - }; + config.imports = [ + ./options.nix + ]; config.systemd.user.services = mkIf cfg.enable (mapAttrs' (path: options: { inherit (options) name; value = { diff --git a/modules/options.nix b/modules/options.nix new file mode 100644 index 0000000..fcd5dda --- /dev/null +++ b/modules/options.nix @@ -0,0 +1,42 @@ +{ config, lib, pkgs, ... }: with lib; let + directoryModule = { name, ... }: { + options = { + name = mkOption { + type = types.str; + default = last (splitString "/" name); + }; + fetch = mkOption { + type = types.bool; + default = true; + }; + upload = mkOption { + type = types.bool; + default = false; + }; + }; + }; + endpointOption = mkOption { + type = types.str; + description = "API endpoint url"; + default = "https://pki.shimun.net"; + }; + + +in +{ + options = { + services.ssh-cert-dist = { + enable = mkEnableOption "ssh-cert-dist"; + endpoint = endpointOption; + directories = mkOption { + type = with types; attrsOf (submodule directoryModule); + default = { }; + }; + }; + programs.ssh-cert-dist = { + enable = mkEnableOption "ssh-cert-dist client"; + endpoint = endpointOption; + }; + }; + +}