From 9a42e80657ff8baa7571fa71a518e048b2353ae9 Mon Sep 17 00:00:00 2001 From: jopejoe1 Date: Wed, 10 Jul 2024 18:14:50 +0200 Subject: [PATCH] infra: init backend api --- nix/infra/backend.nix | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 nix/infra/backend.nix diff --git a/nix/infra/backend.nix b/nix/infra/backend.nix new file mode 100644 index 0000000..f51997a --- /dev/null +++ b/nix/infra/backend.nix @@ -0,0 +1,39 @@ +{ + lib, + config, + self, + ... +}: + +let + user = "alisa"; +in +{ + systemd.services.alisa-backend = { + enable = true; + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + description = "Alisa Backend API Server"; + environment = { + DATABASE_URL = "postgres://${user}@localhost:${config.services.postgresql.settings.port}/${user}"; + TOKEN_SECRET = "secret"; + }; + serviceConfig = { + Restart = "always"; + DynamicUser = true; + User = user; + ExecStart = lib.getExe self.legacyPackages.${config.nixpkgs.hostPlatform.system}.backend; + }; + }; + + services.postgresql = { + enable = true; + ensureDatabases = [ user ]; + ensureUsers = [ + { + name = user; + ensureDBOwnership = true; + } + ]; + }; +}