about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2024-12-29 19:33:57 +0100
committerMel <einebeere@gmail.com>2024-12-29 20:38:23 +0100
commitf4368190f65902ef4e539774623afa25b2831b87 (patch)
tree7b4335e8b11bf8e3b7308ff2a228aad59a24b5cb
parentd3fe7a09b431c7f1849a69c26adfc08d0016540a (diff)
downloadspecimen-f4368190f65902ef4e539774623afa25b2831b87.tar.zst
specimen-f4368190f65902ef4e539774623afa25b2831b87.zip
Add first iteration of NixOS specimen service module
Signed-off-by: Mel <einebeere@gmail.com>
-rw-r--r--application/module.nix65
-rw-r--r--flake.nix3
2 files changed, 68 insertions, 0 deletions
diff --git a/application/module.nix b/application/module.nix
new file mode 100644
index 0000000..557f421
--- /dev/null
+++ b/application/module.nix
@@ -0,0 +1,65 @@
+{
+  lib,
+  config,
+  pkgs,
+  ...
+}:
+
+let
+  inherit (lib)
+    mkIf
+    mkOption
+    mkEnableOption
+    mkPackageOption
+    types
+    ;
+
+  cfg = config.services.specimen;
+in
+{
+  options.services.specimen = {
+    enable = mkEnableOption "specimen application";
+
+    package = mkPackageOption pkgs "specimen" { };
+
+    port = mkOption {
+      type = types.port;
+      default = 4444;
+      description = "port that specimen will listen on.";
+    };
+
+    listenAddress = mkOption {
+      type = types.str;
+      default = "0.0.0.0";
+      description = "address that specimen will listen on.";
+    };
+
+    openFirewall = mkOption {
+      type = types.bool;
+      default = false;
+      description = "open specimen port in firewall for incoming connections.";
+    };
+
+    namePath = mkOption {
+      type = types.path;
+      description = "path from which specimen will get the content to reply with.";
+    };
+  };
+
+  config = mkIf cfg.enable {
+    networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall cfg.port;
+
+    systemd.services.specimen = {
+      description = "specimen application service";
+      wantedBy = "multi-user.target";
+      after = "network.target";
+
+      serviceConfig = {
+        DynamicUser = true;
+        Type = "exec";
+        Restart = "always";
+        ExecStart = "${cfg.package}/bin/specimen -address ${cfg.listenAddress} -port ${cfg.port} -name ${cfg.namePath}";
+      };
+    };
+  };
+}
diff --git a/flake.nix b/flake.nix
index 528d1de..c382f36 100644
--- a/flake.nix
+++ b/flake.nix
@@ -31,11 +31,14 @@
       };
     });
 
+    nixosModules.default = import ./application/module.nix;
+
     nixosConfigurations.${name} = lib.nixosSystem {
       system = "aarch64-linux";
       specialArgs = inputs;
       modules = [
         ./configuration/configuration.nix
+        self.nixosModules.default
       ];
     };
   };