clanModules/mycelium: Remove certain options for compatibility reasons
Remove certain options for compatibility reasons We want to reintroduce them once we pass in `vars` through the inventory.
This commit is contained in:
@@ -24,14 +24,7 @@ mycelium.default = {
|
||||
"berlin"
|
||||
"munich"
|
||||
];
|
||||
config = {
|
||||
topLevelDomain = "m";
|
||||
openFirewall = true;
|
||||
addHostedPublicNodes = true;
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
This will add the machines named `berlin` and `munich` to the `mycelium` vpn.
|
||||
And will also set the toplevel domain of the mycelium vpn to `m`, meaning the
|
||||
machines are now reachable via `berlin.m` and `munich.m`.
|
||||
|
||||
@@ -4,55 +4,10 @@
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
flake = config.clan.core.settings.directory;
|
||||
machineName = config.clan.core.settings.machine.name;
|
||||
|
||||
# Instances might be empty, if the module is not used via the inventory
|
||||
#
|
||||
# Type: { ${instanceName} :: { roles :: Roles } }
|
||||
# Roles :: { ${role_name} :: { machines :: [string] } }
|
||||
instances = config.clan.inventory.services.mycelium or { };
|
||||
|
||||
allPeers = lib.foldlAttrs (
|
||||
acc: _instanceName: instanceConfig:
|
||||
acc
|
||||
++ (
|
||||
if (builtins.elem machineName instanceConfig.roles.peer.machines) then
|
||||
instanceConfig.roles.peer.machines
|
||||
else
|
||||
[ ]
|
||||
)
|
||||
) [ ] instances;
|
||||
allPeerConfigurations = lib.filterAttrs (n: _: builtins.elem n allPeers) flake.nixosConfigurations;
|
||||
allPeersWithIp =
|
||||
builtins.mapAttrs
|
||||
(_: x: lib.removeSuffix "\n" x.config.clan.core.vars.generators.mycelium.files.ip.value)
|
||||
(
|
||||
lib.filterAttrs (
|
||||
_: x: (builtins.tryEval x.config.clan.core.vars.generators.mycelium.files.ip.value).success
|
||||
) allPeerConfigurations
|
||||
);
|
||||
|
||||
ips = lib.attrValues allPeersWithIp;
|
||||
peers = lib.concatMap (ip: [
|
||||
"tcp://[${ip}]:9651"
|
||||
"quic://[${ip}]:9651"
|
||||
]) ips;
|
||||
in
|
||||
{
|
||||
options = {
|
||||
clan.mycelium.topLevelDomain = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "";
|
||||
description = "Top level domain to reach hosts";
|
||||
};
|
||||
clan.mycelium.openFirewall = lib.mkEnableOption "Open the firewall for mycelium";
|
||||
clan.mycelium.addHostedPublicNodes = lib.mkEnableOption "Add hosted Public nodes";
|
||||
clan.mycelium.addHosts = lib.mkOption {
|
||||
default = true;
|
||||
description = "Add mycelium ip's to the host file";
|
||||
};
|
||||
};
|
||||
|
||||
config.services.mycelium = {
|
||||
@@ -60,18 +15,8 @@ in
|
||||
addHostedPublicNodes = lib.mkDefault config.clan.mycelium.addHostedPublicNodes;
|
||||
openFirewall = lib.mkDefault config.clan.mycelium.openFirewall;
|
||||
keyFile = config.clan.core.vars.generators.mycelium.files.key.path;
|
||||
inherit peers;
|
||||
};
|
||||
|
||||
config.networking.hosts = lib.mkIf (config.clan.mycelium.addHosts) (
|
||||
lib.mapAttrs' (
|
||||
host: ip:
|
||||
lib.nameValuePair ip (
|
||||
if (config.clan.mycelium.topLevelDomain == "") then [ host ] else [ "${host}.m" ]
|
||||
)
|
||||
) allPeersWithIp
|
||||
);
|
||||
|
||||
config.clan.core.vars.generators.mycelium = {
|
||||
files."key" = { };
|
||||
files."ip".secret = false;
|
||||
|
||||
Reference in New Issue
Block a user