diff options
author | Cara Salter <cara@devcara.com> | 2022-07-09 22:44:35 -0400 |
---|---|---|
committer | Cara Salter <cara@devcara.com> | 2022-07-09 22:44:35 -0400 |
commit | 90823a79ef80f6a589a414fb8a3006c8ff17a95d (patch) | |
tree | d7124a7ab9e43f9e79a32375da3cea2a9c36a7e8 /flake.nix | |
parent | c9ff6a9d85fb50e0760acad921709582c2e402cb (diff) | |
download | homeworld-90823a79ef80f6a589a414fb8a3006c8ff17a95d.tar.gz homeworld-90823a79ef80f6a589a414fb8a3006c8ff17a95d.zip |
fmt
Diffstat (limited to 'flake.nix')
-rw-r--r-- | flake.nix | 113 |
1 files changed, 0 insertions, 113 deletions
diff --git a/flake.nix b/flake.nix deleted file mode 100644 index 693a8a2..0000000 --- a/flake.nix +++ /dev/null @@ -1,113 +0,0 @@ -{ - inputs = { - flake-utils.url = "github:numtide/flake-utils"; - naersk.url = "github:nix-community/naersk"; - }; - - outputs = { self, nixpkgs, flake-utils, naersk }: - flake-utils.lib.eachDefaultSystem ( - system: let - pkgs = nixpkgs.legacyPackages."${system}"; - naersk-lib = naersk.lib."${system}"; - - deps = with pkgs; [ - libvirt - pkg-config - openssl - gcc - glibc - ]; - in - rec { - # `nix build` - packages.homeworld = naersk-lib.buildPackage { - pname = "homeworld"; - root = ./.; - nativeBuildInputs = deps; - buildInputs = deps; - }; - defaultPackage = packages.homeworld; - - # `nix run` - apps.homeworld = flake-utils.lib.mkApp { - drv = packages.homeworld; - }; - 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"; - }; - services.homeworld.port = lib.mkOption { - type = lib.types.port; - default = 4000; - description = "The port that will be exposed"; - }; - }; - - 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; - - networking.firewall.allowedTCPPorts = [ - config.services.homeworld.port - ]; - }; - }; - - # `nix develop` - devShell = pkgs.mkShell { - nativeBuildInputs = with pkgs; [ rustc cargo ] ++ deps; - }; - } - ); -} |