liminix-fork/bordervm-configuration.nix

106 lines
2.7 KiB
Nix
Raw Normal View History

2023-02-17 17:28:50 +01:00
{ config, pkgs, lib, ... }:
let
cfg = config.bordervm;
inherit (lib) mkOption mdDoc types;
in {
options.bordervm = {
l2tp = {
host = mkOption {
description = mdDoc ''
Hostname or IP address of an L2TP LNS that this VM
will connect to when it receives a PPPoE connection request
'';
type = types.str;
example = "l2tp.example.org";
};
port = mkOption {
description = mdDoc ''
Port number, if non-standard, of the LNS.
'';
type = types.int;
default = 1701;
};
};
ethernet = {
pciId = mkOption {
description = ''
Host PCI ID (as shown by `lspci`) of the ethernet adaptor
to be used by the VM. This uses VFIO and requires setup
on the emulation host before it will work!
'';
type = types.str;
example = "04:00.0";
};
};
};
imports = [
<nixpkgs/nixos/modules/virtualisation/qemu-vm.nix>
];
2023-02-17 17:28:50 +01:00
config = {
boot.kernelParams = [
"loglevel=9"
];
systemd.services.pppoe =
let conf = pkgs.writeText "kpppoed.toml"
''
interface_name = "eth1"
services = [ "myservice" ]
2023-02-17 17:28:50 +01:00
lns_ipaddr = "${cfg.l2tp.host}:${builtins.toString cfg.l2tp.port}"
ac_name = "kpppoed-1.0"
'';
2023-02-17 17:28:50 +01:00
in {
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
serviceConfig = {
ExecStart = "${pkgs.go-l2tp}/bin/kpppoed -config ${conf}";
};
};
systemd.services.tufted = {
wantedBy = [ "multi-user.target" ];
serviceConfig = {
2023-02-17 17:28:50 +01:00
ExecStart = "${pkgs.tufted}/bin/tufted /home/liminix/liminix";
};
};
2023-02-17 17:28:50 +01:00
systemd.services.sshd.wantedBy = pkgs.lib.mkForce [ "multi-user.target" ];
2023-02-17 17:28:50 +01:00
virtualisation = {
qemu = {
networkingOptions = [];
options = [
"-device vfio-pci,host=${cfg.ethernet.pciId}"
"-nographic"
"-serial mon:stdio"
];
};
sharedDirectories = {
liminix = {
source = builtins.toString ./.;
target = "/home/liminix/liminix";
};
};
};
2023-02-17 17:28:50 +01:00
environment.systemPackages = with pkgs; [
tcpdump
wireshark
socat
tufted
iptables
];
security.sudo.wheelNeedsPassword = false;
networking = {
hostName = "border";
firewall = { enable = false; };
interfaces.eth1 = {
useDHCP = false;
ipv4.addresses = [ { address = "10.0.0.1"; prefixLength = 24;}];
};
};
2023-02-17 17:28:50 +01:00
users.users.liminix = {
isNormalUser = true;
uid = 1000;
extraGroups = [ "wheel"];
};
2023-02-17 17:28:50 +01:00
services.getty.autologinUser = "liminix";
};
}