diff --git a/flake.nix b/flake.nix index 226b78a..c823f6f 100644 --- a/flake.nix +++ b/flake.nix @@ -196,13 +196,10 @@ # Statically configure the host names of machines based on their respective zerotier-ip. inputs.clan-core.clanModules.static-hosts # generate ssh host keys with facts - # fixme: not working inputs.clan-core.clanModules.sshd ]; - documentation.nixos.enable = true; clan.static-hosts.topLevelDomain = "bear"; - #clan.static-hosts.excludeHosts = lib.mkForce [ ]; environment.systemPackages = [ clan-core.packages.${pkgs.system}.clan-cli ]; @@ -234,6 +231,7 @@ nix.settings.max-jobs = 1; # no channesl needed this way nix.nixPath = [ "nixpkgs=${pkgs.path}" ]; + documentation.nixos.enable = true; }) # some modules I always use permown.nixosModules.permown diff --git a/nixos/components/network/syncthing.nix b/nixos/components/network/syncthing.nix index 110fef2..44ab41e 100644 --- a/nixos/components/network/syncthing.nix +++ b/nixos/components/network/syncthing.nix @@ -2,6 +2,14 @@ let syncthingPub = clanLib.readFact "syncthing.pub"; zerotierIp = clanLib.readFact "zerotier-ip"; + clanMachines = + lib.mapAttrs + (machine: facts: { + name = machine; + id = facts."syncthing.pub"; + addresses = [ "tcp://[${facts."zerotier-ip"}]:22000" ]; + }) + (clanLib.readFactsFromAllMachines [ "syncthing.pub" "zerotier-ip" ]); in with lib; { @@ -40,12 +48,7 @@ with lib; { }; }; in - { } - - // (zeroDevice "orbi") - // (zeroDevice "cream") - // (zeroDevice "cherry") - // (zeroDevice "chungus") + clanMachines #// (device "mobi" ) #// (device "bobi" ) diff --git a/nixos/lib/clanlib.nix b/nixos/lib/clanlib.nix index 9318493..855c628 100644 --- a/nixos/lib/clanlib.nix +++ b/nixos/lib/clanlib.nix @@ -15,6 +15,7 @@ let else null; + # machine -> factvalue readFactFromAllMachines = fact: let machines = allMachineNames; @@ -23,5 +24,20 @@ let in filteredFacts; + # returns an Attrs of machines and it's facts which have all given facts set. + # machine -> fact -> value + readFactsFromAllMachines = facts: + let + # machine -> fact -> factvalue + machinesFactsAttrs = lib.genAttrs allMachineNames (machine: lib.genAttrs facts (fact: readFact fact machine)); + # remove all machines which don't have all facts set + filteredMachineFactAttrs = + lib.filterAttrs (_machine: values: builtins.all (fact: values.${fact} != null) facts) + machinesFactsAttrs; + in + filteredMachineFactAttrs; + + + in -{ inherit allMachineNames getFactPath readFact readFactFromAllMachines; } +{ inherit allMachineNames getFactPath readFact readFactFromAllMachines readFactsFromAllMachines; }