networking: add dhcpClientId option to set DHCP Client ID
This commit is contained in:
parent
8b720b9662
commit
05a5979906
4 changed files with 37 additions and 0 deletions
|
|
@ -18,6 +18,9 @@ let
|
|||
*${lib.escapeShellArg srv}*)
|
||||
networksetup -setdnsservers ${lib.escapeShellArgs ([ srv ] ++ (emptyList cfg.dns))}
|
||||
networksetup -setsearchdomains ${lib.escapeShellArgs ([ srv ] ++ (emptyList cfg.search))}
|
||||
${optionalString (cfg.dhcpClientId != null) ''
|
||||
networksetup -setdhcp ${lib.escapeShellArgs [ srv cfg.dhcpClientId ]}
|
||||
''}
|
||||
;;
|
||||
esac
|
||||
'') cfg.knownNetworkServices}
|
||||
|
|
@ -133,6 +136,21 @@ in
|
|||
'';
|
||||
};
|
||||
|
||||
networking.dhcpClientId = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
example = "my-client-id";
|
||||
description = ''
|
||||
The DHCP client identifier to use when requesting an IP address from a DHCP server.
|
||||
|
||||
If this option is set, it will be used by the system when requesting an IP address.
|
||||
If not set, no changes will be made.
|
||||
|
||||
Set to the string "empty" to clear any previously configured client ID
|
||||
and restore the system default behavior.
|
||||
'';
|
||||
};
|
||||
|
||||
networking.dns = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [];
|
||||
|
|
@ -162,6 +180,7 @@ in
|
|||
warnings = [
|
||||
(mkIf (cfg.knownNetworkServices == [] && cfg.dns != []) "networking.knownNetworkServices is empty, dns servers will not be configured.")
|
||||
(mkIf (cfg.knownNetworkServices == [] && cfg.search != []) "networking.knownNetworkServices is empty, dns searchdomains will not be configured.")
|
||||
(mkIf (cfg.knownNetworkServices == [] && cfg.dhcpClientId != null) "networking.knownNetworkServices is empty, dhcp client ID will not be configured.")
|
||||
];
|
||||
|
||||
system.activationScripts.networking.text = ''
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ in {
|
|||
tests.networking-firewall = makeTest ./tests/networking-firewall.nix;
|
||||
tests.networking-hostname = makeTest ./tests/networking-hostname.nix;
|
||||
tests.networking-networkservices = makeTest ./tests/networking-networkservices.nix;
|
||||
tests.networking-networkservices-no-dhcp-client-id = makeTest ./tests/networking-networkservices-no-dhcp-client-id.nix;
|
||||
tests.nix-enable = makeTest ./tests/nix-enable.nix;
|
||||
tests.nixpkgs-overlays = makeTest ./tests/nixpkgs-overlays.nix;
|
||||
tests.programs-gnupg = makeTest ./tests/programs-gnupg.nix;
|
||||
|
|
|
|||
14
tests/networking-networkservices-no-dhcp-client-id.nix
Normal file
14
tests/networking-networkservices-no-dhcp-client-id.nix
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{ config, lib, ... }:
|
||||
|
||||
{
|
||||
networking.knownNetworkServices = [ "Wi-Fi" "Thunderbolt Ethernet" ];
|
||||
networking.dns = [ "8.8.8.8" "8.8.4.4" ];
|
||||
|
||||
test = ''
|
||||
echo checking dhcp client ID is not configured in /activate >&2
|
||||
if grep -q "networksetup -setdhcp" ${config.out}/activate; then
|
||||
echo "unexpected dhcp client ID configuration in /activate" >&2
|
||||
exit 1
|
||||
fi
|
||||
'';
|
||||
}
|
||||
|
|
@ -3,11 +3,14 @@
|
|||
{
|
||||
networking.knownNetworkServices = [ "Wi-Fi" "Thunderbolt Ethernet" ];
|
||||
networking.dns = [ "8.8.8.8" "8.8.4.4" ];
|
||||
networking.dhcpClientId = "test-client-id";
|
||||
|
||||
test = ''
|
||||
echo checking dns settings in /activate >&2
|
||||
grep "networksetup -setdnsservers ${lib.escapeShellArgs [ "Wi-Fi" "8.8.8.8" "8.8.4.4" ]}" ${config.out}/activate
|
||||
grep "networksetup -setdnsservers ${lib.escapeShellArgs [ "Thunderbolt Ethernet" "8.8.8.8" "8.8.4.4" ]}" ${config.out}/activate
|
||||
grep "networksetup -setdhcp ${lib.escapeShellArgs [ "Wi-Fi" "test-client-id" ]}" ${config.out}/activate
|
||||
grep "networksetup -setdhcp ${lib.escapeShellArgs [ "Thunderbolt Ethernet" "test-client-id" ]}" ${config.out}/activate
|
||||
echo checking empty searchdomain settings in /activate >&2
|
||||
grep "networksetup -setsearchdomains ${lib.escapeShellArgs [ "Wi-Fi" "empty" ]}" ${config.out}/activate
|
||||
grep "networksetup -setsearchdomains ${lib.escapeShellArgs [ "Thunderbolt Ethernet" "empty" ]}" ${config.out}/activate
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue