nixfiles/nixos/boxes/britway/tailscale.nix

109 lines
3.3 KiB
Nix
Raw Normal View History

2023-12-19 23:40:54 +00:00
{ lib, pkgs, config, assignments, allAssignments, ... }:
let
inherit (lib.my.c) pubDomain;
inherit (lib.my.c.britway) prefixes domain;
# Can't use overrideAttrs because we need to override `vendorHash` within `buildGoModule`
2024-07-14 22:04:03 +01:00
headscale = (pkgs.headscale.override {
2023-12-19 23:40:54 +00:00
buildGoModule = args: pkgs.buildGoModule (args // rec {
2024-07-14 22:04:03 +01:00
version = "0.23.0-alpha12";
2023-12-19 23:40:54 +00:00
src = pkgs.fetchFromGitHub {
owner = "juanfont";
repo = "headscale";
rev = "v${version}";
2024-07-14 22:04:03 +01:00
hash = "sha256-kZZK0cXnFARxblSMz01TDcBbTorkHGAwGpR+a4/mYfU=";
2023-12-19 23:40:54 +00:00
};
2024-07-14 22:04:03 +01:00
patches = [];
vendorHash = "sha256-EorT2AVwA3usly/LcNor6r5UIhLCdj3L4O4ilgTIC2o=";
doCheck = false;
2023-12-19 23:40:54 +00:00
});
2024-07-14 22:04:03 +01:00
});
2023-12-20 00:21:39 +00:00
2023-12-20 16:43:20 +00:00
pubNameservers = [
"1.1.1.1"
"1.0.0.1"
"2606:4700:4700::1111"
"2606:4700:4700::1001"
];
2023-12-19 23:40:54 +00:00
in
{
config = {
environment.systemPackages = [
# For CLI
config.services.headscale.package
];
services = {
headscale = {
enable = true;
package = headscale;
settings = {
disable_check_updates = true;
unix_socket_permission = "0770";
server_url = "https://ts.${pubDomain}";
2024-07-15 22:36:55 +01:00
database = {
type = "sqlite3";
sqlite.path = "/var/lib/headscale/db.sqlite3";
};
2023-12-19 23:40:54 +00:00
noise.private_key_path = "/var/lib/headscale/noise_private.key";
2024-07-15 22:36:55 +01:00
prefixes = with lib.my.c.tailscale.prefix; { inherit v4 v6; };
2023-12-19 23:40:54 +00:00
dns_config = {
# Use IPs that will route inside the VPN to prevent interception
# (e.g. DNS rebinding filtering)
2023-12-20 16:43:20 +00:00
restricted_nameservers = {
"${domain}" = pubNameservers;
"${lib.my.c.colony.domain}" = with allAssignments.estuary.base; [
2023-12-20 16:43:20 +00:00
ipv4.address ipv6.address
];
"${lib.my.c.home.domain}" = with allAssignments; [
river.hi.ipv4.address
river.hi.ipv6.address
stream.hi.ipv4.address
stream.hi.ipv6.address
];
2023-12-20 16:43:20 +00:00
};
2023-12-19 23:40:54 +00:00
magic_dns = true;
base_domain = "ts.${pubDomain}";
2023-12-20 16:43:20 +00:00
override_local_dns = false;
2023-12-19 23:40:54 +00:00
};
oidc = {
only_start_if_oidc_is_available = true;
issuer = "https://accounts.google.com";
client_id = "545475967061-l45cln081mp8t4li2c34v7t7b8la6f4f.apps.googleusercontent.com";
client_secret_path = config.age.secrets."britway/oidc-secret.txt".path;
scope = [ "openid" "profile" "email" ];
allowed_users = [ "jackos1998@gmail.com" ];
};
};
};
2023-12-20 00:21:39 +00:00
tailscale = {
enable = true;
authKeyFile = config.age.secrets."tailscale-auth.key".path;
openFirewall = true;
interfaceName = "tailscale0";
extraUpFlags = [
2023-12-20 16:43:20 +00:00
"--operator=${config.my.user.config.name}"
2023-12-20 00:21:39 +00:00
"--login-server=https://ts.nul.ie"
2023-12-20 16:43:20 +00:00
"--netfilter-mode=off"
2023-12-20 00:21:39 +00:00
"--advertise-exit-node"
2023-12-20 19:06:19 +00:00
"--accept-routes=false"
2023-12-20 00:21:39 +00:00
];
};
2023-12-19 23:40:54 +00:00
};
my = {
secrets = {
files = {
"britway/oidc-secret.txt" = {
owner = "headscale";
group = "headscale";
mode = "440";
};
2023-12-20 00:21:39 +00:00
"tailscale-auth.key" = {};
2023-12-19 23:40:54 +00:00
};
};
};
};
}