From f7c6f796fa348c2b3edfd9bc44d3e8533501681e Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 23 Aug 2024 20:09:41 +0200 Subject: ... --- modules/machine-id/default.nix | 36 ++++++++++++++++++++++++++++++++++++ modules/machine-id/seed | 1 + 2 files changed, 37 insertions(+) create mode 100644 modules/machine-id/default.nix create mode 100644 modules/machine-id/seed (limited to 'modules/machine-id') 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 @@ +{ config, pkgs, lib, hostName, ... }: + +with lib; + +let + cfg = config.system.machine-id.generate; + + generate = pkgs.writers.writePython3 "generate" {} '' + from hashlib import blake2s + from sys import argv + from base64 import b64decode + + + print(blake2s( + argv[2].strip().encode('utf-8'), + key=b64decode(argv[1]), + person=b'machn-id', + digest_size=16, + ).hexdigest()) + ''; + + machine-id = trim (builtins.readFile (pkgs.runCommand "machine-id" { inherit hostName; } '' + ${generate} "${builtins.readFile ./seed}" "$hostName" > $out + '')); +in { + options = { + system.machine-id.generate = { + enable = mkEnableOption "automatic generation of `/etc/machine-id`" // { default = true; }; + }; + }; + + config = mkIf cfg.enable { + environment.etc."machine-id".text = mkDefault machine-id; + networking.hostId = mkDefault (substring 0 8 machine-id); + }; +} 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= -- cgit v1.2.3