summaryrefslogtreecommitdiff
path: root/flake.nix
diff options
context:
space:
mode:
authorCara Salter <cara@devcara.com>2022-05-30 00:11:41 -0400
committerCara Salter <cara@devcara.com>2022-05-30 00:11:41 -0400
commitb7752eef57e008c0d2a7dad868e98ff8b802bd22 (patch)
tree30b99fa44832e972a93b6ab5bcbc1c889bdda380 /flake.nix
parent3eba02283648ab8ceb97e5088c3baf372faa33bc (diff)
downloadhomeworld-b7752eef57e008c0d2a7dad868e98ff8b802bd22.tar.gz
homeworld-b7752eef57e008c0d2a7dad868e98ff8b802bd22.zip
dist: Initial nixos module
Diffstat (limited to 'flake.nix')
-rw-r--r--flake.nix61
1 files changed, 61 insertions, 0 deletions
diff --git a/flake.nix b/flake.nix
index 31ef857..fa2148d 100644
--- a/flake.nix
+++ b/flake.nix
@@ -34,6 +34,67 @@
};
defaultApp = apps.homeworld;
+ nixosModules.homeworld = { config, lib, ... }: {
+ options = {
+ services.homeworld.enable = lib.mkEnableOption "enable homeworld server";
+ services.homeworld.environment-file-location = lib.mkOption {
+ type = lib.types.path;
+ default = "/var/lib/homeworld/.env";
+ description = "The location of the environment file";
+ };
+ };
+
+ config = lib.mkIf config.services.homeworld.enable {
+ users.groups.homeworld = {
+ members = [ "homeworld" "${config.services.postgresql.superUser}" ];
+ };
+ users.users.homeworld = {
+ createHome = true;
+ isSystemUser = true;
+ home = "/var/lib/homeworld";
+ group = "homeworld";
+ };
+
+ systemd.services.homeworld = {
+ wantedBy = [ "multi-user.target" ];
+ after = [ "homeworld-init.service" "postgresql.service" ];
+ requires = [ "homeworld-init.service" "postgresql.service" ];
+ serviceConfig = {
+ User = "homeworld";
+ Group = "homeworld";
+ Restart = "always";
+ WorkingDirectory = "/var/lib/homeworld";
+ ExecStart = "${defaultPackage}/bin/homeworld";
+ EnvironmentFile =
+ "${config.services.homeworld.environment-file-location}";
+ };
+ };
+
+ systemd.services.homeworld-init = {
+ wantedBy = [ "multi-user.target" ];
+ requires = [ "postgresql.service" ];
+ after = [ "postgresql.service" ];
+ description = "Init for Homeworld";
+
+ script = with pkgs; ''
+ if ! [ -e /var/lib/postgresql/.homeworld-inited ]; then
+ ${config.services.postgresql.package}/bin/createuser homeworld
+ ${config.services.postgresql.package}/bin/createdb -O homeworld homeworld
+ touch /var/lib/postgresql/.homeworld-inited
+ fi
+ '';
+
+ serviceConfig = {
+ Type = "oneshot";
+ User = "${config.services.postgresql.superUser}";
+ Group = "homeworld";
+ };
+ };
+
+ services.postgresql.enable = true;
+ };
+ };
+
# `nix develop`
devShell = pkgs.mkShell {
nativeBuildInputs = with pkgs; [ rustc cargo ] ++ deps;