mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-16 23:03:40 +01:00
networkmanager NixOS service: Make it possible to append or insert name servers in /etc/resolv.conf
This commit is contained in:
parent
f923c32204
commit
26d7598d46
1 changed files with 22 additions and 20 deletions
|
@ -55,15 +55,19 @@ let
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
ns = xs: writeText "nameservers" (
|
||||||
|
concatStrings (map (s: "nameserver ${s}\n") xs)
|
||||||
|
);
|
||||||
|
|
||||||
overrideNameserversScript = writeScript "02overridedns" ''
|
overrideNameserversScript = writeScript "02overridedns" ''
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
${optionalString cfg.overrideNameservers "${gnused}/bin/sed -i '/nameserver /d' /etc/resolv.conf"}
|
tmp=`${coreutils}/bin/mktemp`
|
||||||
${concatStrings (map (s: ''
|
${gnused}/bin/sed '/nameserver /d' /etc/resolv.conf > $tmp
|
||||||
${optionalString cfg.appendNameservers
|
${gnugrep}/bin/grep 'nameserver ' /etc/resolv.conf | \
|
||||||
"${gnused}/bin/sed -i '/nameserver ${s}/d' /etc/resolv.conf"
|
${gnugrep}/bin/grep -vf ${ns (cfg.appendNameservers ++ cfg.insertNameservers)} > $tmp.ns
|
||||||
}
|
${optionalString (cfg.appendNameservers != []) "${coreutils}/bin/cat $tmp $tmp.ns ${ns cfg.appendNameservers} > /etc/resolv.conf"}
|
||||||
echo 'nameserver ${s}' >> /etc/resolv.conf
|
${optionalString (cfg.insertNameservers != []) "${coreutils}/bin/cat $tmp ${ns cfg.insertNameservers} $tmp.ns > /etc/resolv.conf"}
|
||||||
'') config.networking.nameservers)}
|
${coreutils}/bin/rm -f $tmp $tmp.ns
|
||||||
'';
|
'';
|
||||||
|
|
||||||
in {
|
in {
|
||||||
|
@ -95,23 +99,21 @@ in {
|
||||||
apply = list: [ networkmanager modemmanager wpa_supplicant ] ++ list;
|
apply = list: [ networkmanager modemmanager wpa_supplicant ] ++ list;
|
||||||
};
|
};
|
||||||
|
|
||||||
overrideNameservers = mkOption {
|
appendNameservers = mkOption {
|
||||||
default = false;
|
type = types.listOf types.string;
|
||||||
|
default = [];
|
||||||
description = ''
|
description = ''
|
||||||
If enabled, any nameservers received by DHCP or configured in
|
A list of name servers that should be appended
|
||||||
NetworkManager will be replaced by the nameservers configured
|
to the ones configured in NetworkManager or received by DHCP.
|
||||||
in the <literal>networking.nameservers</literal> option. This
|
|
||||||
option overrides the <literal>appendNameservers</literal> option
|
|
||||||
if both are enabled.
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
appendNameservers = mkOption {
|
insertNameservers = mkOption {
|
||||||
default = false;
|
type = types.listOf types.string;
|
||||||
|
default = [];
|
||||||
description = ''
|
description = ''
|
||||||
If enabled, the name servers configured in the
|
A list of name servers that should be inserted before
|
||||||
<literal>networking.nameservers</literal> option will be appended
|
the ones configured in NetworkManager or received by DHCP.
|
||||||
to the ones configured in NetworkManager or received by DHCP.
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -144,7 +146,7 @@ in {
|
||||||
{ source = "${networkmanager_openconnect}/etc/NetworkManager/VPN/nm-openconnect-service.name";
|
{ source = "${networkmanager_openconnect}/etc/NetworkManager/VPN/nm-openconnect-service.name";
|
||||||
target = "NetworkManager/VPN/nm-openconnect-service.name";
|
target = "NetworkManager/VPN/nm-openconnect-service.name";
|
||||||
}
|
}
|
||||||
] ++ pkgs.lib.optional (cfg.overrideNameservers || cfg.appendNameservers)
|
] ++ pkgs.lib.optional (cfg.appendNameservers == [] || cfg.insertNameservers == [])
|
||||||
{ source = overrideNameserversScript;
|
{ source = overrideNameserversScript;
|
||||||
target = "NetworkManager/dispatcher.d/02overridedns";
|
target = "NetworkManager/dispatcher.d/02overridedns";
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue