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.
This commit is contained in:
Ricardo M. Correia 2014-11-01 18:27:54 +01:00
parent e9affb4274
commit 7a7bf8368e

View File

@ -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, <<EOF);
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page
@ -491,6 +499,7 @@ EOF
$bootLoaderConfig
# networking.hostName = "nixos"; # Define your hostname.
networking.hostId = "$hostIdHex";
# networking.wireless.enable = true; # Enables wireless.
# Select internationalisation properties.