Skip to content

Commit

Permalink
Merge pull request #10 from SamyDjemai/feat/socket-path
Browse files Browse the repository at this point in the history
feat: add socket path option
  • Loading branch information
benley authored Dec 3, 2024
2 parents c60c459 + 1aeffaa commit 04e80cf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ and update tailscale route advertisements accordingly.
## Commandline options

```
Usage: tailscale-manager <configfile.json> [--dryrun] [--tailscale PATH]
[--interval INT] [--max-shrink-ratio RATIO]
Usage: tailscale-manager <configfile.json> [--dryrun] [--tailscale PATH]
[--socket SOCKET_PATH] [--interval INT]
[--max-shrink-ratio RATIO]
Tailscale routes manager
Expand Down Expand Up @@ -96,6 +97,8 @@ Available options:
--dryrun Dryrun mode
--tailscale PATH Path to the tailscale executable
(default: "tailscale")
--socket SOCKET_PATH Path to the tailscaled socket
(default: "/var/run/tailscale/tailscaled.sock")
--interval INT Interval (in seconds) between runs. 0 means exit
after running once. (default: 0)
--max-shrink-ratio RATIO Max allowed route shrinkage between consecutive runs,
Expand Down
6 changes: 6 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@
default = 0.5;
description = "How much route shrinkage is allowed between subsequent runs (between 0 and 1)";
};
socketPath = mkOption {
type = types.path;
default = "/var/run/tailscale/tailscaled.sock";
description = "Path to the tailscaled socket";
};
};
config = mkIf cfg.enable {
systemd.services.tailscale-manager = {
Expand All @@ -112,6 +117,7 @@
ExecStart = lib.escapeShellArgs (
[ "${cfg.package}/bin/tailscale-manager" configFile
"--tailscale=${config.services.tailscale.package}/bin/tailscale"
"--socket=${cfg.socketPath}"
"--interval=${toString cfg.interval}"
"--max-shrink-ratio=${toString cfg.maxShrinkRatio}"
] ++ lib.optional cfg.dryRun "--dryrun"
Expand Down
8 changes: 7 additions & 1 deletion src/TailscaleManager.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ data TailscaleManagerOptions
{ configFile :: FilePath
, dryRun :: Bool
, tailscaleCmd :: FilePath
, socketPath :: FilePath
, interval :: Seconds
, maxShrinkRatio :: Double
}
Expand Down Expand Up @@ -68,6 +69,11 @@ tsManagerOptions =
<> help "Path to the tailscale executable"
<> value "tailscale"
<> showDefault)
<*> strOption (long "socket"
<> metavar "SOCKET_PATH"
<> help "Path to the tailscaled socket"
<> value "/var/run/tailscale/tailscaled.sock"
<> showDefault)
<*> option auto (long "interval"
<> metavar "INT"
<> help "Interval (in seconds) between runs. 0 means exit after running once."
Expand Down Expand Up @@ -128,7 +134,7 @@ runOnce options prevRoutes = do
let shrinkage = shrinkRatio prevRoutes newRoutes
if shrinkage < maxShrinkRatio options
then do
invokeTailscale $ ["set", "--advertise-routes=" ++ intercalate "," (map show $ S.toList newRoutes)] ++ tsExtraArgs config
invokeTailscale $ ["--socket=" ++ socketPath options, "set", "--advertise-routes=" ++ intercalate "," (map show $ S.toList newRoutes)] ++ tsExtraArgs config
logDelay
return newRoutes
else do
Expand Down

0 comments on commit 04e80cf

Please sign in to comment.