From 7eb4e21075843a85ce9d31bbcaefe23d688e8f7d Mon Sep 17 00:00:00 2001 From: Daiderd Jordan Date: Fri, 5 Jan 2018 00:15:11 +0100 Subject: [PATCH] defaults: add option for NetBIOSName --- default.nix | 1 + modules/networking/default.nix | 11 +++-------- modules/system/defaults-write.nix | 2 ++ modules/system/defaults/smb.nix | 13 +++++++++++++ tests/networking.nix | 14 ++++++++++++++ 5 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 modules/system/defaults/smb.nix create mode 100644 tests/networking.nix diff --git a/default.nix b/default.nix index 1f8e479d..2b1516a0 100644 --- a/default.nix +++ b/default.nix @@ -28,6 +28,7 @@ let ./modules/system/defaults/LaunchServices.nix ./modules/system/defaults/dock.nix ./modules/system/defaults/finder.nix + ./modules/system/defaults/smb.nix ./modules/system/defaults/trackpad.nix ./modules/system/applications.nix ./modules/system/etc.nix diff --git a/modules/networking/default.nix b/modules/networking/default.nix index 0eed2844..e45199ee 100644 --- a/modules/networking/default.nix +++ b/modules/networking/default.nix @@ -3,34 +3,29 @@ with lib; let - cfg = config.networking; hostName = optionalString (cfg.hostName != null) '' scutil --set ComputerName '${cfg.hostName}' scutil --set LocalHostName '${cfg.hostName}' scutil --set HostName '${cfg.hostName}' - defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string '${cfg.hostName}' ''; - in { options = { - networking.hostName = mkOption { type = types.nullOr types.str; default = null; example = "myhostname"; - description = '' - Hostname for your machine. - ''; + description = "Hostname for your machine."; }; - }; config = { + system.defaults.smb.NetBIOSName = cfg.hostName; + system.activationScripts.networking.text = '' # Set defaults echo "configuring networking..." >&2 diff --git a/modules/system/defaults-write.nix b/modules/system/defaults-write.nix index e5c2cddb..eca78b6a 100644 --- a/modules/system/defaults-write.nix +++ b/modules/system/defaults-write.nix @@ -26,6 +26,7 @@ let LaunchServices = defaultsToList "com.apple.LaunchServices" cfg.LaunchServices; dock = defaultsToList "com.apple.dock" cfg.dock; finder = defaultsToList "com.apple.finder" cfg.finder; + smb = defaultsToList "/Library/Preferences/SystemConfiguration/com.apple.smb.server" cfg.smb; trackpad = defaultsToList "com.apple.AppleMultitouchTrackpad" cfg.trackpad; trackpadBluetooth = defaultsToList "com.apple.driver.AppleBluetoothMultitouch.trackpad" cfg.trackpad; @@ -45,6 +46,7 @@ in ${concatStringsSep "\n" LaunchServices} ${concatStringsSep "\n" dock} ${concatStringsSep "\n" finder} + ${concatStringsSep "\n" smb} ${concatStringsSep "\n" trackpad} ${concatStringsSep "\n" trackpadBluetooth} ''; diff --git a/modules/system/defaults/smb.nix b/modules/system/defaults/smb.nix new file mode 100644 index 00000000..edc9d06d --- /dev/null +++ b/modules/system/defaults/smb.nix @@ -0,0 +1,13 @@ +{ config, lib, ... }: + +with lib; + +{ + options = { + system.defaults.smb.NetBIOSName = mkOption { + type = types.nullOr types.str; + default = null; + description = "Hostname to use for NetBIOS."; + }; + }; +} diff --git a/tests/networking.nix b/tests/networking.nix new file mode 100644 index 00000000..f89277aa --- /dev/null +++ b/tests/networking.nix @@ -0,0 +1,14 @@ +{ config, pkgs, ... }: + +{ + networking.hostName = "EVE"; + + test = '' + echo checking hostname in /activate >&2 + grep "scutil --set ComputerName 'EVE'" ${config.out}/activate + grep "scutil --set LocalHostName 'EVE'" ${config.out}/activate + grep "scutil --set HostName 'EVE'" ${config.out}/activate + echo checking defaults write in ${config.out}/activate-user >&2 + grep "defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server 'NetBIOSName' -string 'EVE'" ${config.out}/activate-user + ''; +}