-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
flake.nix: Split nixos module to a separate file (#18)
- Split out nix/nixos-module.nix. This way it can theoretically be imported without using flakes, since some people prefer to do things that way. - Use a nixpkgs overlay to add tailscale-manager to pkgs, so it shows up when vm-text.nix imports the module - Move nixosModules to the system-independent outputs section where it belongs - Remove last references to `packageName` since we were not using it consistently Resources: https://vtimofeenko.com/posts/practical-nix-flake-anatomy-a-guided-tour-of-flake.nix/
- Loading branch information
Showing
3 changed files
with
100 additions
and
94 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,86 @@ | ||
{ config, lib, pkgs, ... }: | ||
|
||
with lib; | ||
let | ||
cfg = config.services.tailscale-manager; | ||
configFile = pkgs.writeTextFile { | ||
name = "tailscale-manager.json"; | ||
text = generators.toJSON {} { | ||
routes = cfg.routes; | ||
hostRoutes = cfg.hostRoutes; | ||
extraArgs = cfg.extraArgs; | ||
awsManagedPrefixLists = cfg.awsManagedPrefixLists; | ||
}; | ||
}; | ||
in { | ||
options.services.tailscale-manager = { | ||
enable = mkEnableOption "tailscale-manager"; | ||
package = mkPackageOption pkgs "tailscale-manager" {}; | ||
interval = mkOption { | ||
type = types.int; | ||
default = 300; | ||
description = "Interval between runs, in seconds"; | ||
}; | ||
routes = mkOption { | ||
type = types.listOf types.str; | ||
default = []; | ||
description = "List of CIDR prefix routes to advertise"; | ||
}; | ||
hostRoutes = mkOption { | ||
type = types.listOf types.str; | ||
default = []; | ||
description = "List of hostnames and IP addresses to add as /32 routes"; | ||
}; | ||
awsManagedPrefixLists = mkOption { | ||
type = types.listOf types.str; | ||
default = []; | ||
description = "AWS prefix list IDs for route discovery"; | ||
}; | ||
extraArgs = mkOption { | ||
type = types.listOf types.str; | ||
default = []; | ||
description = "Extra arguments for `tailscale set`"; | ||
}; | ||
dryRun = mkOption { | ||
type = types.bool; | ||
default = false; | ||
description = "Enable dry-run mode, don't actually apply changes."; | ||
}; | ||
maxShrinkRatio = mkOption { | ||
type = types.float; | ||
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 = { | ||
after = ["tailscaled.service"]; | ||
wants = ["tailscaled.service"]; | ||
wantedBy = ["multi-user.target"]; | ||
# Never give up on trying to restart | ||
startLimitIntervalSec = 0; | ||
serviceConfig = { | ||
Type = "exec"; | ||
Restart = "always"; | ||
# Restart at increasing intervals to avoid things like EC2 | ||
# metadata service rate limits | ||
RestartSec = 1; | ||
RestartSteps = 30; | ||
RestartMaxDelaySec = 60; | ||
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" | ||
); | ||
}; | ||
}; | ||
}; | ||
} |
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