liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

bordervm-configuration.nix (4971B)


      1 {
      2   config,
      3   pkgs,
      4   lib,
      5   ...
      6 }:
      7 let
      8   cfg = config.bordervm;
      9   inherit (lib)
     10     mkOption
     11     mkEnableOption
     12     mdDoc
     13     types
     14     optional
     15     optionals
     16     ;
     17 in
     18 {
     19   options.bordervm = {
     20     keys = mkOption {
     21       type = types.listOf types.str;
     22       default = [ ];
     23     };
     24     l2tp = {
     25       host = mkOption {
     26         description = mdDoc ''
     27           Hostname or IP address of an L2TP LNS that this VM
     28           will connect to when it receives a PPPoE connection request
     29         '';
     30         type = types.str;
     31         example = "l2tp.example.org";
     32       };
     33       port = mkOption {
     34         description = mdDoc ''
     35           Port number, if non-standard, of the LNS.
     36         '';
     37         type = types.int;
     38         default = 1701;
     39       };
     40     };
     41     ethernet = {
     42       pci = {
     43         enable = mkEnableOption "passthru PCI ethernet";
     44         id = mkOption {
     45           description = ''
     46             Host PCI ID (as shown by `lspci`) of the ethernet adaptor
     47             to be used by the VM. This uses VFIO and requires setup
     48             on the emulation host before it will work!
     49           '';
     50           type = types.str;
     51           example = "04:00.0";
     52         };
     53       };
     54       usb = {
     55         enable = mkEnableOption "passthru USB ethernet";
     56         vendor = mkOption {
     57           type = types.str;
     58           example = "0x0bda";
     59         };
     60         product = mkOption {
     61           type = types.str;
     62           example = "0x8153";
     63         };
     64       };
     65     };
     66   };
     67   imports = [
     68     <nixpkgs/nixos/modules/virtualisation/qemu-vm.nix>
     69   ];
     70   config = {
     71     boot.kernelParams = [ "loglevel=9" ];
     72     systemd.services.pppoe =
     73       let
     74         conf = pkgs.writeText "kpppoed.toml" ''
     75           interface_name = "eth1"
     76           services = [ "myservice" ]
     77           lns_ipaddr = "${cfg.l2tp.host}:${builtins.toString cfg.l2tp.port}"
     78           ac_name = "kpppoed-1.0"
     79         '';
     80       in
     81       {
     82         wantedBy = [ "multi-user.target" ];
     83         after = [ "network-online.target" ];
     84         serviceConfig = {
     85           ExecStart = "${pkgs.go-l2tp}/bin/kpppoed -config ${conf}";
     86         };
     87       };
     88     systemd.services.tufted = {
     89       wantedBy = [ "multi-user.target" ];
     90       serviceConfig = {
     91         ExecStart = "${pkgs.tufted}/bin/tufted /home/liminix/liminix";
     92       };
     93     };
     94     services.openssh.enable = true;
     95     services.dnsmasq = {
     96       enable = true;
     97       resolveLocalQueries = false;
     98       settings = {
     99         # domain-needed = true;
    100         dhcp-range = [ "10.0.0.10,10.0.0.240" ];
    101         interface = "eth1";
    102       };
    103     };
    104 
    105     services.nginx = {
    106       enable = true;
    107       user = "liminix";
    108       virtualHosts.${config.networking.hostName} = {
    109         root = "/home/liminix";
    110         default = true;
    111       };
    112     };
    113     systemd.services.nginx.serviceConfig.ProtectHome = "read-only";
    114 
    115     systemd.services.sshd.wantedBy = pkgs.lib.mkForce [ "multi-user.target" ];
    116 
    117     virtualisation = {
    118       forwardPorts = [
    119         {
    120           from = "host";
    121           host.port = 7654;
    122           #        guest.address = "10.0.2.15";
    123           guest.port = 7654;
    124         }
    125         {
    126           host.port = 2222;
    127           guest.address = "10.0.2.15";
    128           guest.port = 22;
    129         }
    130       ];
    131       qemu = {
    132         networkingOptions = [ ];
    133         options =
    134           [ ]
    135           ++ optional cfg.ethernet.pci.enable "-device vfio-pci,host=${cfg.ethernet.pci.id}"
    136           ++ optionals cfg.ethernet.usb.enable [
    137             "-device usb-ehci,id=ehci"
    138             "-device usb-host,bus=ehci.0,vendorid=${cfg.ethernet.usb.vendor},productid=${cfg.ethernet.usb.product}"
    139           ]
    140           ++ [
    141             "-nographic"
    142             "-serial mon:stdio"
    143           ];
    144       };
    145       sharedDirectories = {
    146         liminix = {
    147           securityModel = "none";
    148           source = builtins.toString ./.;
    149           target = "/home/liminix/liminix";
    150         };
    151       };
    152     };
    153 
    154     services.tang = {
    155       enable = true;
    156       ipAddressAllow = [
    157         "10.0.0.0/24"
    158         "0.0.0.0/0"
    159       ];
    160     };
    161 
    162     environment.systemPackages =
    163       let
    164         wireshark-nogui = pkgs.wireshark.override { withQt = false; };
    165       in
    166       with pkgs;
    167       [
    168         tcpdump
    169         wireshark-nogui
    170         socat
    171         tufted
    172         iptables
    173         usbutils
    174         busybox
    175         clevis
    176       ];
    177     security.sudo.wheelNeedsPassword = false;
    178     networking = {
    179       hostName = "border";
    180       firewall = {
    181         enable = false;
    182       };
    183       interfaces.eth1 = {
    184         useDHCP = false;
    185         ipv4.addresses = [
    186           {
    187             address = "10.0.0.1";
    188             prefixLength = 24;
    189           }
    190         ];
    191       };
    192       nat = {
    193         enable = true;
    194         internalInterfaces = [ "eth1" ];
    195         externalInterface = "eth0";
    196       };
    197     };
    198     users.users.liminix = {
    199       isNormalUser = true;
    200       uid = 1000;
    201       extraGroups = [ "wheel" ];
    202       openssh.authorizedKeys.keys = cfg.keys;
    203     };
    204     services.getty.autologinUser = "liminix";
    205   };
    206 }