nixos/modules/common/applications/netbird.nix

81 lines
2.4 KiB
Nix

{ config, pkgs, lib, ... }: {
options = {
netbird = {
enable = lib.mkEnableOption {
description = "Enable Netbird";
default = false;
};
opts = {
setup_key = lib.mkOption {
type = lib.types.str;
description = ''
Setup key obtained from the Management Service Dashboard (used to register peer)
'';
default = "";
};
setup_key_file = lib.mkOption {
type = lib.types.str;
description = ''
Path to a file containing a setup key obtained from the Management Service Dashboard (used to register peer)
'';
default = "";
};
management_url = lib.mkOption {
type = lib.types.str;
description = ''
Management Service URL [http|https]://[host]:[port]
'';
default = "https://api.wiretrustee.com:443";
};
admin_url = lib.mkOption {
type = lib.types.str;
description = ''
Admin Panel URL [http|https]://[host]:[port]
'';
default = "https://app.netbird.io";
};
};
};
};
# TODO: This code should live somewhere else and be available to everything.
# mkIfElse = p: yes: no: lib.mkMerge [
# (lib.mkIf p yes)
# (lib.mkif (!p) no)
# ];
config = lib.mkIf (config.netbird.enable) (lib.mkMerge [
{
services.netbird = {
enable = true;
tunnels = {
wt0.environment = (lib.mkMerge [
{
NB_MANAGEMENT_URL = config.netbird.opts.management_url;
NB_ADMIN_URL = config.netbird.opts.admin_url;
}
(lib.mkIf (config.netbird.opts.setup_key != "") {
NB_SETUP_KEY = config.netbird.opts.setup_key;
})
(lib.mkIf (config.netbird.opts.setup_key_file != "") {
NB_SETUP_KEY_FILE = config.netbird.opts.setup_key_file;
})
]);
};
};
environment = {
variables = {
NB_MANAGEMENT_URL = config.netbird.opts.management_url;
NB_ADMIN_URL = config.netbird.opts.admin_url;
NB_SETUP_KEY = config.netbird.opts.setup_key;
NB_SETUP_KEY_FILE = config.netbird.opts.setup_key_file;
};
};
}
(lib.mkIf (config.gui.enable) {
home-manager.users.${config.user} = {
home.packages = [
pkgs.netbird-ui
];
};
})
]);
}