How to set the hostId when migrating to flakes

I use ZFS which requires that I set the hostId within the networking set. I think this is the default as I don’t remember writing this myself.

  networking = {
    hostId = (builtins.substring 0 8 (builtins.readFile "/etc/machine-id"));
    networkmanager.enable = true;
    hostName = "mai";
    firewall.allowedUDPPorts = [ 631 ];
    firewall.allowedTCPPorts = [ 443 631 19000 8080 3000 3333 ];

However when I try to migrate to flakes I get the following error:

error: access to absolute path '/etc/machine-id' is forbidden in pure eval mode (use '--impure' to override)

What is the recommended way to fix this issue?

Copy the file into your flake if you want to readFile it, or I just put the string value straight in the flake.

I use dhcp, wont this potentially change or is it a fixed value that I can just hardcode as a string?

networking.hostId = “number” works for me - generate it yourself at install time…

it’s a fixed value. Since you’re migrating I’d actually copy the first 8 characters from the existing file in /etc.

Awesome, thanks for the speedy help!