System/modules/linux/virtualization.nix

41 lines
1.1 KiB
Nix
Raw Normal View History

2022-06-23 02:57:41 -04:00
{ config, lib, pkgs, ... }:
let nc = config.nathan.config;
in with lib; {
2022-07-02 02:44:43 -04:00
config = mkMerge [
(mkIf nc.virtualization.qemu {
# Enable the kernel modules
boot.kernelModules = [ "kvm-amd" "kvm-intel" ];
# Enable libvirt
virtualisation.libvirtd.enable = true;
# Install virt-manager
environment.systemPackages = with pkgs; [ virtmanager ];
})
2022-07-02 02:44:43 -04:00
(mkIf nc.virtualization.docker {
2022-06-23 02:57:41 -04:00
# Enable docker
virtualisation.docker = {
enable = true;
# Automatically prune to keep things lean
autoPrune.enable = true;
};
2022-09-05 20:52:22 -04:00
# Make sure our containers can reach the network
boot.kernel.sysctl."net.ipv4.ip_forward" = true;
2022-07-02 02:44:43 -04:00
})
(mkIf nc.virtualization.lxc {
2022-06-23 02:57:41 -04:00
virtualisation.lxd = {
enable = true;
recommendedSysctlSettings = true;
};
users.users.${nc.user} = mkIf nc.installUser { extraGroups = [ "lxd" ]; };
2022-07-02 02:44:43 -04:00
})
(mkIf nc.virtualization.nixos {
2022-06-23 02:57:41 -04:00
# Setup networking for nixos containers
networking = {
nat = {
enable = true;
internalInterfaces = [ "ve-+" ];
};
};
2022-07-02 02:44:43 -04:00
})
];
2022-06-23 02:57:41 -04:00
}