From e72f3f9d2c8a06cab6a5fd6ae773057effcef8b2 Mon Sep 17 00:00:00 2001 From: patrick-scho Date: Fri, 11 Apr 2025 15:38:33 +0200 Subject: [PATCH] add systemd service to flake --- flake.nix | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 3444d10..29c9ade 100644 --- a/flake.nix +++ b/flake.nix @@ -21,7 +21,7 @@ ''; installPhase = '' - mkdir -p $out/bin + mkdir -p $out/bin $out/db cp zig-out/bin/chirp $out/bin ''; }; @@ -30,6 +30,36 @@ type = "app"; program = "${self.packages.${system}.default}/bin/chirp"; }; - }); + }) + // { + nixosModules.default = { config, lib, pkgs, ... }: { + options.services.chirp = { + enable = lib.mkEnableOption "Enable Chirp"; + + port = lib.mkOption { + type = lib.types.port; + default = 8080; + description = "Port to listen on"; + }; + }; + + config = lib.mkIf config.services.chirp.enable { + systemd.services.chirp = { + description = "Chirp SystemD Service"; + wantedBy = ["multi-user.target"]; + after = ["network.target"]; + serviceConfig = { + ExecStart = "${self.packages.${pkgs.system}.default}/bin/chirp"; + Restart = "always"; + Type = "simple"; + DynamicUser = "yes"; + }; + environment = { + PORT = toString config.services.chirp.port; + }; + }; + }; + }; + }; } -- 2.50.1