From 85334b9cfe379d93f01ab334d434ae704e84cfa4 Mon Sep 17 00:00:00 2001 From: Benedikt Ritter Date: Sun, 27 Oct 2024 14:31:32 +0100 Subject: [PATCH 1/3] networking: Add default value for DHCP Replicates the behavior of nixos-generate-config which is to configure `useDCHP` to default to true if there are more than 0 network interfaces. See https://github.com/NixOS/nixpkgs/blob/f59db697ef71a9cbebd11cc81d87d184866382ff/nixos/modules/installer/tools/nixos-generate-config.pl#L608 --- modules/nixos/networking/default.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/nixos/networking/default.nix b/modules/nixos/networking/default.nix index 57ba9ea..ecc8792 100644 --- a/modules/nixos/networking/default.nix +++ b/modules/nixos/networking/default.nix @@ -1,6 +1,10 @@ +{ config, lib, ... }: { imports = [ ./broadcom.nix ./intel.nix ]; + config.networking = lib.mkIf (builtins.length (config.facter.report.network_interface or [ ]) > 0) { + useDHCP = lib.mkDefault true; + }; } From b4beb32149a16d15220e307ca4c9d7ff4eddc3ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Mon, 4 Nov 2024 14:18:19 +0100 Subject: [PATCH 2/3] networking: use networkd otherwise we would need to add each interface individually, which is quite difficult without stable interface names. So let's use networkd, which is overall the better solution anyway. --- modules/nixos/networking/default.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/nixos/networking/default.nix b/modules/nixos/networking/default.nix index ecc8792..0af40f8 100644 --- a/modules/nixos/networking/default.nix +++ b/modules/nixos/networking/default.nix @@ -4,7 +4,8 @@ ./broadcom.nix ./intel.nix ]; - config.networking = lib.mkIf (builtins.length (config.facter.report.network_interface or [ ]) > 0) { - useDHCP = lib.mkDefault true; + config = lib.mkIf (builtins.length (config.facter.report.network_interface or [ ]) > 0) { + networking.useDHCP = lib.mkDefault true; + networking.useNetworkd = lib.mkDefault true; }; } From 84e8b2aaf07dded73c0b59af3e61b496231c7b57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Mon, 4 Nov 2024 14:21:03 +0100 Subject: [PATCH 3/3] add facter.dhcp.enable option --- modules/nixos/networking/default.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/nixos/networking/default.nix b/modules/nixos/networking/default.nix index 0af40f8..e80408b 100644 --- a/modules/nixos/networking/default.nix +++ b/modules/nixos/networking/default.nix @@ -4,7 +4,11 @@ ./broadcom.nix ./intel.nix ]; - config = lib.mkIf (builtins.length (config.facter.report.network_interface or [ ]) > 0) { + + options.facter.detected.dhcp.enable = lib.mkEnableOption "Facter dhcp module" // { + default = builtins.length config.facter.report.network_interface or [ ] > 0; + }; + config = lib.mkIf config.facter.detected.dhcp.enable { networking.useDHCP = lib.mkDefault true; networking.useNetworkd = lib.mkDefault true; };