Skip to content

Commit

Permalink
add tailscale serve
Browse files Browse the repository at this point in the history
  • Loading branch information
domenkozar committed Nov 24, 2024
1 parent 7ce658c commit b6974d7
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 30 deletions.
57 changes: 27 additions & 30 deletions devenv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -63,32 +63,10 @@
"type": "github"
}
},
"git-hooks": {
"inputs": {
"flake-compat": "flake-compat",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1730302582,
"owner": "cachix",
"repo": "git-hooks.nix",
"rev": "af8a16fe5c264f5e9e18bcee2859b40a656876cf",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "git-hooks.nix",
"type": "github"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"git-hooks",
"pre-commit-hooks",
"nixpkgs"
]
},
Expand Down Expand Up @@ -122,7 +100,7 @@
},
"nix": {
"inputs": {
"flake-compat": "flake-compat_2",
"flake-compat": "flake-compat",
"flake-parts": "flake-parts",
"libgit2": "libgit2",
"nixpkgs": "nixpkgs",
Expand Down Expand Up @@ -191,10 +169,10 @@
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1730327045,
"lastModified": 1731797254,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "080166c15633801df010977d9d7474b4a6c549d7",
"rev": "e8c38b73aeb218e27163376a2d617e61a2ad9b59",
"type": "github"
},
"original": {
Expand Down Expand Up @@ -249,15 +227,34 @@
"type": "github"
}
},
"pre-commit-hooks_2": {
"inputs": {
"flake-compat": "flake-compat_2",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1732021966,
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "3308484d1a443fc5bc92012435d79e80458fe43c",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": {
"inputs": {
"devenv": "devenv",
"git-hooks": "git-hooks",
"nix": "nix",
"nixpkgs": "nixpkgs_2",
"pre-commit-hooks": [
"git-hooks"
]
"pre-commit-hooks": "pre-commit-hooks_2"
}
}
},
Expand Down
64 changes: 64 additions & 0 deletions src/modules/services/tailscale.nix
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;
};
}

0 comments on commit b6974d7

Please sign in to comment.