diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..4ad0df7 --- /dev/null +++ b/flake.lock @@ -0,0 +1,94 @@ +{ + "nodes": { + "naersk": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1698420672, + "narHash": "sha256-/TdeHMPRjjdJub7p7+w55vyABrsJlt5QkznPYy55vKA=", + "owner": "nix-community", + "repo": "naersk", + "rev": "aeb58d5e8faead8980a807c840232697982d47b9", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1711106783, + "narHash": "sha256-PDwAcHahc6hEimyrgGmFdft75gmLrJOZ0txX7lFqq+I=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a3ed7406349a9335cb4c2a71369b697cecd9d351", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1711106783, + "narHash": "sha256-PDwAcHahc6hEimyrgGmFdft75gmLrJOZ0txX7lFqq+I=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a3ed7406349a9335cb4c2a71369b697cecd9d351", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "naersk": "naersk", + "nixpkgs": "nixpkgs_2", + "utils": "utils" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..58500ea --- /dev/null +++ b/flake.nix @@ -0,0 +1,78 @@ +{ + inputs = { + utils.url = "github:numtide/flake-utils"; + naersk.url = "github:nix-community/naersk"; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + }; + + outputs = { self, utils, naersk, nixpkgs }: + utils.lib.eachSystem [ + "x86_64-linux" + "aarch64-linux" + ] (system: + let + pkgs = (import nixpkgs) { + inherit system; + }; + + naersk' = pkgs.callPackage naersk {}; + + in { + packages = { + default = naersk'.buildPackage { + nativeBuildInputs = []; + src = ./.; + }; + }; + } + ) // { + nixosModule = {config, lib, pkgs, ... }: + with lib; + let cfg = config.ashe.services.contact_rs; + + in { + options.ashe.services.contact_rs = { + enable = mkEnableOption "Enables the rust contact service"; + + port = mkOption rec { + type = types.int; + default = 8000; + example = default; + description = "The port for this service to listen on"; + + }; + + domain = mkOption rec { + type = types.str; + default = "contact.tempest.dev"; + example = default; + description = "The domain name for the contact server"; + }; + }; + + config = mkIf cfg.enable { + systemd.services."ashe.contact_rs" = { + wantedBy = [ "multi-user.target" ]; + + serviceConfig = let pkg = self.packages.${pkgs.system}.default; + in { + Restart = "on-failure"; + ExecStart = "${pkg}/bin/contact-rs ${cfg.configFile}"; + DynamicUser = "yes"; + PrivateTmp = "yes"; + Environment = [ + "PORT=${toString cfg.port}" + ]; + }; + }; + + services.nginx.virtualHosts.${cfg.domain} = { + locations."/" = { proxyPass = "http://127.0.0.1:${toString cfg.port}"; }; + forceSSL = true; + enableACME = true; + }; + }; + }; + }; +} +