finally zfs is working

This commit is contained in:
Snorre Ettrup Altschul 2025-03-02 22:23:51 +01:00
parent 5634e20d49
commit 95de139644
4 changed files with 122 additions and 51 deletions

View file

@ -1,27 +1,20 @@
{ pkgs
, inputs
, modulesPath
, lib
, ...
{
pkgs,
inputs,
modulesPath,
lib,
...
}: {
imports = [
(modulesPath + "/profiles/qemu-guest.nix") # Temporary
];
networking.useDHCP = lib.mkDefault true;
nixpkgs.hostPlatform = "x86_64-linux";
hardware.cpu.intel.updateMicrocode = true;
boot.loader = {
systemd-boot.enable = true;
efi.canTouchEfiVariables = true;
timeout = 0;
};
# boot.zfs.extraPools = [ "zraid" ];
boot.supportedFilesystems = [ "zfs" ];
boot.zfs.forceImportRoot = false;
boot.zfs.devNodes = "/dev/disk/by-path";
nix.settings.experimental-features = ["nix-command" "flakes"];
nix.gc = {
@ -61,15 +54,13 @@
shell = pkgs.zsh;
};
users.users."nixos" =
{
users.users."nixos" = {
isNormalUser = true;
initialPassword = "1234";
extraGroups = ["wheel"];
};
users.users.root =
{
users.users.root = {
initialPassword = "1234";
};
@ -112,12 +103,14 @@
services.openssh = {
enable = true;
settings = {
PasswordAuthentication = true;
KbdInteractiveAuthentication = true;
PasswordAuthentication = false;
KbdInteractiveAuthentication = false;
AllowUsers = null;
PermitRootLogin = "no";
};
};
nix.settings.trusted-users = ["@wheel"];
system.stateVersion = "24.11";
}

View file

@ -1,8 +1,8 @@
{
lib,
root-disk ? "Expected a mf disk brother",
raid-disks ? "Expected disks for raid",
...
{ lib
, root-disk ? throw "Expected a mf disk brother"
, raid-disks ? []
, swap-size ? -1
, ...
}: {
disko.devices = {
disk =
@ -23,12 +23,19 @@
mountOptions = [ "umask=0077" ];
};
};
swap = lib.mkIf (swap-size != -1) {
size = swap-size;
content = {
type = "swap";
discardPolicy = "both";
resumeDevice = true;
};
};
root = {
size = "100%";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/";
type = "zfs";
pool = "zroot";
};
};
};
@ -55,6 +62,7 @@
# };
# };
}
# Import all disks into raid named "raid5"
// lib.attrsets.genAttrs raid-disks (name: {
type = "disk";
device = "/dev/" + name;
@ -65,29 +73,54 @@
size = "100%";
content = {
type = "zfs";
pool = "storage";
pool = "raid5";
};
};
};
};
});
zpool = lib.mkIf (builtins.length raid-disks > 0) {
storage = {
zpool = {
zroot = {
type = "zpool";
rootFsOptions.mountpoint = "none";
datasets = {
root = {
type = "zfs_fs";
mountpoint = "/";
};
"nix/store" = {
type = "zfs_fs";
mountpoint = "/nix/store";
};
};
};
raid5 = lib.mkIf (builtins.length raid-disks > 0) {
type = "zpool";
mode = "raidz";
# TODO: Cache-ing
# rootFsOptions = {
# compression = "zstd";
# "com.sun:auto-snapshot" = "false";
# };
mountpoint = "/storage";
rootFsOptions.compression = "zstd";
rootFsOptions.mountpoint = "none";
datasets = {
var = {
type = "zfs_fs";
mountpoint = "/storage/var";
mountpoint = "/var";
};
home = {
type = "zfs_fs";
mountpoint = "/home";
};
src = {
type = "zfs_fs";
mountpoint = "/srv";
};
opt = {
type = "zfs_fs";
mountpoint = "/opt";
};
};
};

View file

@ -26,12 +26,13 @@
formatter.${system} = pkgs.alejandra;
nixosConfigurations = {
server = nixpkgs.lib.nixosSystem {
server-vm = nixpkgs.lib.nixosSystem {
specialArgs = {inherit inputs;};
modules = [
inputs.disko.nixosModules.default
(import ./disko.nix {
lib = pkgs.lib;
swap-size = "16G";
root-disk = "/dev/vda";
raid-disks = [
"vdb"
@ -41,9 +42,33 @@
})
inputs.home-manager.nixosModules.default
./vm-hardware-configuration.nix
./configuration.nix
];
};
server = nixpkgs.lib.nixosSystem {
specialArgs = {inherit inputs;};
modules = [
inputs.disko.nixosModules.default
(import ./disko.nix {
lib = pkgs.lib;
swap-size = "128G";
root-disk = "/dev/nvme0n1";
raid-disks = [
"sda"
"sdb"
"sdc"
"sdd"
];
})
inputs.home-manager.nixosModules.default
./hardware-configuration.nix
./configuration.nix
];
};
};
};
}

View file

@ -0,0 +1,20 @@
{
config,
lib,
pkgs,
modulesPath,
...
}: {
imports = [
(modulesPath + "/profiles/qemu-guest.nix")
];
boot.initrd.availableKernelModules = ["ahci" "xhci_pci" "virtio_pci" "virtio_scsi" "sr_mod" "virtio_blk"];
boot.initrd.kernelModules = [];
boot.kernelModules = ["kvm_amd"];
boot.extraModulePackages = [];
networking.useDHCP = lib.mkDefault true;
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
}