From 49d444416cf88dad03da0ec71573cd9747245581 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Forsman?= Date: Sun, 1 Jan 2017 16:41:34 +0100 Subject: [PATCH 1/2] nixos: cosmetic refactor of environment.etc."hostid" Create the file using attrset instead of list, to make it easier to later provide other files in the same module. --- nixos/modules/tasks/network-interfaces.nix | 24 +++++++++------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/nixos/modules/tasks/network-interfaces.nix b/nixos/modules/tasks/network-interfaces.nix index aaa78daeb3a3..74f7e5fcc2c3 100644 --- a/nixos/modules/tasks/network-interfaces.nix +++ b/nixos/modules/tasks/network-interfaces.nix @@ -910,20 +910,16 @@ in domainname "${cfg.domain}" ''; - environment.etc = mkIf (cfg.hostId != null) - [ - { - target = "hostid"; - source = pkgs.runCommand "gen-hostid" {} '' - hi="${cfg.hostId}" - ${if pkgs.stdenv.isBigEndian then '' - echo -ne "\x''${hi:0:2}\x''${hi:2:2}\x''${hi:4:2}\x''${hi:6:2}" > $out - '' else '' - echo -ne "\x''${hi:6:2}\x''${hi:4:2}\x''${hi:2:2}\x''${hi:0:2}" > $out - ''} - ''; - } - ]; + environment.etc."hostid" = mkIf (cfg.hostId != null) + { source = pkgs.runCommand "gen-hostid" {} '' + hi="${cfg.hostId}" + ${if pkgs.stdenv.isBigEndian then '' + echo -ne "\x''${hi:0:2}\x''${hi:2:2}\x''${hi:4:2}\x''${hi:6:2}" > $out + '' else '' + echo -ne "\x''${hi:6:2}\x''${hi:4:2}\x''${hi:2:2}\x''${hi:0:2}" > $out + ''} + ''; + }; environment.systemPackages = [ pkgs.host From cb9195b7bcde7ec8a2d5fa99df0a93afacd5c537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Forsman?= Date: Sun, 1 Jan 2017 16:44:32 +0100 Subject: [PATCH 2/2] nixos: provide /etc/hostname /etc/hostname is the file used by hostnamectl(1) and the org.freedesktop.hostname1 dbus service (both provided by systemd) to get the "static hostname". Better provide it so that users of those tools/services get a proper hostname. An example of an issue created by the lack of /etc/hostname is that the bluetooth stack on NixOS identifies itself to peers as "BlueZ $VERSION" instead of the hostname. References: https://www.freedesktop.org/software/systemd/man/hostname.html Changes v1 -> v2: * ensure /etc/hostname ends with a newline --- nixos/modules/tasks/network-interfaces.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/nixos/modules/tasks/network-interfaces.nix b/nixos/modules/tasks/network-interfaces.nix index 74f7e5fcc2c3..83d9854d3517 100644 --- a/nixos/modules/tasks/network-interfaces.nix +++ b/nixos/modules/tasks/network-interfaces.nix @@ -921,6 +921,13 @@ in ''; }; + # static hostname configuration needed for hostnamectl and the + # org.freedesktop.hostname1 dbus service (both provided by systemd) + environment.etc."hostname" = mkIf (cfg.hostName != "") + { + text = cfg.hostName + "\n"; + }; + environment.systemPackages = [ pkgs.host pkgs.iproute