forked from dan/liminix
1
0
Fork 0
liminix/examples/rotuer.nix

194 lines
4.9 KiB
Nix
Raw Permalink 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;
2023-09-24 22:29:30 +00:00
inherit (pkgs.liminix.services) oneshot longrun bundle;
2023-09-04 21:05:42 +00:00
inherit (pkgs) serviceFns;
2023-07-20 10:28:45 +00:00
svc = config.system.service;
2023-07-22 22:37:01 +00: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 11:58:51 +00:00
../modules/wlan.nix
../modules/network
../modules/ppp
2023-07-14 21:53:25 +00:00
../modules/dnsmasq
2023-09-24 22:29:30 +00:00
../modules/dhcp6c
../modules/firewall
2023-07-16 16:50:06 +00:00
../modules/hostapd
../modules/bridge
2023-07-22 22:22:45 +00:00
../modules/ntp
2023-08-10 21:53:21 +00:00
../modules/ssh
../modules/outputs/btrfs.nix
../modules/outputs/extlinux.nix
];
2023-05-20 21:34:57 +00:00
hostname = "rotuer";
rootfsType = "btrfs";
rootOptions = "subvol=@";
boot.loader.extlinux.enable = true;
2023-08-05 11:21:18 +00:00
services.hostap = svc.hostapd.build {
interface = config.hardware.networkInterfaces.wlan;
params = {
ssid = "liminix";
hw_mode="g";
channel = "2";
ieee80211n = 1;
2023-07-22 22:37:01 +00:00
} // wirelessConfig;
};
2023-08-05 11:21:18 +00:00
services.hostap5 = svc.hostapd.build {
interface = config.hardware.networkInterfaces.wlan5;
2023-03-01 22:24:58 +00: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-22 22:37:01 +00:00
} // wirelessConfig;
2023-03-01 22:24:58 +00:00
};
services.int = svc.network.address.build {
2023-09-01 16:57:22 +00:00
interface = svc.bridge.primary.build { ifname = "int"; };
family = "inet"; address ="10.8.0.1"; prefixLength = 16;
};
services.bridge = svc.bridge.members.build {
primary = services.int;
members = with config.hardware.networkInterfaces;
[ wlan
wlan5
lan ];
};
2023-03-01 22:24:58 +00:00
2023-08-05 13:16:54 +00:00
services.ntp = svc.ntp.build {
2023-07-22 22:22:45 +00:00
pools = { "pool.ntp.org" = ["iburst"]; };
makestep = { threshold = 1.0; limit = 3; };
};
2023-04-23 17:22:39 +00:00
2023-08-10 21:53:21 +00:00
services.sshd = svc.ssh.build { };
2023-05-20 21:48:30 +00: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"
2023-09-04 22:07:13 +00:00
# ra-stateless: sends router advertisements with the O and A
# bits set, and provides a stateless DHCP service. The client
# will use a SLAAC address, and use DHCP for other
# configuration information.
"::,constructor:$(output ${interface} ifname),ra-stateless"
];
2023-09-04 22:07:13 +00:00
# You can add static addresses for the DHCP server here. I'm
# not putting my actual MAC addresses in a public git repo ...
hosts = { } // lib.optionalAttrs (builtins.pathExists ./static-leases.nix) (import ./static-leases.nix);
domain = "fake.liminix.org";
};
2023-08-10 21:53:45 +00:00
services.wan = svc.pppoe.build {
2023-07-20 11:05:36 +00: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
)
'';
};
2023-09-04 21:06:15 +00:00
2023-08-28 17:23:32 +00: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-09-24 22:29:30 +00:00
ruleset = import ./demo-firewall.nix;
2023-07-16 16:04:01 +00:00
};
services.packet_forwarding = svc.network.forward.build { };
2023-09-24 22:29:30 +00:00
services.dhcp6c =
let client = svc.dhcp6c.client.build {
interface = services.wan;
};
in bundle {
name = "dhcp6c";
contents = [
(svc.dhcp6c.prefix.build {
inherit client;
interface = services.int;
})
(svc.dhcp6c.address.build {
inherit client;
interface = services.wan;
})
];
};
2023-06-20 19:13:59 +00:00
defaultProfile.packages = with pkgs; [
min-collect-garbage
];
2023-12-13 21:54:15 +00:00
programs.busybox.applets = [
"fdisk" "sfdisk"
];
}