treesummaryrefslogcommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.zig2
-rw-r--r--flake.lock16
-rw-r--r--flake.nix36
3 files changed, 43 insertions, 11 deletions
diff --git a/build.zig b/build.zig
index bd06ef3..37ebe2e 100644
--- a/build.zig
+++ b/build.zig
@@ -38,7 +38,7 @@ pub fn build(b: *std.Build) void {
// If neither case applies to you, feel free to delete the declaration you
// don't need and to put everything under a single module.
const exe = b.addExecutable(.{
- .name = "default",
+ .name = "zhttpws",
.root_module = b.createModule(.{
// b.createModule defines a new module just like b.addModule but,
// unlike b.addModule, it does not expose the module to consumers of
diff --git a/flake.lock b/flake.lock
index 88e744e..d2d41db 100644
--- a/flake.lock
+++ b/flake.lock
@@ -2,12 +2,10 @@
"nodes": {
"nixpkgs": {
"locked": {
- "lastModified": 1776949667,
- "narHash": "sha256-GMSVw35Q+294GlrTUKlx087E31z7KurReQ1YHSKp5iw=",
- "owner": "NixOS",
- "repo": "nixpkgs",
- "rev": "01fbdeef22b76df85ea168fbfe1bfd9e63681b30",
- "type": "github"
+ "lastModified": 0,
+ "narHash": "sha256-4TLFHUwXraw9Df5mXC/vCrJgb50CRr3CzUzF0Mn3CII=",
+ "path": "/nix/store/jfwg36s3hfhlvxrxfw7d60nhycx5gp4h-source",
+ "type": "path"
},
"original": {
"id": "nixpkgs",
@@ -27,11 +25,11 @@
]
},
"locked": {
- "lastModified": 1777022972,
- "narHash": "sha256-JONIVp25MIU90jh5LOl1LJsFoVhWTyRmvvxaJMqG5/g=",
+ "lastModified": 1777092395,
+ "narHash": "sha256-cJitc7H7Zr6YLPuVLvop+T2nd+b66f25kUaDivpuD2k=",
"owner": "silversquirl",
"repo": "zig-flake",
- "rev": "a94c5ff62b4d642e6c12a38a5835ad13cbfd21d8",
+ "rev": "22e43efd36acb474a255496ada6c927e2fd2ac20",
"type": "github"
},
"original": {
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}
+ '';
+ };
+ };
};
}