summaryrefslogtreecommitdiff
path: root/modules/machine-id
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2024-08-23 20:09:41 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2024-08-23 20:09:41 +0200
commitf7c6f796fa348c2b3edfd9bc44d3e8533501681e (patch)
tree9fe21e6e85315a7c4b11f604dcee448971aabfb2 /modules/machine-id
parentc6d39b2d83cf588e1198ac3a2ae1893e276271f9 (diff)
downloadnixos-f7c6f796fa348c2b3edfd9bc44d3e8533501681e.tar
nixos-f7c6f796fa348c2b3edfd9bc44d3e8533501681e.tar.gz
nixos-f7c6f796fa348c2b3edfd9bc44d3e8533501681e.tar.bz2
nixos-f7c6f796fa348c2b3edfd9bc44d3e8533501681e.tar.xz
nixos-f7c6f796fa348c2b3edfd9bc44d3e8533501681e.zip
...
Diffstat (limited to 'modules/machine-id')
-rw-r--r--modules/machine-id/default.nix36
-rw-r--r--modules/machine-id/seed1
2 files changed, 37 insertions, 0 deletions
diff --git a/modules/machine-id/default.nix b/modules/machine-id/default.nix
new file mode 100644
index 00000000..2c33db26
--- /dev/null
+++ b/modules/machine-id/default.nix
@@ -0,0 +1,36 @@
1{ config, pkgs, lib, hostName, ... }:
2
3with lib;
4
5let
6 cfg = config.system.machine-id.generate;
7
8 generate = pkgs.writers.writePython3 "generate" {} ''
9 from hashlib import blake2s
10 from sys import argv
11 from base64 import b64decode
12
13
14 print(blake2s(
15 argv[2].strip().encode('utf-8'),
16 key=b64decode(argv[1]),
17 person=b'machn-id',
18 digest_size=16,
19 ).hexdigest())
20 '';
21
22 machine-id = trim (builtins.readFile (pkgs.runCommand "machine-id" { inherit hostName; } ''
23 ${generate} "${builtins.readFile ./seed}" "$hostName" > $out
24 ''));
25in {
26 options = {
27 system.machine-id.generate = {
28 enable = mkEnableOption "automatic generation of `/etc/machine-id`" // { default = true; };
29 };
30 };
31
32 config = mkIf cfg.enable {
33 environment.etc."machine-id".text = mkDefault machine-id;
34 networking.hostId = mkDefault (substring 0 8 machine-id);
35 };
36}
diff --git a/modules/machine-id/seed b/modules/machine-id/seed
new file mode 100644
index 00000000..176ce403
--- /dev/null
+++ b/modules/machine-id/seed
@@ -0,0 +1 @@
ZmOKMn16QBuqIix5RVMCBj11XxQrLCWxcdjs+qBiuRA=