This commit is contained in:
Joseph Hanson 2024-07-06 22:38:39 -05:00
parent 1a50754a3b
commit 5c427104e1
Signed by: jahanson
SSH key fingerprint: SHA256:vy6dKBECV522aPAwklFM3ReKAVB086rT3oWwiuiFG7o
4 changed files with 203 additions and 0 deletions

54
configuration.nix Normal file
View file

@ -0,0 +1,54 @@
# This is a small config that can be used to bootstrap a system with ZFS.
{ config, lib, modulesPath, ... }:
{
imports =
[
(modulesPath + "/installer/scan/not-detected.nix")
];
# Generate a hostId for ZFS
# head -c4 /dev/urandom | od -A none -t x4
networking.hostId = "f35c6293";
networking.hostName = "MiniNix";
boot = {
initrd.availableKernelModules = [ "xhci_pci" "ahci" "nvme" "usbhid" "usb_storage" "sd_mod" ];
initrd.kernelModules = [ ];
kernelModules = [ "kvm-intel" ];
extraModulePackages = [ ];
loader = {
grub = {
enable = true;
zfsSupport = true;
device = "nodev";
mirroredBoots = [
{ devices = [ "nodev" ]; path = "/boot"; }
];
};
};
};
fileSystems."/" = {
device = "zroot/root";
fsType = "zfs";
};
fileSystems."/nix" = {
device = "zroot/nix";
fsType = "zfs";
};
fileSystems."/var" = {
device = "zroot/var";
fsType = "zfs";
};
fileSystems."/home" = {
device = "zroot/home";
fsType = "zfs";
};
swapDevices = [ ];
hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
system.stateVersion = "24.05";
}

73
disko-nixos.nix Normal file
View file

@ -0,0 +1,73 @@
{ disks ? [ "/dev/sda" ], ... }: {
disko.devices = {
disk = {
main = {
type = "disk";
device = builtins.elemAt disks 0;
content = {
type = "gpt";
partitions = {
ESP = {
size = "1024M";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
};
zfs = {
size = "100%";
content = {
type = "zfs";
pool = "zroot";
};
};
};
};
};
};
zpool = {
zroot = {
type = "zpool";
mode = "";
rootFsOptions = {
compression = "zstd";
"com.sun:auto-snapshot" = "false";
mountpoint = "none";
acltype = "posixacl";
};
mountOptions = [
"ashift=12"
];
postCreateHook = "zfs list -t snapshot -H -o name | grep -E '^zroot@blank$' || zfs snapshot zroot@blank";
datasets = {
root = {
type = "zfs_fs";
mountpoint = "/";
};
nix = {
type = "zfs_fs";
mountpoint = "/nix";
};
var = {
type = "zfs_fs";
mountpoint = "/var";
};
home = {
type = "zfs_fs";
mountpoint = "/home";
options = {
"com.sun:auto-snapshot" = "true";
};
};
};
};
};
};
}

48
flake.lock Normal file
View file

@ -0,0 +1,48 @@
{
"nodes": {
"disko": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1720056646,
"narHash": "sha256-BymcV4HWtx2VFuabDCM4/nEJcfivCx0S02wUCz11mAY=",
"owner": "nix-community",
"repo": "disko",
"rev": "64679cd7f318c9b6595902b47d4585b1d51d5f9e",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "disko",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1720110830,
"narHash": "sha256-E5dN9GDV4LwMEduhBLSkyEz51zM17XkWZ3/9luvNOPs=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "c0d0be00d4ecc4b51d2d6948e37466194c1e6c51",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-24.05",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"disko": "disko",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

28
flake.nix Normal file
View file

@ -0,0 +1,28 @@
{
description = "MiniNix";
inputs = {
# Nixpkgs
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
# disko - Declarative disk partitioning and formatting using nix
disko = {
url = "github:nix-community/disko";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, disko, ... }@inputs: {
nixosConfigurations = {
"mini-x86" = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = { inherit inputs; };
modules = [
./configuration.nix
disko.nixosModules.disko
(import ./disko-nixos.nix { disks = [ "/dev/nvme0n1" ]; })
];
};
};
};
}