2012-03-15 07:19:17 +00:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
2013-01-03 17:55:56 +00:00
|
|
|
with pkgs;
|
2012-03-15 07:19:17 +00:00
|
|
|
|
|
|
|
let
|
2012-09-19 12:13:34 +00:00
|
|
|
cfg = config.networking.networkmanager;
|
|
|
|
|
|
|
|
stateDirs = "/var/lib/NetworkManager /var/lib/dhclient";
|
|
|
|
|
2013-01-03 17:55:56 +00:00
|
|
|
configFile = writeText "NetworkManager.conf" ''
|
2012-09-19 12:13:34 +00:00
|
|
|
[main]
|
|
|
|
plugins=keyfile
|
|
|
|
|
|
|
|
[keyfile]
|
|
|
|
${optionalString (config.networking.hostName != "") ''
|
|
|
|
hostname=${config.networking.hostName}
|
|
|
|
''}
|
|
|
|
|
|
|
|
[logging]
|
|
|
|
level=WARN
|
|
|
|
'';
|
|
|
|
|
|
|
|
polkitConf = ''
|
|
|
|
[network-manager]
|
|
|
|
Identity=unix-group:networkmanager
|
|
|
|
Action=org.freedesktop.NetworkManager.*
|
|
|
|
ResultAny=yes
|
|
|
|
ResultInactive=no
|
|
|
|
ResultActive=yes
|
|
|
|
|
|
|
|
[modem-manager]
|
|
|
|
Identity=unix-group:networkmanager
|
|
|
|
Action=org.freedesktop.ModemManager.*
|
|
|
|
ResultAny=yes
|
|
|
|
ResultInactive=no
|
|
|
|
ResultActive=yes
|
|
|
|
'';
|
|
|
|
|
2013-01-03 17:55:56 +00:00
|
|
|
ipUpScript = writeScript "01nixos-ip-up" ''
|
2012-09-19 12:13:34 +00:00
|
|
|
#!/bin/sh
|
|
|
|
if test "$2" = "up"; then
|
2013-01-16 12:17:57 +00:00
|
|
|
${config.systemd.package}/bin/systemctl start ip-up.target
|
2012-09-19 12:13:34 +00:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
in {
|
2012-03-15 07:19:17 +00:00
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
networking.networkmanager.enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
merge = mergeEnableOption;
|
|
|
|
description = ''
|
|
|
|
Whether to use NetworkManager to obtain an IP adress and other
|
|
|
|
configuration for all network interfaces that are not manually
|
2012-09-19 12:13:34 +00:00
|
|
|
configured. If enabled, a group <literal>networkmanager</literal>
|
|
|
|
will be created. Add all users that should have permission
|
|
|
|
to change network settings to this group.
|
2012-03-15 07:19:17 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
networking.networkmanager.packages = mkOption {
|
2012-09-19 12:13:34 +00:00
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
Extra packages that provide NetworkManager plugins.
|
|
|
|
'';
|
|
|
|
merge = mergeListOption;
|
2013-01-03 17:55:56 +00:00
|
|
|
apply = list: [ networkmanager modemmanager wpa_supplicant ] ++ list;
|
2012-03-15 07:19:17 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2012-09-19 12:13:34 +00:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2013-03-31 19:18:51 +00:00
|
|
|
assertions = [{
|
|
|
|
assertion = config.networking.wireless.enable == false;
|
|
|
|
message = "You can not use networking.networkmanager with services.networking.wireless";
|
|
|
|
}];
|
|
|
|
|
2013-01-03 17:55:56 +00:00
|
|
|
environment.etc = [
|
|
|
|
{ source = ipUpScript;
|
|
|
|
target = "NetworkManager/dispatcher.d/01nixos-ip-up";
|
|
|
|
}
|
|
|
|
{ source = configFile;
|
|
|
|
target = "NetworkManager/NetworkManager.conf";
|
|
|
|
}
|
|
|
|
];
|
2012-09-19 12:13:34 +00:00
|
|
|
|
|
|
|
environment.systemPackages = cfg.packages;
|
2012-03-15 07:19:17 +00:00
|
|
|
|
2012-09-19 12:13:34 +00:00
|
|
|
users.extraGroups = singleton {
|
|
|
|
name = "networkmanager";
|
|
|
|
gid = config.ids.gids.networkmanager;
|
|
|
|
};
|
|
|
|
|
2013-01-03 17:55:56 +00:00
|
|
|
systemd.packages = cfg.packages;
|
|
|
|
|
|
|
|
# Create an initialisation service that both starts
|
|
|
|
# NetworkManager when network.target is reached,
|
|
|
|
# and sets up necessary directories for NM.
|
2013-01-17 12:37:54 +00:00
|
|
|
systemd.services."networkmanager-init" = {
|
2013-01-03 17:55:56 +00:00
|
|
|
description = "NetworkManager initialisation";
|
|
|
|
wantedBy = [ "network.target" ];
|
|
|
|
partOf = [ "NetworkManager.service" ];
|
|
|
|
wants = [ "NetworkManager.service" ];
|
|
|
|
before = [ "NetworkManager.service" ];
|
|
|
|
script = ''
|
2012-09-19 12:13:34 +00:00
|
|
|
mkdir -m 700 -p /etc/NetworkManager/system-connections
|
|
|
|
mkdir -m 755 -p ${stateDirs}
|
|
|
|
'';
|
2013-01-03 17:55:56 +00:00
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
};
|
2012-09-19 12:13:34 +00:00
|
|
|
};
|
2012-03-15 07:19:17 +00:00
|
|
|
|
2013-01-03 17:55:56 +00:00
|
|
|
# Turn off NixOS' network management
|
|
|
|
networking = {
|
|
|
|
useDHCP = false;
|
|
|
|
wireless.enable = false;
|
|
|
|
};
|
2012-09-19 12:13:34 +00:00
|
|
|
|
|
|
|
security.polkit.permissions = polkitConf;
|
|
|
|
|
|
|
|
services.dbus.packages = cfg.packages;
|
|
|
|
|
|
|
|
services.udev.packages = cfg.packages;
|
2012-03-15 07:19:17 +00:00
|
|
|
};
|
|
|
|
}
|