From 286a2eb9a89d9e916b0ede163f2b6e04001de3ff Mon Sep 17 00:00:00 2001 From: "Jill \"oatmealine\" Monoids" Date: Thu, 23 Mar 2023 23:36:54 +0300 Subject: [PATCH] wip nixos service --- flake.nix | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/flake.nix b/flake.nix index 4eff380..9932961 100644 --- a/flake.nix +++ b/flake.nix @@ -47,5 +47,61 @@ shards ]; }; + + nixosModule = { config, lib, pkgs, ... }: + with lib; + let + cfg = config.services.crystal-gauntlet; + in { + options.services.crystal-gauntlet = { + enable = mkEnableOption "Enables the crystal-gauntlet server"; + + domain = mkOption { + type = types.nullOr types.str; + default = null; + description = "Which domain to host the server under; if disabled, NGINX is not used"; + }; + port = mkOption { + type = types.port; + default = 8050; + }; + package = mkOption { + type = types.package; + default = self.packages.${system}.default; + }; + }; + + config = mkIf cfg.enable { + systemd.services."crystal-gauntlet" = { + wantedBy = [ "multi-user.target" ]; + + serviceConfig = { + Restart = "on-failure"; + ExecStart = "${getExe cfg.package}"; + DynamicUser = "yes"; + RuntimeDirectory = "crystal-gauntlet"; + RuntimeDirectoryMode = "0755"; + StateDirectory = "crystal-gauntlet"; + StateDirectoryMode = "0700"; + CacheDirectory = "crystal-gauntlet"; + CacheDirectoryMode = "0750"; + }; + }; + + services.nginx = mkIf cfg.domain { + virtualHosts."${cfg.domain}" = { + enableACME = true; + forceSSL = false; + addSSL = true; + locations."/" = { + proxyPass = "http://127.0.0.1:${cfg.port}/"; + }; + extraConfig = '' + client_max_body_size 500M; + ''; + }; + }; + }; + }; }); } \ No newline at end of file