This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

superconfig / configs / kartei.nix
2.6 kB 85 lines
1# Host data from the kartei flake input, rendered straight into NixOS 2# options; stockholm's krebs.hosts (and its hosts/ssh/build modules) is not 3# used. Hosts are kartei's plus the superconfig-only cards in ../retiolum. 4{ 5 config, 6 lib, 7 self, 8 ... 9}: 10let 11 inherit (self.inputs) kartei; 12 13 hosts = kartei.hosts // self.retiolum.hosts; 14 15 # Name suffixes that go into /etc/hosts; ".r" names also get a bare short 16 # form (barnacle.r -> barnacle), as stockholm's krebs.dns did. 17 domains = [ 18 "r" 19 "i" 20 "w" 21 "shack" 22 ]; 23 hostDomain = alias: lib.any (d: lib.hasSuffix ".${d}" alias) domains; 24 shortsOf = aliases: map (lib.removeSuffix ".r") (lib.filter (lib.hasSuffix ".r") aliases); 25 26 # superconfig's own cards (../retiolum) only carry ip4/ip6/aliases 27 netAddrs = 28 net: 29 net.addrs or ( 30 lib.optional (net.ip4 or null != null) net.ip4.addr 31 ++ lib.optional (net.ip6 or null != null) net.ip6.addr 32 ); 33 netAliases = net: net.aliases or [ ]; 34 sshPort = net: net.ssh.port or 22; 35 36 allNets = lib.concatMap (host: lib.attrValues (host.nets or { })) (lib.attrValues hosts); 37 38in 39{ 40 config = { 41 networking.hosts = lib.filterAttrs (_: names: names != [ ]) ( 42 lib.zipAttrsWith (_: lib.concatLists) ( 43 lib.concatMap ( 44 net: 45 let 46 longs = lib.filter hostDomain (netAliases net); 47 names = longs ++ shortsOf longs; 48 in 49 map (addr: { ${addr} = names; }) (netAddrs net) 50 ) allNets 51 ) 52 ); 53 54 services.openssh.knownHosts = 55 lib.filterAttrs (_: known: known.publicKey != null && known.hostNames != [ ]) 56 ( 57 lib.mapAttrs (_: host: { 58 publicKey = host.ssh.pubkey or null; 59 hostNames = lib.concatMap ( 60 net: 61 map (name: if sshPort net != 22 then "[${name}]:${toString (sshPort net)}" else name) ( 62 shortsOf (netAliases net) ++ netAliases net ++ netAddrs net 63 ) 64 ) (lib.attrValues (host.nets or { })); 65 }) hosts 66 // { 67 localhost = { 68 publicKey = hosts.${config.networking.hostName}.ssh.pubkey or null; 69 hostNames = [ 70 "localhost" 71 "127.0.0.1" 72 "::1" 73 ]; 74 }; 75 } 76 ); 77 78 programs.ssh.extraConfig = lib.mkBefore ( 79 lib.concatMapStrings (net: '' 80 Host ${toString (netAliases net ++ netAddrs net)} 81 Port ${toString (sshPort net)} 82 '') (lib.filter (net: sshPort net != 22) allNets) 83 ); 84 }; 85}