Closed teto closed 5 years ago
what about the multihoming issue ? it seems to work fine with the nixos/tests infrastructure. There seems to be some related code (to vlans) in nixos/lib/testing.nix but it doesn't seem called in nixos-shell
I managed to come up in my vm.nix with sthg like
let
vlans = [ 1 2];
zeroPad = n: if n < 10 then "0${toString n}" else toString n;
# see https://wiki.qemu.org/Documentation/Networking 's doc
qemuNICFlags = nic: net: machine:
[ "-device virtio-net-pci,netdev=vlan${toString nic},mac=52:54:00:12:${zeroPad net}:${zeroPad machine}"
"-netdev user,id=vlan${toString nic}"
];
in
{
virtualisation.qemu.options = with pkgs.lib; let
m = {snd = 1;};
interfacesNumbered = zipLists vlans (range 1 255);
interfaces = flip map interfacesNumbered ({ fst, snd }:
nameValuePair "eth${toString snd}" { ipv4.addresses =
[ { address = "192.168.${toString fst}.${toString m.snd}";
prefixLength = 24;
} ];
});
in
flip map interfacesNumbered
({ fst, snd }: qemuNICFlags snd fst m.snd);
}
actually the doc of virtualisation.qemu.vlans is a bit misleading as it will work only with extra code (as in nixos tests). Also I wanted to run my own kernel but qemu-vm hardcodes it. Hopefully qemu uses the last parameter set on the command line so I can still override the nixpkgs one. I might have a look at improving qemu-vm.nix. The pasted code uses SLIRP which seems to be bad for perf. maybe nixos-shell could run some VDE logic as the nixos tests. Anyway that should be good for now on my side.
I was pondering between using this and keep using nixops but this seems leaner (my nixops is full of libvirt hacks) and I also like that the host store can be accessed.
I am trying to create a multihomed vm.nix by adding
virtualisation.vlans = [ 2 1 3 4 ];
in my vm.nix but I still see only one eth0 in the vm.I installed nixos-shell via nix-env and the name is not very inspiring so here is patch changing the name and removing some trailing whitespace if you want.