diff --git a/nixos/modules/system/etc/etc-activation.nix b/nixos/modules/system/etc/etc-activation.nix index c294a3a6d436..b00c25e37802 100644 --- a/nixos/modules/system/etc/etc-activation.nix +++ b/nixos/modules/system/etc/etc-activation.nix @@ -173,5 +173,18 @@ }) + (lib.mkIf (config.system.etc.overlay.enable && !config.system.etc.overlay.mutable) { + # Systemd requires /etc/machine-id exists or can be initialized on first + # boot. This file should not be part of an image or system config because + # it is unique to the machine, so it is initialized at first boot and + # persisted in the system state directory, /var/lib/nixos. + environment.etc."machine-id".source = lib.mkDefault "/var/lib/nixos/machine-id"; + boot.initrd.systemd.tmpfiles.settings.machine-id."/sysroot/var/lib/nixos/machine-id".f = + lib.mkDefault + { + argument = "uninitialized"; + }; + }) + ]; }