Skip to content

Commit

Permalink
feat: Better tailscale module
Browse files Browse the repository at this point in the history
Make it into a proper module with options, add shortcut for setting the
trusted ACL tag
  • Loading branch information
lpchaim committed Oct 11, 2024
1 parent fe7d5fc commit ba9178e
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 19 deletions.
19 changes: 0 additions & 19 deletions modules/nixos/base/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -185,25 +185,6 @@ in {
};
power-profiles-daemon.enable = true;
printing.enable = true;
tailscale = {
enable = true;
authKeyFile = config.sops.secrets."tailscale/oauth/secret".path;
authKeyParameters = {
ephemeral = false;
preauthorized = true;
};
extraUpFlags = [
"--accept-dns"
"--accept-routes"
"--advertise-exit-node"
"--advertise-tags=tag:nixos"
"--operator=${shared.defaults.name.user}"
"--reset" # Forces unspecified arguments to default values
"--ssh"
];
openFirewall = true;
useRoutingFeatures = "both";
};
udisks2.enable = true;
};
services.xserver.enable = lib.mkDefault true;
Expand Down
66 changes: 66 additions & 0 deletions modules/nixos/tailscale/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
config,
lib,
options,
...
}: let
inherit (lib.lpchaim) shared;
in
lib.lpchaim.mkModule {
inherit config;
namespace = "my.networking.tailscale";
options = {
enable = lib.mkEnableOption "tailscale" // {default = true;};
authKeyParameters =
options.services.tailscale.authKeyParameters
// {
default.ephemeral = false;
default.preauthorized = true;
};
trusted = lib.mkOption {
description = "Whether to tag this device as trusted";
type = lib.types.bool;
default = false;
};
advertise.exitNode = lib.mkOption {
description = "Whether to advertise an exit node";
default = false;
type = lib.types.bool;
};
advertise.tags = lib.mkOption {
description = "ACL tags to advertise";
default = ["nixos"];
type = with lib.types; listOf str;
};
};
configBuilder = cfg:
lib.mkIf cfg.enable {
services.tailscale = let
tags =
cfg.advertise.tags
++ lib.optionals cfg.trusted ["trusted"];
formattedTags = lib.pipe tags [
(map (it: "tag:${it}"))
(builtins.concatStringsSep ",")
];
in {
inherit (cfg) authKeyParameters;
enable = true;
authKeyFile = config.sops.secrets."tailscale/oauth/secret".path;
extraUpFlags =
[
"--accept-dns"
"--accept-routes"
"--advertise-tags=${formattedTags}"
"--operator=${shared.defaults.name.user}"
"--reset" # Forces unspecified arguments to default values
"--ssh"
]
++ lib.optionals cfg.advertise.exitNode [
"--advertise-exit-node"
];
openFirewall = true;
useRoutingFeatures = "both";
};
};
}
1 change: 1 addition & 0 deletions systems/x86_64-linux/desktop/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ in {

system.stateVersion = "23.11";
my.gaming.enable = true;
my.networking.tailscale.trusted = true;
my.security.secureboot.enable = true;

fileSystems."/run/media/lpchaim/storage" = {
Expand Down
1 change: 1 addition & 0 deletions systems/x86_64-linux/laptop/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ in {
networking.hostName = "laptop";
system.stateVersion = "23.11";
my.gaming.steam.enable = true;
my.networking.tailscale.trusted = true;
my.security.secureboot.enable = true;
}

0 comments on commit ba9178e

Please sign in to comment.