File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11{ pkgs , lib , ... } :
22let
3- # TODO: make this like a python script with a list of interfaces in order of preference
3+ names = import ./blade-names.nix ;
4+
5+ bash-sets = lib . mapAttrsToList ( mac : name : "names['${ mac } ']='${ name } '" ) names ;
6+
47 auto-hostname = pkgs . writeShellApplication {
58 name = "auto-hostname" ;
69
1518 mac_file=/sys/class/net/enp0s25/address
1619 fi
1720
18- mac=$(cat $mac_file | tr -d '\r\n ' | tr ':' '-')
21+ mac=$(cat $mac_file | tr -d '\r\n ')
22+
23+ declare -A names
24+ ${ lib . concatLines bash-sets }
25+
26+ if [[ -v names[$mac] ]]; then
27+ name='' ${names[$mac]}
28+ else
29+ name="node-(echo $mac | tr ':' '-')"
30+ fi
31+
32+ echo "mac: '$mac'"
33+ echo "name: '$name'"
1934
20- hostname "blade-$mac"
35+ hostname "$name"
36+ echo "hostname set to '$(hostname)'"
2137 '' ;
2238 } ;
2339in {
Original file line number Diff line number Diff line change 1- # keep-sorted start
2- [
3- "backbiter"
4- "damocles"
5- "durendal"
6- "eyelander"
7- "excalibur"
8- "gram"
9- "gryffindor"
10- "kusanagi"
11- "narsil"
12- "oathbringer"
13- "riptide"
14- "sting"
15- ]
16- # keep-sorted end
1+ {
2+ # TODO: prospit's a special case and won't remain here forever
3+ "d8:9e:f3:3e:f9:41" = "prospit" ;
4+
5+ "40:f2:e9:c6:65:5f" = "backbiter" ;
6+ "40:f2:e9:c6:69:43" = "damocles" ;
7+ "40:f2:e9:c6:69:67" = "durendal" ;
8+ "40:f2:e9:c6:74:59" = "eyelander" ;
9+ "40:f2:e9:c6:75:f1" = "excalibur" ;
10+ "40:f2:e9:c6:76:21" = "gram" ;
11+
12+ "unassigned-0" = "gryffindor" ;
13+ "unassigned-1" = "kusanagi" ;
14+ "unassigned-2" = "narsil" ;
15+ "unassigned-3" = "oathbringer" ;
16+ "unassigned-4" = "riptide" ;
17+ "unassigned-5" = "sting" ;
18+ }
You can’t perform that action at this time.
0 commit comments