nixos-config/profiles/virtualisation.nix

82 lines
2.1 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 {
2023-03-26 19:24:28 +03:00
virtualisation = {
oci-containers.backend = lib.mkForce "podman";
docker = {
enable = true;
daemon.settings = {
features = { buildkit = true; };
};
storageDriver = "overlay2";
2022-10-21 13:57:17 +03:00
};
2023-03-26 19:24:28 +03:00
podman = {
enable = true;
defaultNetwork.settings.dns_enabled = true;
2024-06-30 13:52:30 +03:00
dockerSocket.enable = !config.virtualisation.docker.enable;
2023-01-26 00:23:55 +03:00
};
2023-03-26 19:24:28 +03:00
containers.registries.search = [
2025-02-16 22:19:42 +03:00
"docker.io" "ghcr.io" "quay.io"
2023-03-26 19:24:28 +03:00
];
containers.storage.settings = {
storage = {
2024-06-29 10:48:20 +03:00
driver = "overlay";
2023-03-26 19:24:28 +03:00
graphroot = "/var/lib/containers/storage";
runroot = "/run/containers/storage";
};
};
libvirtd = {
enable = true;
qemu = {
ovmf.enable = true;
ovmf.packages = [
2023-04-08 17:58:22 +03:00
(pkgs.OVMFFull.override {
secureBoot = true;
tpmSupport = true;
}).fd
2023-03-26 19:24:28 +03:00
];
runAsRoot = false;
2023-04-08 17:58:22 +03:00
swtpm.enable = true;
2023-03-26 19:24:28 +03:00
};
onBoot = "ignore";
onShutdown = "shutdown";
};
2024-06-29 10:48:20 +03:00
spiceUSBRedirection.enable = !isServer;
2021-10-27 15:19:41 +03:00
};
2021-02-07 02:38:11 +03:00
2023-05-24 21:29:27 +03:00
environment.systemPackages = [ pkgs.virtiofsd ];
2023-04-08 17:58:22 +03:00
users.users."qemu-libvirtd" = {
extraGroups =
lib.optionals (!config.virtualisation.libvirtd.qemu.runAsRoot)
[ "kvm" "input" ];
};
2023-03-26 19:24:28 +03:00
security.unprivilegedUsernsClone = true;
2022-12-10 22:34:39 +03:00
home-manager.users.${config.mainuser} = {
2023-03-26 19:24:28 +03:00
home.file.".config/containers/storage.conf".text = ''
[storage]
2023-10-01 23:45:11 +03:00
driver = "overlay"
2023-03-26 19:24:28 +03:00
'';
2023-04-08 17:58:22 +03:00
home.file.".config/libvirt/libvirt.conf".text = ''
uri_default = "qemu:///system"
'';
2022-10-08 04:32:18 +03:00
};
2024-06-29 10:48:20 +03:00
programs.extra-container.enable = !isServer;
programs.virt-manager.enable = !isServer;
2022-12-14 23:46:25 +03:00
2023-03-27 16:00:57 +03:00
persist.state.homeDirectories = [
".config/containers"
];
2023-03-26 19:24:28 +03:00
persist.state.directories = lib.mkIf (devInfo.fileSystem != "zfs") [
2022-12-14 23:46:25 +03:00
"/var/lib/docker"
"/var/lib/libvirt"
2023-03-26 19:24:28 +03:00
"/var/lib/containers"
2022-12-14 23:46:25 +03:00
];
2021-09-15 18:37:21 +03:00
};
2023-03-26 19:24:28 +03:00
}