-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ce658c
commit b6974d7
Showing
2 changed files
with
91 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ config, lib, pkgs, ... }: | ||
|
||
with lib; | ||
|
||
let | ||
cfg = config.services.tailscale; | ||
|
||
serveOpts = { | ||
options = { | ||
target = mkOption { | ||
type = types.nullOr types.str; | ||
default = null; | ||
description = "Target for serve command (URL, file path, text content)"; | ||
}; | ||
|
||
port = mkOption { | ||
type = types.nullOr types.int; | ||
default = null; | ||
description = "Port to expose service on"; | ||
}; | ||
|
||
protocol = mkOption { | ||
type = types.enum [ "https" "http" "tcp" "tls-terminated-tcp" ]; | ||
default = "https"; | ||
description = "Protocol to expose service with"; | ||
}; | ||
|
||
path = mkOption { | ||
type = types.nullOr types.str; | ||
default = null; | ||
description = "Path to append to base URL"; | ||
}; | ||
}; | ||
}; | ||
in | ||
{ | ||
options = { | ||
services.tailscale = { | ||
enable = mkEnableOption "Tailscale serve service"; | ||
|
||
serve = mkOption { | ||
type = types.attrsOf (types.submodule serveOpts); | ||
default = { }; | ||
description = "Tailscale serve configurations"; | ||
}; | ||
}; | ||
}; | ||
|
||
config = lib.mkIf cfg.enable { | ||
packages = [ pkgs.tailscale ]; | ||
processes = mapAttrs' | ||
(name: serveCfg: | ||
nameValuePair "tailscale-serve-${name}" { | ||
exec = concatStringsSep " " ([ | ||
"${pkgs.tailscale}/bin/tailscale serve" | ||
] | ||
++ optional (serverCfg.path != null) "--set-path=${serveCfg.path}" | ||
++ optional (serverCfg.port != null) "--${serveCfg.protocol}=${toString serveCfg.port}" | ||
++ optional (serverCfg.target != null) serveCfg.target); | ||
} | ||
) | ||
cfg.serve; | ||
}; | ||
} |