From 8fe2cff0cc646369f0d07fcddcde063a41b373a1 Mon Sep 17 00:00:00 2001 From: Piotr Limanowski Date: Wed, 5 Jul 2017 11:32:36 +0200 Subject: [PATCH] Adds an idea for networking module The idea is to follow: https://nixos.org/nixos/options.html#networking so we can share even more configuration ideas from NixOS. --- default.nix | 1 + modules/networking/default.nix | 41 +++++++++++++++++++++++++++ modules/system/activation-scripts.nix | 1 + 3 files changed, 43 insertions(+) create mode 100644 modules/networking/default.nix diff --git a/default.nix b/default.nix index 89fc103..734529c 100644 --- a/default.nix +++ b/default.nix @@ -31,6 +31,7 @@ let ./modules/system/etc.nix ./modules/system/launchd.nix ./modules/time + ./modules/networking ./modules/nix ./modules/nix/nix-darwin.nix ./modules/nix/nixpkgs.nix diff --git a/modules/networking/default.nix b/modules/networking/default.nix new file mode 100644 index 0000000..634618e --- /dev/null +++ b/modules/networking/default.nix @@ -0,0 +1,41 @@ +{ config, lib, pkgs, ... }: + +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}" + ''; + +in + +{ + options = { + + networking.hostName = mkOption { + type = types.nullOr types.str; + default = null; + example = "myhostname"; + description = '' + Hostname for your machine. + ''; + }; + + }; + + config = { + + system.activationScripts.networking.text = '' + # Set defaults + echo "configuring networking..." >&2 + + ${hostName} + ''; + + }; +} diff --git a/modules/system/activation-scripts.nix b/modules/system/activation-scripts.nix index 301c612..aa97633 100644 --- a/modules/system/activation-scripts.nix +++ b/modules/system/activation-scripts.nix @@ -60,6 +60,7 @@ in ${cfg.activationScripts.etc.text} ${cfg.activationScripts.launchd.text} ${cfg.activationScripts.time.text} + ${cfg.activationScripts.networking.text} # Make this configuration the current configuration. # The readlink is there to ensure that when $systemConfig = /system