From 68507c174ab506d1704b95b3168c4023790ee124 Mon Sep 17 00:00:00 2001 From: Astro Date: Thu, 3 Dec 2020 22:45:35 +0100 Subject: [PATCH] nixos-module.nix: init --- nixos-module.nix | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 nixos-module.nix diff --git a/nixos-module.nix b/nixos-module.nix new file mode 100644 index 0000000..14a3256 --- /dev/null +++ b/nixos-module.nix @@ -0,0 +1,59 @@ +{ config, lib, pkgs, ... }: + +let + yammat = import ./. { inherit pkgs; }; + cfg = config.services.yammat; +in +{ + options.services.yammat = with lib; { + enable = mkEnableOption "Yammat"; + user = mkOption { + type = types.str; + default = "yammat"; + description = "System user to run Yammat"; + }; + + group = mkOption { + type = types.str; + default = "yammat"; + description = "System group to run Yammat"; + }; + }; + + config = lib.mkIf cfg.enable { + users.users.${cfg.user} = { + isSystemUser = true; + group = cfg.group; + }; + users.groups.${cfg.group} = {}; + + services.postgresql = { + enable = true; + ensureDatabases = [ "yammat" ]; + ensureUsers = [ { + name = cfg.user; + ensurePermissions = { + "DATABASE yammat" = "ALL PRIVILEGES"; + }; + } ]; + }; + + systemd.services.yammat = { + description = "Yammat Matemat"; + after = [ "postgresql.service" ]; + requires = [ "postgresql.service" ]; + wantedBy = [ "multi-user.target" ]; + environment = { + APPROOT = yammat; + STATIC_DIR = "${yammat}/static"; + PGHOST = ""; + }; + serviceConfig = { + User = cfg.user; + Group = cfg.group; + WorkingDirectory = yammat; + ExecStart = "${yammat}/bin/yammat"; + }; + }; + }; +}