Add simple VM

This commit is contained in:
Bun 2025-03-24 02:55:47 -04:00
parent 0c78b13ceb
commit ad87c44701
8 changed files with 138 additions and 0 deletions

View file

@ -55,6 +55,7 @@
# nixos-rebuild switch --flake /etc/nixos#hostname
nixosConfigurations = {
tower = mkNix [ ./hosts/tower ]; # Main Desktop
qemu = mkNix [ ./hosts/qemu ]; # Virtualization Testing
envy = mkNix [ ./hosts/envy ]; # HP Convertable
pear = mkNix [ ./hosts/pear ]; # MacBook Pro

View file

@ -0,0 +1,10 @@
{ pkgs, ... }:
{
boot = {
kernelPackages = pkgs.linuxPackages_latest;
loader.grub = {
enable = true;
device = "/dev/vda";
};
};
}

13
hosts/qemu/default.nix Normal file
View file

@ -0,0 +1,13 @@
{ config, lib, ... }:
{
imports = [
./boot
./disko
./hardware
./users
../../modules/system
];
networking.hostName = "qemu";
system.stateVersion = "24.11";
}

View file

@ -0,0 +1,90 @@
{ config, disko, ... }:
{
imports = [ disko.nixosModules.disko ];
disko.devices = {
disk = {
"${config.networking.hostName}" = {
type = "disk";
device = "/dev/nvme0n1";
content = {
type = "gpt";
partitions = {
ESP = {
priority = 1;
size = "2G";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = [ "umask=0077" ];
};
};
luks = {
size = "100%";
content = {
type = "luks";
name = "${config.networking.hostName}-disk";
settings.allowDiscards = true;
passwordFile = "/tmp/secret.key";
content = {
type = "lvm_pv";
vg = "${config.networking.hostName}";
};
};
};
};
};
};
};
lvm_vg = {
"${config.networking.hostName}" = {
type = "lvm_vg";
lvs = {
root = {
size = "100%";
content = {
type = "btrfs";
extraArgs = [ "-f" ];
subvolumes = {
"/root" = {
mountpoint = "/";
mountOptions = [ "compress=zstd" "noatime" "ssd" ];
};
"/prev" = {
mountpoint = "/prev";
mountOptions = [ "compress=zstd" "noatime" "ssd" ];
};
"/nix" = {
mountpoint = "/nix";
mountOptions = [ "compress=zstd" "noatime" "ssd" ];
};
# Impermanence
"/persist" = {
mountpoint = "/persist";
mountOptions = [ "compress=zstd" "noatime" "ssd" ];
};
"/persist/.snapshots" = { };
"/persist/home" = { };
"/persist/home/.snapshots" = { };
};
};
};
swap = {
size = "4G";
content = {
type = "swap";
discardPolicy = "both";
};
};
};
};
};
};
# Needed for impermanence
fileSystems."/persist".neededForBoot = true;
}

View file

@ -0,0 +1,13 @@
{ config, lib, modulesPath, ... }:
{
imports = [
(modulesPath + "/installer/scan/not-detected.nix")
(modulesPath + "/virtualisation/qemu-vm.nix")
];
boot.initrd.availableKernelModules = [ "xhci_pci" "sr_mod" ];
boot.initrd.kernelModules = [ "dm-snapshot" ];
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
}

View file

@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAb+aqIyTDcXDH8vMK697zQnYYUjgbUD2tJyknlztE3j

View file

@ -0,0 +1,4 @@
{ ... }:
{
imports = [ ./main ];
}

View file

@ -0,0 +1,6 @@
{ config, lib, ... }:
{
home-manager.users."${config.sysusers.main}".home = {
stateVersion = lib.mkForce config.system.stateVersion;
};
}