nixos-config/profiles/virtualisation.nix

89 lines
2.4 KiB
Nix
Raw Normal View History

2021-10-24 23:15:08 +03:00
{ config, lib, pkgs, ... }:
with config.deviceSpecific; {
2022-02-01 05:17:22 +03:00
config = lib.mkIf enableVirtualisation {
virtualisation.docker = {
2022-09-23 21:26:59 +03:00
enable = true;
2022-10-21 13:57:17 +03:00
daemon.settings = {
features = { buildkit = true; };
};
2022-10-08 04:32:18 +03:00
storageDriver = if (devInfo.fileSystem == "zfs") then
"zfs"
else if (devInfo.fileSystem == "btrfs") then
"btrfs"
else
"overlay2";
2022-02-01 05:17:22 +03:00
};
2023-01-26 00:23:55 +03:00
virtualisation.oci-containers.backend = "podman";
virtualisation.podman = {
enable = true;
extraPackages = [ pkgs.zfs ];
2023-01-26 00:36:27 +03:00
defaultNetwork.settings.dns_enabled = true;
2023-01-26 00:23:55 +03:00
};
virtualisation.containers.registries.search = [
"docker.io" "gcr.io" "quay.io"
];
virtualisation.containers.storage.settings =
lib.mkIf (devInfo.fileSystem == "zfs") {
storage = {
driver = "zfs";
graphroot = "/var/lib/containers/storage";
runroot = "/run/containers/storage";
};
};
2021-02-07 02:38:11 +03:00
2022-02-01 05:17:22 +03:00
virtualisation.libvirtd = {
2022-12-07 22:05:00 +03:00
enable = true;
2022-02-01 05:17:22 +03:00
qemu = {
2022-12-07 22:05:00 +03:00
ovmf.enable = true;
ovmf.packages = [ pkgs.OVMFFull.fd ];
runAsRoot = false;
2022-02-01 05:17:22 +03:00
};
onBoot = "ignore";
onShutdown = "shutdown";
2021-10-27 15:19:41 +03:00
};
2021-02-07 02:38:11 +03:00
2022-12-10 22:34:39 +03:00
home-manager.users.${config.mainuser} = {
2022-12-07 22:05:00 +03:00
home.file.".config/libvirt/libvirt.conf".text = ''
uri_default = "qemu:///system"
'';
home.packages = with pkgs; [
docker-compose
virt-manager
];
};
virtualisation.lxd = lib.mkIf (!isContainer) {
enable = true;
2023-01-26 02:12:00 +03:00
zfsSupport = devInfo.fileSystem == "zfs";
2022-10-08 04:32:18 +03:00
recommendedSysctlSettings = true;
};
2022-12-07 22:05:00 +03:00
virtualisation.lxc = lib.mkIf (!isContainer) {
enable = true;
lxcfs.enable = true;
2022-10-08 04:32:18 +03:00
systemConfig = ''
lxc.lxcpath = /var/lib/lxd/containers
${if devInfo.fileSystem == "zfs" then ''
2022-12-14 23:46:25 +03:00
lxc.bdev.zfs.root = rpool/nixos/lxd
2022-10-08 04:32:18 +03:00
'' else ""}
'';
defaultConfig = ''
lxc.idmap = u 0 100000 65535
lxc.idmap = g 0 100000 65535
lxc.include = ${pkgs.lxcfs}/share/lxc/config/common.conf.d/00-lxcfs.conf
'';
};
2022-02-01 05:17:22 +03:00
virtualisation.spiceUSBRedirection.enable = true;
networking.nat = {
enable = true;
internalInterfaces = [ "ve-+" ];
2022-12-07 22:05:00 +03:00
# externalInterface = "enp8s0";
2022-02-01 05:17:22 +03:00
};
2022-12-14 23:46:25 +03:00
persist.state.directories = lib.mkIf devInfo.fileSystem != "zfs" [
"/var/lib/docker"
"/var/lib/libvirt"
];
2021-09-15 18:37:21 +03:00
};
2021-02-07 02:38:11 +03:00
}