From 63ae447a0fb30e0be364837ca0ceec6cfc12d252 Mon Sep 17 00:00:00 2001 From: Nikita Mikhailov Date: Sun, 8 Mar 2015 18:29:14 +0100 Subject: [PATCH 1/2] Add 'fixedWidthString' and 'fixedWidthNumber' formatting functions --- lib/strings.nix | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/strings.nix b/lib/strings.nix index 56d990de62da..39112407c570 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -208,4 +208,15 @@ rec { # standard GNU Autoconf scripts. enableFeature = enable: feat: "--${if enable then "enable" else "disable"}-${feat}"; + # Create a fixed width string with additional prefix to match required width + fixedWidthString = width: filler: str: + let + strw = lib.stringLength str; + reqWidth = width - (lib.stringLength filler); + in + assert strw <= width; + if strw == width then str else filler + fixedWidthString reqWidth filler str; + + # Format a number adding leading zeroes up to fixed width + fixedWidthNumber = width: n: fixedWidthString width "0" (toString n); } From 579159c72b222278dbec156a1526faddbe56472f Mon Sep 17 00:00:00 2001 From: Nikita Mikhailov Date: Sun, 8 Mar 2015 18:30:15 +0100 Subject: [PATCH 2/2] Add dispatcher configuration options to NetworkManager module --- .../services/networking/networkmanager.nix | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/networking/networkmanager.nix b/nixos/modules/services/networking/networkmanager.nix index f72c7fb39d6c..3a64d3f09e02 100644 --- a/nixos/modules/services/networking/networkmanager.nix +++ b/nixos/modules/services/networking/networkmanager.nix @@ -71,6 +71,13 @@ let ${coreutils}/bin/rm -f $tmp $tmp.ns ''; + # pre-up and pre-down hooks were added in NM 0.9.10, but we still use 0.9.0 + dispatcherTypesSubdirMap = { + "basic" = ""; + /*"pre-up" = "pre-up.d/"; + "pre-down" = "pre-down.d/";*/ + }; + in { ###### interface @@ -118,6 +125,30 @@ in { ''; }; + dispatcherScripts = mkOption { + type = types.listOf (types.submodule { + options = { + source = mkOption { + type = types.str; + description = '' + A script source. + ''; + }; + + type = mkOption { + type = types.enum (attrNames dispatcherTypesSubdirMap); + default = "basic"; + description = '' + Dispatcher hook type. Only basic hooks are currently available. + ''; + }; + }; + }); + default = []; + description = '' + A list of scripts which will be executed in response to network events. + ''; + }; }; }; @@ -155,7 +186,11 @@ in { ] ++ optional (cfg.appendNameservers == [] || cfg.insertNameservers == []) { source = overrideNameserversScript; target = "NetworkManager/dispatcher.d/02overridedns"; - }; + } + ++ lib.imap (i: s: { + text = s.source; + target = "NetworkManager/dispatcher.d/${dispatcherTypesSubdirMap.${s.type}}03userscript${lib.fixedWidthNumber 4 i}"; + }) cfg.dispatcherScripts; environment.systemPackages = cfg.packages ++ [ networkmanager_openvpn