From 688d658a9689194787f6df15b83daad7e78f20bc Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Wed, 25 Jan 2023 10:19:20 +0100 Subject: [PATCH 1/3] nixos/wireless: fix failure on missing config file This change prevents doing the secret substitution when the config is missing, which would result in an error. The service can be useful even without configuration; for example connman controls wpa_supplicant using dbus and as such it does not need a config file nor any other declarative options. --- .../modules/services/networking/wpa_supplicant.nix | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/nixos/modules/services/networking/wpa_supplicant.nix b/nixos/modules/services/networking/wpa_supplicant.nix index 119575bdddb4..0595e9e6df23 100644 --- a/nixos/modules/services/networking/wpa_supplicant.nix +++ b/nixos/modules/services/networking/wpa_supplicant.nix @@ -121,11 +121,15 @@ let ''} # substitute environment variables - ${pkgs.gawk}/bin/awk '{ - for(varname in ENVIRON) - gsub("@"varname"@", ENVIRON[varname]) - print - }' "${configFile}" > "${finalConfig}" + if [ -f "${configFile}" ]; then + ${pkgs.gawk}/bin/awk '{ + for(varname in ENVIRON) + gsub("@"varname"@", ENVIRON[varname]) + print + }' "${configFile}" > "${finalConfig}" + else + touch "${finalConfig}" + fi iface_args="-s ${optionalString cfg.dbusControlled "-u"} -D${cfg.driver} ${configStr}" From fc211deccf85739831181adf5b74be1ca811c653 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Thu, 26 Jan 2023 00:22:21 +0100 Subject: [PATCH 2/3] nixos/tests/connman: init --- nixos/tests/all-tests.nix | 1 + nixos/tests/connman.nix | 77 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 nixos/tests/connman.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 9bf85cd0b97d..9cfdcc3d5ca0 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -134,6 +134,7 @@ in { cntr = handleTestOn ["aarch64-linux" "x86_64-linux"] ./cntr.nix {}; cockroachdb = handleTestOn ["x86_64-linux"] ./cockroachdb.nix {}; collectd = handleTest ./collectd.nix {}; + connman = handleTest ./connman.nix {}; consul = handleTest ./consul.nix {}; containers-bridge = handleTest ./containers-bridge.nix {}; containers-custom-pkgs.nix = handleTest ./containers-custom-pkgs.nix {}; diff --git a/nixos/tests/connman.nix b/nixos/tests/connman.nix new file mode 100644 index 000000000000..348b2a895a63 --- /dev/null +++ b/nixos/tests/connman.nix @@ -0,0 +1,77 @@ +import ./make-test-python.nix ({ pkgs, lib, ...}: +{ + name = "connman"; + meta = with lib.maintainers; { + maintainers = [ rnhmjoj ]; + }; + + # Router running radvd on VLAN 1 + nodes.router = { ... }: { + imports = [ ../modules/profiles/minimal.nix ]; + + virtualisation.vlans = [ 1 ]; + + boot.kernel.sysctl."net.ipv6.conf.all.forwarding" = true; + + networking = { + useDHCP = false; + interfaces.eth1.ipv6.addresses = + [ { address = "fd12::1"; prefixLength = 64; } ]; + }; + + services.radvd = { + enable = true; + config = '' + interface eth1 { + AdvSendAdvert on; + AdvManagedFlag on; + AdvOtherConfigFlag on; + prefix fd12::/64 { + AdvAutonomous off; + }; + }; + ''; + }; + }; + + # Client running connman, connected to VLAN 1 + nodes.client = { ... }: { + virtualisation.vlans = [ 1 ]; + + # add a virtual wlan interface + boot.kernelModules = [ "mac80211_hwsim" ]; + boot.extraModprobeConfig = '' + options mac80211_hwsim radios=1 + ''; + + # Note: the overrides are needed because the wifi is + # disabled with mkVMOverride in qemu-vm.nix. + services.connman.enable = lib.mkOverride 0 true; + services.connman.networkInterfaceBlacklist = [ "eth0" ]; + networking.wireless.enable = lib.mkOverride 0 true; + networking.wireless.interfaces = [ "wlan0" ]; + }; + + testScript = + '' + start_all() + + with subtest("Router is ready"): + router.wait_for_unit("radvd.service") + + with subtest("Daemons are running"): + client.wait_for_unit("wpa_supplicant-wlan0.service") + client.wait_for_unit("connman.service") + client.wait_until_succeeds("connmanctl state | grep -q ready") + + with subtest("Wired interface is configured"): + client.wait_until_succeeds("ip -6 route | grep -q fd12::/64") + client.wait_until_succeeds("ping -c 1 fd12::1") + + with subtest("Can set up a wireless access point"): + client.succeed("connmanctl enable wifi") + client.wait_until_succeeds("connmanctl tether wifi on nixos-test reproducibility | grep -q 'Enabled'") + client.wait_until_succeeds("iw wlan0 info | grep -q nixos-test") + ''; +}) + From fed3e4cc87ac65e2a2cf4231ccec937e5edc8d8c Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Thu, 26 Jan 2023 00:42:13 +0100 Subject: [PATCH 3/3] connman: add NixOS tests to passthru --- pkgs/tools/networking/connman/connman/default.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkgs/tools/networking/connman/connman/default.nix b/pkgs/tools/networking/connman/connman/default.nix index bfe609f85268..da1a6107e463 100644 --- a/pkgs/tools/networking/connman/connman/default.nix +++ b/pkgs/tools/networking/connman/connman/default.nix @@ -1,4 +1,6 @@ -{ lib, stdenv +{ lib +, nixosTests +, stdenv , fetchurl , fetchpatch , pkg-config @@ -170,6 +172,8 @@ stdenv.mkDerivation rec { doCheck = true; + passthru.tests.connman = nixosTests.connman; + meta = with lib; { description = "A daemon for managing internet connections"; homepage = "https://git.kernel.org/pub/scm/network/connman/connman.git/";