From de650a5aad4060bc3984f7d6c184cd23fd3d7e75 Mon Sep 17 00:00:00 2001 From: Rory& Date: Tue, 3 Jun 2025 04:27:32 +0200 Subject: Fix nix package, implement module --- flake.nix | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'flake.nix') diff --git a/flake.nix b/flake.nix index bbd4476..5b2f8fc 100644 --- a/flake.nix +++ b/flake.nix @@ -87,7 +87,7 @@ } )) // { nixosModules.default = { config, lib, ...}: { - options.safensound = { + options.services.safensound = { enable = lib.mkEnableOption "Enable SafeNSound service"; package = lib.mkOption { type = lib.types.package; @@ -105,7 +105,7 @@ default = "mongodb-pass"; description = "Path to the database credentials file."; }; - JwtSecretPath = lib.mkOption { + jwtSecretPath = lib.mkOption { type = lib.types.path; default = "."; description = "Path to the JWT secret directory."; @@ -113,6 +113,33 @@ logQueries = lib.mkEnableOption "Log queries"; logAuth = lib.mkEnableOption "Log authentication"; }; + + config = lib.mkIf (config.safensound.enable) ( + let + cfg = config.services.safensound; + in + { + systemd.services.safensound = { + description = "SafeNSound Service"; + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" "mongodb.service" ]; + requires = [ "mongodb.service" ]; + environment = { + PORT = cfg.port; + LOG_REQUESTS = cfg.logRequests; + DATABASE_SECRET_PATH = cfg.dbCredentialsPath; + JWT_SECRET_PATH = cfg.jwtSEcretPath; + LOG_QUERIES = cfg.logQueries; + LOG_AUTH = cfg.logAuth; + }; + serviceConfig = { + Type = "simple"; + ExecStart = "${cfg.package}/bin/start"; + Restart = "on-failure"; + DynamicUser = true; + }; + }; + }); }; }; } \ No newline at end of file -- cgit 1.5.1