From d9b3eedae6ce9adc7966fa42d021cca2288b98b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Wed, 20 Mar 2024 15:31:10 -0500 Subject: [PATCH] nixos/modules/cctl: initial module definition --- nixos/default.nix | 6 ++++ nixos/modules/cctl.nix | 69 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 nixos/modules/cctl.nix diff --git a/nixos/default.nix b/nixos/default.nix index 1757047e..dee0f65b 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -40,6 +40,12 @@ in imports = [ ./modules/kairos.nix ]; services.kairos.package = self.packages.${pkgs.system}.kairos; }; + cctl = + { pkgs, lib, ... }: + { + imports = [ ./modules/cctl.nix ]; + services.cctl.package = self.packages.${pkgs.system}.cctld; + }; }; }; } diff --git a/nixos/modules/cctl.nix b/nixos/modules/cctl.nix new file mode 100644 index 00000000..f03fcc71 --- /dev/null +++ b/nixos/modules/cctl.nix @@ -0,0 +1,69 @@ +{ lib, pkgs, config, ... }: +let + inherit (lib) + types + mkOption + mkIf + mkMerge + mkEnableOption + mdDoc + ; + cfg = config.services.cctl; +in +{ + options.services.cctl = { + + enable = mkEnableOption (mdDoc "cctl"); + + package = mkOption { + type = types.package; + }; + + port = mkOption { + type = types.port; + default = 11101; + example = 60000; + description = mdDoc '' + Port to listen on. + TODO make port configurable in cctl + ''; + }; + + logLevel = mkOption { + type = types.enum [ + "error" + "warn" + "info" + "debug" + "trace" + ]; + default = "info"; + description = '' + The log-level that should be used. + ''; + }; + }; + + config = mkIf cfg.enable { + + systemd.services.cctl = + { + description = "cctl"; + documentation = [ "" ]; + wantedBy = [ "multi-user.target" ]; + after = [ "network-online.target" ]; + requires = [ "network-online.target" ]; + environment = { + RUST_LOG = cfg.logLevel; + }; + serviceConfig = mkMerge [ + { + ExecStart = ''${lib.getExe cfg.package}''; + Type = "notify"; + Restart = "always"; + DynamicUser = true; + } + ]; + }; + }; +}