Add wireless options

This commit is contained in:
Ehmry - 2022-06-23 17:27:14 -05:00
parent 2999346274
commit a4cd619f69
5 changed files with 73 additions and 38 deletions

View File

@ -47,18 +47,12 @@ let
services.disabled = [ "dnsmasq" ];
# include files in the images.
# to set UCI configuration, create a uci-defauts scripts as per
# official OpenWRT ImageBuilder recommendation.
files = pkgs.runCommandNoCC "image-files" { } ''
mkdir -p $out/etc/uci-defaults
cat > $out/etc/uci-defaults/99-custom <<EOF
uci -q batch << EOI
set system.@system[0].hostname='testap'
commit
EOI
EOF
'';
wireless.interfaces.ap0 = {
device = "radio0";
network = "lan";
mode = "ap";
ssid = "Test AP";
};
})
];
@ -94,18 +88,12 @@ in sys.config.system.build.image
services.disabled = [ "dnsmasq" ];
# include files in the images.
# to set UCI configuration, create a uci-defauts scripts as per
# official OpenWRT ImageBuilder recommendation.
files = pkgs.runCommandNoCC "image-files" { } ''
mkdir -p $out/etc/uci-defaults
cat > $out/etc/uci-defaults/99-custom <<EOF
uci -q batch << EOI
set system.@system[0].hostname='testap'
commit
EOI
EOF
'';
wireless.interfaces.ap0 = {
device = "radio0";
network = "lan";
mode = "ap";
ssid = "Test AP";
};
})
];

View File

@ -4,24 +4,19 @@
build.profile = "avm_fritz7412";
system.settings = {
hostname = "testap";
description = "nix-openwrt-imagebuilder example";
timezone = "CET-1CEST,M3.5.0,M10.5.0/3";
};
packages.include = [ "tcpdump" "vxlan" "kmod-vxlan" ];
dropbear.settings = {
PasswordAuth = false;
dropbear.settings = { PasswordAuth = false; };
wireless.interfaces.ap0 = {
device = "radio0";
network = "lan";
mode = "ap";
ssid = "Test AP";
};
files = pkgs.runCommandNoCC "image-files" { } ''
mkdir -p $out/etc/uci-defaults
cat > $out/etc/uci-defaults/99-custom <<EOF
uci -q batch << EOI
set system.@system[0].hostname='testap'
commit
EOI
EOF
'';
}

View File

@ -4,7 +4,7 @@
options = with lib; {
files = mkOption {
type = types.path;
type = with types; nullOr path;
default = null;
example = literalExample ''
pkgs.runCommandNoCC "image-files" { } '''

51
lib/modules/wireless.nix Normal file
View File

@ -0,0 +1,51 @@
{ config, lib, ... }:
let cfg = config.wireless;
in {
options.wireless = with lib; {
devices = mkOption {
default = { };
description = ''
See <link xlink:href="https://openwrt.org/docs/guide-user/network/wifi/basic#wi-fi_devices"/>
'';
type = with types; attrsOf uciSection;
example = {
wl0 = {
type = "broadcom";
channel = 6;
};
};
};
interfaces = mkOption {
default = { };
description = ''
See <link xlink:href="https://openwrt.org/docs/guide-user/network/wifi/basic#wi-fi_interfaces"/>
'';
type = with types; attrsOf uciSection;
example = {
ap0 = {
device = "wl0";
network = "lan";
mode = "ap";
ssid = "MyWifiAP";
encryption = "psk2";
key = "secret passphrase";
};
};
};
};
config.uci.batch = let
toUci' = type:
(lib.attrsets.mapAttrsToList (section: settings:
lib.toUciBatch {
config = "wireless";
inherit section type;
} settings));
in lib.strings.concatStringsSep "\n"
((toUci' "wifi-device" cfg.devices) ++ (toUci' "wifi-iface" cfg.interfaces));
}

View File

@ -20,6 +20,7 @@ let
./modules/services.nix
./modules/system.nix
./modules/uci.nix
./modules/wireless.nix
] ++ modules;
};
in { inherit (result) config options; }