update clanlib.nix

This commit is contained in:
Ingolf Wagner 2024-06-07 07:54:43 +02:00
parent b8cf22c653
commit 5574cf652d
Signed by: palo
GPG key ID: 76BF5F1928B9618B
3 changed files with 27 additions and 10 deletions

View file

@ -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

View file

@ -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" )

View file

@ -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; }