nixos/systemd-boot: Don't write to /etc/machine-id (#347493)

This commit is contained in:
Julien Malka
2025-01-02 11:47:20 +01:00
committed by GitHub
2 changed files with 2 additions and 9 deletions

View File

@@ -619,9 +619,6 @@ let format' = format; in let
# __noChroot for example). # __noChroot for example).
export HOME=$TMPDIR export HOME=$TMPDIR
NIXOS_INSTALL_BOOTLOADER=1 nixos-enter --root $mountPoint -- /nix/var/nix/profiles/system/bin/switch-to-configuration boot NIXOS_INSTALL_BOOTLOADER=1 nixos-enter --root $mountPoint -- /nix/var/nix/profiles/system/bin/switch-to-configuration boot
# The above scripts will generate a random machine-id and we don't want to bake a single ID into all our images
rm -f $mountPoint/etc/machine-id
''} ''}
# Set the ownerships of the contents. The modes are set in preVM. # Set the ownerships of the contents. The modes are set in preVM.

View File

@@ -159,7 +159,7 @@ def copy_from_file(file: str, dry_run: bool = False) -> str:
def write_entry(profile: str | None, generation: int, specialisation: str | None, def write_entry(profile: str | None, generation: int, specialisation: str | None,
machine_id: str, bootspec: BootSpec, current: bool) -> None: machine_id: str | None, bootspec: BootSpec, current: bool) -> None:
if specialisation: if specialisation:
bootspec = bootspec.specialisations[specialisation] bootspec = bootspec.specialisations[specialisation]
kernel = copy_from_file(bootspec.kernel) kernel = copy_from_file(bootspec.kernel)
@@ -281,11 +281,7 @@ def install_bootloader(args: argparse.Namespace) -> None:
except IOError as e: except IOError as e:
if e.errno != errno.ENOENT: if e.errno != errno.ENOENT:
raise raise
# Since systemd version 232 a machine ID is required and it might not machine_id = None
# be there on newly installed systems, so let's generate one so that
# bootctl can find it and we can also pass it to write_entry() later.
cmd = [f"{SYSTEMD}/bin/systemd-machine-id-setup", "--print"]
machine_id = run(cmd, stdout=subprocess.PIPE).stdout.rstrip()
if os.getenv("NIXOS_INSTALL_GRUB") == "1": if os.getenv("NIXOS_INSTALL_GRUB") == "1":
warnings.warn("NIXOS_INSTALL_GRUB env var deprecated, use NIXOS_INSTALL_BOOTLOADER", DeprecationWarning) warnings.warn("NIXOS_INSTALL_GRUB env var deprecated, use NIXOS_INSTALL_BOOTLOADER", DeprecationWarning)