This repository has no description
0

Configure Feed

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

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