nix machine / user configurations

feat(wolumonde): nixify the headscale acl

ptr.pet 3da5bf24 0b8107c2

verified
Changed files
+107 -8
hosts
wolumonde
modules
headscale.nix
webhook.nix
+65
hosts/wolumonde/modules/headscale.nix/acl.nix
···
+
{config, lib, ...}: let
+
l = lib // builtins;
+
t = l.types;
+
+
cfg = config.services.headscale.acl;
+
ruleType = t.submodule {
+
options = {
+
action = l.mkOption {
+
type = t.enum [ "accept" ];
+
default = "accept";
+
};
+
proto = l.mkOption {
+
type = t.nullOr (t.enum ["tcp" "udp"]);
+
default = null;
+
};
+
src = l.mkOption {
+
type = t.listOf t.str;
+
};
+
dst = l.mkOption {
+
type = t.listOf t.str;
+
};
+
};
+
};
+
in {
+
options = {
+
services.headscale.acl = {
+
groups = l.mkOption {
+
type = t.attrsOf (t.listOf t.str);
+
default = [];
+
};
+
tagOwners = l.mkOption {
+
type = t.attrsOf (t.listOf t.str);
+
default = [];
+
};
+
hosts = l.mkOption {
+
type = t.attrsOf t.str;
+
default = [];
+
};
+
rules = l.mkOption {
+
type = t.listOf ruleType;
+
default = [];
+
};
+
};
+
};
+
+
config = let
+
generated = l.toFile "policy.hujson" (l.toJSON {
+
groups = l.mapAttrs' (k: v: l.nameValuePair "group:${k}" v) cfg.groups;
+
tagOwners = l.mapAttrs' (k: v: l.nameValuePair "tag:${k}" v) cfg.tagOwners;
+
hosts = cfg.hosts;
+
acls = l.map
+
(rule:
+
if rule.proto == null
+
then l.removeAttrs rule ["proto"]
+
else rule
+
)
+
cfg.rules;
+
});
+
in {
+
services.headscale.settings.policy = {
+
mode = "file";
+
path = generated;
+
};
+
};
+
}
+32 -5
hosts/wolumonde/modules/headscale.nix/default.nix
···
-
{ config, ... }:
+
{ lib, config, ... }:
let
rootDomain = "gaze.systems";
domain = "vpn.${rootDomain}";
in
{
+
imports = [./acl.nix];
+
age.secrets.headscaleOidcSecret = {
file = ../../../../secrets/headscaleOidcSecret.age;
mode = "600";
···
enable = true;
address = "0.0.0.0";
port = 1111;
+
acl = {
+
groups.admin = ["90008@gaze.systems"];
+
tagOwners = {
+
private-infra = ["group:admin"];
+
other-infra = ["group:admin"];
+
};
+
hosts = {
+
wolumonde = "100.64.0.2";
+
higashi = "100.64.0.5";
+
};
+
rules = lib.mkBefore [
+
{
+
src = ["group:admin"];
+
dst = ["tag:private-infra:*" "tag:other-infra:*"];
+
}
+
{
+
src = ["tag:private-infra"];
+
dst = ["tag:other-infra:*"];
+
}
+
{
+
src = ["90008@gaze.systems"];
+
dst = ["90008@gaze.systems:*"];
+
}
+
{
+
src = ["90008@gaze.systems" "tag:private-infra"];
+
dst = ["autogroup:internet:*"];
+
}
+
];
+
};
settings = {
server_url = "https://${domain}";
-
policy = {
-
mode = "file";
-
path = ./acl.hujson;
-
};
dns = {
base_domain = "lan.${rootDomain}";
nameservers.global = [
+10 -3
hosts/wolumonde/modules/webhook.nix/deploy-wolumonde.nix
···
-
{ pkgs, ... }:
-
{
+
{ pkgs, ... }: let
+
port = toString 9000;
+
in {
services.webhook.hooks."deploy-wolumonde" = {
execute-command = "${pkgs.curl}/bin/curl";
pass-arguments-to-command =
···
source = "string";
name = n;
})
-
[ "http://higashi:9000/hooks/deploy-wolumonde" ];
+
[ "http://higashi:${port}/hooks/deploy-wolumonde" ];
};
+
+
services.headscale.acl.rules = [{
+
proto = "tcp";
+
src = ["wolumonde"];
+
dst = ["higashi:${port}"];
+
}];
}