From 7a7bf8368e25d13b1f2e915514c804728b7648ef Mon Sep 17 00:00:00 2001 From: "Ricardo M. Correia" Date: Sat, 1 Nov 2014 18:27:54 +0100 Subject: [PATCH] nixos-generate-config: Configure networking.hostId by default The host id value gets generated by reading a 32-bit value from /dev/urandom. This makes programs that rely on a correct host id more reliable. It also makes using ZFS more seamless, as you don't need to configure the hostId manually; instead, it becomes part of your config from the moment you install NixOS. --- nixos/modules/installer/tools/nixos-generate-config.pl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nixos/modules/installer/tools/nixos-generate-config.pl b/nixos/modules/installer/tools/nixos-generate-config.pl index e8f100d6498..9abc1b4cc1b 100644 --- a/nixos/modules/installer/tools/nixos-generate-config.pl +++ b/nixos/modules/installer/tools/nixos-generate-config.pl @@ -476,6 +476,14 @@ EOF EOF } + # Generate a random 32-bit value to use as the host id + open my $rnd, "<", "/dev/urandom" or die $!; + read $rnd, $hostIdBin, 4; + close $rnd; + + # Convert the 32-bit value to a hex string + my $hostIdHex = unpack("H*", $hostIdBin); + write_file($fn, <