Skip to content

Commit 95545c0

Browse files
committed
hosts/bastille: add some actual names to auto-hostname
there's still some possible issues with the script (hence the paranoid `echo` after `hostname`)
1 parent 6041f78 commit 95545c0

2 files changed

Lines changed: 37 additions & 19 deletions

File tree

hosts/bastille/auto-hostname.nix

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{ pkgs, lib, ... }:
22
let
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

@@ -15,9 +18,22 @@ let
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
};
2339
in {

hosts/bastille/blade-names.nix

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
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+
}

0 commit comments

Comments
 (0)