2024-11-15 10:17:56 +01:00
|
|
|
{ config, lib, ... }:
|
|
|
|
let
|
2024-03-01 11:21:37 +01:00
|
|
|
cfg = config.steveej.holo-zerotier;
|
2024-11-15 10:17:56 +01:00
|
|
|
in
|
|
|
|
{
|
2024-03-01 11:21:37 +01:00
|
|
|
options.steveej.holo-zerotier = {
|
|
|
|
enable = lib.mkEnableOption "Enable holo-zerotier";
|
2024-11-15 10:17:56 +01:00
|
|
|
autostart = lib.mkOption { default = false; };
|
2024-03-01 11:21:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
2024-11-15 10:17:56 +01:00
|
|
|
nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ "zerotierone" ];
|
2024-04-18 17:28:17 +02:00
|
|
|
|
2024-03-01 11:21:37 +01:00
|
|
|
services.zerotierone = {
|
2024-11-15 10:17:56 +01:00
|
|
|
inherit (cfg) enable;
|
2024-03-01 11:21:37 +01:00
|
|
|
joinNetworks = [
|
|
|
|
# moved to the service below as it's now secret
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2024-11-15 10:17:56 +01:00
|
|
|
systemd.services.zerotierone.wantedBy = lib.mkIf (!cfg.autostart) (lib.mkForce [ ]);
|
2024-03-01 11:21:37 +01:00
|
|
|
|
|
|
|
systemd.services.zerotieroneSecretNetworks = {
|
2024-11-15 10:17:56 +01:00
|
|
|
inherit (cfg) enable;
|
|
|
|
requiredBy = [ "zerotierone.service" ];
|
|
|
|
partOf = [ "zerotierone.service" ];
|
2024-03-01 11:21:37 +01:00
|
|
|
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
serviceConfig.RemainAfterExit = true;
|
|
|
|
|
2024-11-15 10:17:56 +01:00
|
|
|
script =
|
|
|
|
let
|
|
|
|
secret = config.sops.secrets.zerotieroneNetworks;
|
|
|
|
in
|
|
|
|
''
|
|
|
|
# include the secret's hash to trigger a restart on change
|
|
|
|
# ${builtins.hashString "sha256" (builtins.toJSON secret)}
|
|
|
|
|
|
|
|
${config.systemd.services.zerotierone.preStart}
|
|
|
|
|
|
|
|
rm -rf /var/lib/zerotier-one/networks.d/*.conf
|
|
|
|
for network in `grep -v '#' ${secret.path}`; do
|
|
|
|
touch /var/lib/zerotier-one/networks.d/''${network}.conf
|
|
|
|
done
|
|
|
|
'';
|
2024-03-01 11:21:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
sops.secrets.zerotieroneNetworks = {
|
|
|
|
sopsFile = ../../../secrets/work-holo/zerotierone.txt;
|
|
|
|
format = "binary";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|