From 8d7a89c3aab3e12ba71595195f2964d36fb8ffc8 Mon Sep 17 00:00:00 2001 From: Patrick Date: Fri, 8 May 2026 01:26:02 +0200 Subject: update build and flake --- flake.nix | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'flake.nix') diff --git a/flake.nix b/flake.nix index 8662667..265a9ea 100644 --- a/flake.nix +++ b/flake.nix @@ -6,6 +6,7 @@ }; outputs = { + self, nixpkgs, zig, ... @@ -23,12 +24,45 @@ packages = forAllSystems (pkgs: zig: { default = zig.makePackage { - pname = "zig-flake-template"; + pname = "zhttpws"; version = "0.0.0"; src = ./.; zigReleaseMode = "fast"; depsHash = "sha256-pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo="; }; }); + + nixosModules.default = { config, lib, pkgs }: + let cfg = config.services.zhttpws; + in { + options.services.zhttpws = { + enable = lib.mkEnableOption "zhttpws"; + domain = lib.mkOption { + type = lib.types.str; + }; + port = lib.mkOption { + type = lib.types.port; + }; + }; + + config = lib.mkIf cfg.enable { + systemd.services.zhttpws = { + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; + serviceConfig = { + ExecStart = "${self.packages.${pkgs.system}.default}/bin/zhttpws"; + DynamicUser = true; + Restart = "always"; + }; + environment = { + PORT = toString cfg.port; + }; + }; + + services.caddy.virtualHosts."${cfg.domain}".extraConfig = '' + reverse_proxy localhost:${toString cfg.port} + ''; + }; + }; }; } -- cgit v1.2.3