From becb4b69c13946bec535b8e0a0c64e9b661c699f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 4 Dec 2007 15:02:48 +0000 Subject: [PATCH] Allow the hostname to be empty (to obtain it using dhcp). svn path=/nixos/trunk/; revision=9857 --- system/activate-configuration.sh | 14 ++++++++++++-- system/options.nix | 5 ++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/system/activate-configuration.sh b/system/activate-configuration.sh index 962be60b2a3..2ed025e1803 100644 --- a/system/activate-configuration.sh +++ b/system/activate-configuration.sh @@ -119,6 +119,7 @@ mkdir -m 1777 -p /nix/var/nix/gcroots/per-user mkdir -m 0755 -p /nix/var/nix/temproots mkdir -m 0755 -p /nix/var/nix/profiles mkdir -m 1777 -p /nix/var/nix/profiles/per-user +mkdir -m 0755 -p /nix/var/nix/channel-cache ln -sf /nix/var/nix/profiles /nix/var/nix/gcroots/ ln -sf /nix/var/nix/manifests /nix/var/nix/gcroots/ @@ -138,8 +139,17 @@ for i in @setuidPrograms@; do done -# Set the host name. -hostname @hostName@ +# Set the host name. Don't clear it if it's not configured in the +# NixOS configuration, since it may have been set by dhclient in the +# meantime. +if test -n "@hostName@"; then + hostname @hostName@ +else + # dhclient won't do anything if the hostname isn't empty. + if test "$(hostname)" = "(none)"; then + hostname '' + fi +fi # Make this configuration the current configuration. diff --git a/system/options.nix b/system/options.nix index e06b4c2197b..974034648f9 100644 --- a/system/options.nix +++ b/system/options.nix @@ -216,7 +216,10 @@ hostName = mkOption { default = "nixos"; - description = "The name of the machine."; + description = " + The name of the machine. Leave it empty if you want to obtain + it from a DHCP server (if using DHCP). + "; }; extraHosts = mkOption {