Revert "Merge pull request 'machine_id_v2' (#2052) from Qubasa/clan-core:machine_id_v2 into main"

This reverts commit 68a72a4156, reversing
changes made to 7af3e80249.
This commit is contained in:
a-kenji
2024-09-10 14:01:12 +02:00
parent 140e31ab94
commit f1b857f4ae
28 changed files with 254 additions and 545 deletions

View File

@@ -18,7 +18,5 @@
./vm.nix
./wayland-proxy-virtwl.nix
./zerotier
./machine_id.nix
./disk_id.nix
];
}

View File

@@ -1,48 +0,0 @@
{
config,
pkgs,
lib,
...
}:
let
cfg = config.clan.core.machine;
facts = config.clan.core.facts.services.diskId.public or { };
in
{
options.clan.core.machine = {
diskId = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = "The disk id";
};
generateDiskId = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Generate a new disk id";
};
};
config = lib.mkMerge [
(lib.mkIf ((facts.diskId.value or null) != null) {
clan.core.machine.diskId = lib.mkDefault facts.diskId.value;
})
(lib.mkIf cfg.generateDiskId {
clan.core.facts.services.diskId = {
public.diskId = { };
generator.path = [
pkgs.coreutils
pkgs.bash
];
generator.script = ''
uuid=$(bash ${./uuid4.sh})
# Remove the hyphens from the UUID
uuid_no_hyphens=$(echo -n "$uuid" | tr -d '-')
echo -n "$uuid_no_hyphens" > "$facts/diskId"
'';
};
})
];
}

View File

@@ -1,59 +0,0 @@
{
config,
pkgs,
lib,
...
}:
let
cfg = config.clan.core.machine;
facts = config.clan.core.facts.services.machineId.public or { };
in
{
options.clan.core.machine = {
machineId = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = "A machine id based on the UUID v4 format";
};
generateMachineId = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Generate a new machine id";
};
};
config = lib.mkMerge [
(lib.mkIf (cfg.machineId != null) {
assertions = [
{
assertion = lib.stringLength cfg.machineId == 32;
message = "machineId must be exactly 32 characters long.";
}
];
boot.kernelParams = [
''systemd.machine_id=${cfg.machineId}''
];
})
(lib.mkIf ((facts.machineId.value or null) != null) {
clan.core.machine.machineId = lib.mkDefault facts.machineId.value;
})
(lib.mkIf cfg.generateMachineId {
clan.core.facts.services.machineId = {
public.machineId = { };
generator.path = [
pkgs.coreutils
pkgs.bash
];
generator.script = ''
uuid=$(bash ${./uuid4.sh})
# Remove the hyphens from the UUID
uuid_no_hyphens=$(echo -n "$uuid" | tr -d '-')
echo -n "$uuid_no_hyphens" > "$facts/machineId"
'';
};
})
];
}

View File

@@ -1,20 +0,0 @@
#!/usr/bin/env bash
# Read 16 bytes from /dev/urandom
uuid=$(dd if=/dev/urandom bs=1 count=16 2>/dev/null | od -An -tx1 | tr -d ' \n')
# Break the UUID into pieces and apply the required modifications
byte6=${uuid:12:2}
byte8=${uuid:16:2}
# Construct the correct version and variant
hex_byte6=$(printf "%x" $((0x$byte6 & 0x0F | 0x40)))
hex_byte8=$(printf "%x" $((0x$byte8 & 0x3F | 0x80)))
# Rebuild the UUID with the correct fields
uuid_v4="${uuid:0:12}${hex_byte6}${uuid:14:2}${hex_byte8}${uuid:18:14}"
# Format the UUID correctly 8-4-4-4-12
uuid_formatted="${uuid_v4:0:8}-${uuid_v4:8:4}-${uuid_v4:12:4}-${uuid_v4:16:4}-${uuid_v4:20:12}"
echo -n "$uuid_formatted"