liminix-fork/examples/rotuer.nix

195 lines
5 KiB
Nix
Raw Normal View History

# This is not part of Liminix per se. This is my "scratchpad"
# configuration for the device I'm testing with.
#
# Parts of it do do things that Liminix eventually needs to do, but
# don't look in here for solutions - just for identifying the
# problems.
{ config, pkgs, lib, ... } :
let
secrets = import ./rotuer-secrets.nix;
inherit (pkgs.liminix.services) oneshot longrun bundle target;
inherit (pkgs)
dropbear
ifwait
2023-04-23 19:22:39 +02:00
writeText
writeFennelScript
2023-03-03 21:07:39 +01:00
serviceFns;
2023-07-20 12:28:45 +02:00
svc = config.system.service;
2023-07-23 00:37:01 +02:00
wirelessConfig = {
country_code = "GB";
inherit (secrets) 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
wmm_enabled = 1;
};
in rec {
boot = {
tftp = {
freeSpaceBytes = 3 * 1024 * 1024;
serverip = "10.0.0.1";
ipaddr = "10.0.0.8";
};
};
imports = [
2023-04-23 13:58:51 +02:00
../modules/wlan.nix
../modules/standard.nix
../modules/network
../modules/ppp
2023-07-14 23:53:25 +02:00
../modules/dnsmasq
../modules/firewall
2023-07-16 18:50:06 +02:00
../modules/hostapd
../modules/bridge
2023-07-23 00:22:45 +02:00
../modules/ntp
2023-08-10 23:53:21 +02:00
../modules/ssh
];
2023-04-23 13:58:51 +02:00
rootfsType = "jffs2";
2023-05-20 23:34:57 +02:00
hostname = "rotuer";
2023-08-05 13:21:18 +02:00
services.hostap = svc.hostapd.build {
2023-07-16 18:50:06 +02:00
interface = config.hardware.networkInterfaces.wlan_24;
params = {
ssid = "liminix";
hw_mode="g";
channel = "2";
ieee80211n = 1;
2023-07-23 00:37:01 +02:00
} // wirelessConfig;
};
2023-08-05 13:21:18 +02:00
services.hostap5 = svc.hostapd.build {
2023-07-16 18:50:06 +02:00
interface = config.hardware.networkInterfaces.wlan_5;
2023-03-01 23:24:58 +01:00
params = rec {
ssid = "liminix_5";
hw_mode="a";
channel = 36;
ht_capab = "[HT40+]";
vht_oper_chwidth = 1;
vht_oper_centr_freq_seg0_idx = channel + 6;
ieee80211ac = 1;
2023-07-23 00:37:01 +02:00
} // wirelessConfig;
2023-03-01 23:24:58 +01:00
};
services.int = svc.network.address.build {
interface = svc.bridge.primary.build { ifname = "int"; };# services.int;
family = "inet"; address ="10.8.0.1"; prefixLength = 16;
};
services.bridge = svc.bridge.members.build {
primary = services.int;
members = with config.hardware.networkInterfaces;
2023-08-28 19:24:14 +02:00
[ wlan_24 wlan_5 lan ];
};
2023-03-01 23:24:58 +01:00
2023-08-05 15:16:54 +02:00
services.ntp = svc.ntp.build {
2023-07-23 00:22:45 +02:00
pools = { "pool.ntp.org" = ["iburst"]; };
makestep = { threshold = 1.0; limit = 3; };
};
2023-04-23 19:22:39 +02:00
2023-08-10 23:53:21 +02:00
services.sshd = svc.ssh.build { };
2023-05-20 23:48:30 +02:00
users.root = secrets.root;
services.dns =
let interface = services.int;
in svc.dnsmasq.build {
resolvconf = services.resolvconf;
inherit interface;
ranges = [
"10.8.0.10,10.8.0.240"
"::,constructor:$(output ${interface} ifname),ra-stateless"
];
domain = "fake.liminix.org";
};
2023-08-10 23:53:45 +02:00
services.wan = svc.pppoe.build {
2023-07-20 13:05:36 +02:00
interface = config.hardware.networkInterfaces.wan;
ppp-options = [
"debug" "+ipv6" "noauth"
"name" secrets.l2tp.name
"password" secrets.l2tp.password
];
};
services.resolvconf = oneshot rec {
dependencies = [ services.wan ];
name = "resolvconf";
up = ''
. ${serviceFns}
( in_outputs ${name}
echo "nameserver $(output ${services.wan} ns1)" > resolv.conf
echo "nameserver $(output ${services.wan} ns2)" >> resolv.conf
chmod 0444 resolv.conf
)
'';
down = ''
rm -rf /run/service-state/${name}/
'';
};
2023-08-28 19:23:32 +02:00
filesystem =
let inherit (pkgs.pseudofile) dir symlink;
in dir {
etc = dir {
"resolv.conf" = symlink "${services.resolvconf}/.outputs/resolv.conf";
};
};
services.defaultroute4 = svc.network.route.build {
via = "$(output ${services.wan} address)";
target = "default";
dependencies = [ services.wan ];
};
services.defaultroute6 = svc.network.route.build {
via = "$(output ${services.wan} ipv6-peer-address)";
target = "default";
interface = services.wan;
};
services.firewall = svc.firewall.build {
2023-07-16 18:04:01 +02:00
ruleset = import ./rotuer-firewall.nix;
};
services.packet_forwarding = svc.network.forward.build { };
services.dhcp6 =
let
name = "dhcp6c.wan";
in longrun {
inherit name;
2023-05-26 19:36:44 +02:00
notification-fd = 10;
run = ''
export SERVICE_STATE=/run/service-state/${name}
2023-06-30 21:02:03 +02:00
${pkgs.odhcp6c}/bin/odhcp6c -s ${pkgs.odhcp-script} -e -v -p /run/${name}.pid -P 48 $(output ${services.wan} ifname)
)
'';
dependencies = [ services.wan ];
};
services.acquire-lan-prefix =
let script = pkgs.callPackage ./acquire-delegated-prefix.nix { };
in longrun {
name = "acquire-lan-prefix";
run = "${script} /run/service-state/dhcp6c.wan $(output ${services.int} ifname)";
dependencies = [ services.dhcp6 ];
};
services.acquire-wan-address =
let script = pkgs.callPackage ./acquire-wan-address.nix { };
in longrun {
name = "acquire-wan-address";
run = "${script} /run/service-state/dhcp6c.wan $(output ${services.wan} ifname)";
dependencies = [ services.dhcp6 ];
};
2023-06-20 21:13:59 +02:00
defaultProfile.packages = with pkgs; [
min-collect-garbage
];
}