extract extneder example to a "profile"
this is a bit of an experiment to reduce the copy-paste in examples by turning them into "application" modules. planning to follow up with another module for "wifi router"
This commit is contained in:
parent
94dbc56595
commit
9d6e50cbbc
2 changed files with 112 additions and 64 deletions
|
@ -11,10 +11,6 @@
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
secrets = import ./extneder-secrets.nix;
|
secrets = import ./extneder-secrets.nix;
|
||||||
inherit (pkgs.liminix.services) oneshot longrun bundle target;
|
|
||||||
inherit (pkgs.pseudofile) dir symlink;
|
|
||||||
inherit (pkgs) dropbear ifwait serviceFns;
|
|
||||||
svc = config.system.service;
|
|
||||||
in rec {
|
in rec {
|
||||||
boot = {
|
boot = {
|
||||||
tftp = {
|
tftp = {
|
||||||
|
@ -24,12 +20,8 @@ in rec {
|
||||||
};
|
};
|
||||||
|
|
||||||
imports = [
|
imports = [
|
||||||
../modules/wlan.nix
|
../modules/profiles/wap.nix
|
||||||
../modules/vlan
|
../modules/vlan
|
||||||
../modules/network
|
|
||||||
../modules/hostapd
|
|
||||||
../modules/bridge
|
|
||||||
../modules/ssh
|
|
||||||
];
|
];
|
||||||
|
|
||||||
hostname = "extneder";
|
hostname = "extneder";
|
||||||
|
@ -69,68 +61,24 @@ in rec {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
services.hostap = svc.hostapd.build {
|
profile.wap = {
|
||||||
interface = config.hardware.networkInterfaces.wlan;
|
interfaces = with config.hardware.networkInterfaces; [
|
||||||
params = {
|
|
||||||
country_code = "GB";
|
|
||||||
hw_mode = "g";
|
|
||||||
wmm_enabled = 1;
|
|
||||||
ieee80211n = 1;
|
|
||||||
inherit (secrets) ssid channel wpa_passphrase;
|
|
||||||
auth_algs = 1; # 1=wpa2, 2=wep, 3=both
|
|
||||||
wpa = 2; # 1=wpa, 2=wpa2, 3=both
|
|
||||||
wpa_key_mgmt = "WPA-PSK";
|
|
||||||
wpa_pairwise = "TKIP CCMP"; # auth for wpa (may not need this?)
|
|
||||||
rsn_pairwise = "CCMP"; # auth for wpa2
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
services.int = svc.bridge.primary.build {
|
|
||||||
ifname = "int";
|
|
||||||
};
|
|
||||||
|
|
||||||
services.dhcpc = svc.network.dhcp.client.build {
|
|
||||||
interface = services.int;
|
|
||||||
dependencies = [ config.services.hostname ];
|
|
||||||
};
|
|
||||||
|
|
||||||
services.bridge = svc.bridge.members.build {
|
|
||||||
primary = services.int;
|
|
||||||
members = with config.hardware.networkInterfaces; [
|
|
||||||
lan
|
lan
|
||||||
wlan
|
wlan
|
||||||
];
|
];
|
||||||
};
|
|
||||||
|
|
||||||
services.sshd = svc.ssh.build {};
|
wireless = {
|
||||||
|
networks.${secrets.ssid} = {
|
||||||
services.resolvconf = oneshot rec {
|
interface = config.hardware.networkInterfaces.wlan;
|
||||||
dependencies = [ services.dhcpc ];
|
inherit (secrets) channel wpa_passphrase;
|
||||||
name = "resolvconf";
|
country_code = "GB";
|
||||||
# CHECK: https://udhcp.busybox.net/README.udhcpc says
|
hw_mode = "g";
|
||||||
# 'A list of DNS server' but doesn't say what separates the
|
wmm_enabled = 1;
|
||||||
# list members. Assuming it's a space or other IFS character
|
ieee80211n = 1;
|
||||||
up = ''
|
};
|
||||||
. ${serviceFns}
|
|
||||||
( in_outputs ${name}
|
|
||||||
for i in $(output ${services.dhcpc} dns); do
|
|
||||||
echo "nameserver $i" > resolv.conf
|
|
||||||
done
|
|
||||||
)
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
filesystem = dir {
|
|
||||||
etc = dir {
|
|
||||||
"resolv.conf" = symlink "${services.resolvconf}/.outputs/resolv.conf";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
services.defaultroute4 = svc.network.route.build {
|
|
||||||
via = "$(output ${services.dhcpc} router)";
|
|
||||||
target = "default";
|
|
||||||
dependencies = [services.dhcpc];
|
|
||||||
};
|
|
||||||
|
|
||||||
users.root.passwd = lib.mkForce secrets.root.passwd;
|
users.root.passwd = lib.mkForce secrets.root.passwd;
|
||||||
defaultProfile.packages = with pkgs; [nftables strace tcpdump swconfig];
|
defaultProfile.packages = with pkgs; [nftables strace tcpdump swconfig];
|
||||||
}
|
}
|
||||||
|
|
100
modules/profiles/wap.nix
Normal file
100
modules/profiles/wap.nix
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
pkgs,
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
inherit (pkgs) liminix;
|
||||||
|
inherit (lib) mkEnableOption mkOption types isDerivation hasAttr ;
|
||||||
|
|
||||||
|
inherit (pkgs.liminix.services) oneshot longrun bundle target;
|
||||||
|
inherit (pkgs.pseudofile) dir symlink;
|
||||||
|
inherit (pkgs) serviceFns;
|
||||||
|
svc = config.system.service;
|
||||||
|
cfg = config.profile.wap;
|
||||||
|
|
||||||
|
hostaps =
|
||||||
|
let
|
||||||
|
defaults = {
|
||||||
|
auth_algs = 1; # 1=wpa2, 2=wep, 3=both
|
||||||
|
wpa = 2; # 1=wpa, 2=wpa2, 3=both
|
||||||
|
wpa_key_mgmt = "WPA-PSK";
|
||||||
|
wpa_pairwise = "TKIP CCMP"; # auth for wpa (may not need this?)
|
||||||
|
rsn_pairwise = "CCMP"; # auth for wpa2
|
||||||
|
};
|
||||||
|
in lib.mapAttrs'
|
||||||
|
(name : value :
|
||||||
|
let
|
||||||
|
attrs = defaults // { ssid = name; } // value;
|
||||||
|
in lib.nameValuePair
|
||||||
|
"hostap-${name}"
|
||||||
|
(svc.hostapd.build {
|
||||||
|
interface = attrs.interface;
|
||||||
|
params = lib.filterAttrs (k: v: k != "interface") attrs;
|
||||||
|
}))
|
||||||
|
cfg.wireless.networks;
|
||||||
|
|
||||||
|
in {
|
||||||
|
imports = [
|
||||||
|
../wlan.nix
|
||||||
|
../network
|
||||||
|
../hostapd
|
||||||
|
../bridge
|
||||||
|
../ssh
|
||||||
|
{ config.services = hostaps; }
|
||||||
|
];
|
||||||
|
|
||||||
|
options.profile.wap = {
|
||||||
|
interfaces = mkOption {
|
||||||
|
type = types.listOf liminix.lib.types.interface;
|
||||||
|
default = [];
|
||||||
|
};
|
||||||
|
wireless = mkOption {
|
||||||
|
type = types.attrsOf types.anything;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
config = {
|
||||||
|
services.sshd = svc.ssh.build {};
|
||||||
|
|
||||||
|
services.int = svc.bridge.primary.build {
|
||||||
|
ifname = "int";
|
||||||
|
};
|
||||||
|
|
||||||
|
services.bridge = svc.bridge.members.build {
|
||||||
|
primary = config.services.int;
|
||||||
|
members = cfg.interfaces;
|
||||||
|
};
|
||||||
|
|
||||||
|
services.dhcpc = svc.network.dhcp.client.build {
|
||||||
|
interface = config.services.int;
|
||||||
|
dependencies = [ config.services.hostname ];
|
||||||
|
};
|
||||||
|
|
||||||
|
services.defaultroute4 = svc.network.route.build {
|
||||||
|
via = "$(output ${config.services.dhcpc} router)";
|
||||||
|
target = "default";
|
||||||
|
dependencies = [config.services.dhcpc];
|
||||||
|
};
|
||||||
|
|
||||||
|
services.resolvconf = oneshot rec {
|
||||||
|
dependencies = [ config.services.dhcpc ];
|
||||||
|
name = "resolvconf";
|
||||||
|
# CHECK: https://udhcp.busybox.net/README.udhcpc says
|
||||||
|
# 'A list of DNS server' but doesn't say what separates the
|
||||||
|
# list members. Assuming it's a space or other IFS character
|
||||||
|
up = ''
|
||||||
|
. ${serviceFns}
|
||||||
|
( in_outputs ${name}
|
||||||
|
for i in $(output ${config.services.dhcpc} dns); do
|
||||||
|
echo "nameserver $i" > resolv.conf
|
||||||
|
done
|
||||||
|
)
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
filesystem = dir {
|
||||||
|
etc = dir {
|
||||||
|
"resolv.conf" = symlink "${config.services.resolvconf}/.outputs/resolv.conf";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in a new issue