summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKleidi Bujari <mail@4kb.net>2025-04-05 14:58:10 -0400
committerKleidi Bujari <mail@4kb.net>2025-04-05 14:58:10 -0400
commit179bf31d5edc90c826dacf0b06b149469d8d14fa (patch)
tree28a07fad01cce7627a2f332094e4a5261c8e5430
parentbf4d4b2a330c03373f75942b9b1723a67f03a709 (diff)
downloaddepot-179bf31d5edc90c826dacf0b06b149469d8d14fa.tar.gz
depot-179bf31d5edc90c826dacf0b06b149469d8d14fa.tar.bz2
depot-179bf31d5edc90c826dacf0b06b149469d8d14fa.zip
automate hosts gen and bump nixpkgs
-rw-r--r--flake.lock35
-rw-r--r--flake.nix97
-rw-r--r--lib/depot-tools.nix6
-rw-r--r--machines/iridium.nix (renamed from machines/iridium/default.nix)1
-rw-r--r--machines/iso.nix (renamed from machines/iso/default.nix)1
-rw-r--r--machines/natest.nix13
-rw-r--r--machines/radon/default.nix1
-rw-r--r--machines/t1.nix (renamed from machines/t1/default.nix)5
-rw-r--r--machines/t480.nix (renamed from machines/t480/default.nix)1
-rw-r--r--modules/disk.nix152
-rw-r--r--packages/cv/cv.typ2
-rw-r--r--packages/partitioner.nix95
12 files changed, 284 insertions, 125 deletions
diff --git a/flake.lock b/flake.lock
index b40bfe5..61b6ed8 100644
--- a/flake.lock
+++ b/flake.lock
@@ -7,40 +7,20 @@
]
},
"locked": {
- "lastModified": 1715070411,
- "narHash": "sha256-5CNvkH0Nf7yMwgKhjUNg/lUK40C7DXB4zKOuA2jVO90=",
+ "lastModified": 1736864502,
+ "narHash": "sha256-ItkIZyebGvNH2dK9jVGzJHGPtb6BSWLN8Gmef16NeY0=",
"owner": "nix-community",
"repo": "disko",
- "rev": "4677f6c53482a8b01ee93957e3bdd569d51261d6",
+ "rev": "0141aabed359f063de7413f80d906e1d98c0c123",
"type": "github"
},
"original": {
"owner": "nix-community",
- "ref": "v1.6.1",
+ "ref": "latest",
"repo": "disko",
"type": "github"
}
},
- "naersk": {
- "inputs": {
- "nixpkgs": [
- "nixpkgs"
- ]
- },
- "locked": {
- "lastModified": 1736429655,
- "narHash": "sha256-BwMekRuVlSB9C0QgwKMICiJ5EVbLGjfe4qyueyNQyGI=",
- "owner": "nix-community",
- "repo": "naersk",
- "rev": "0621e47bd95542b8e1ce2ee2d65d6a1f887a13ce",
- "type": "github"
- },
- "original": {
- "owner": "nix-community",
- "repo": "naersk",
- "type": "github"
- }
- },
"nixos-hardware": {
"locked": {
"lastModified": 1735388221,
@@ -59,11 +39,11 @@
},
"nixpkgs": {
"locked": {
- "lastModified": 1741513245,
- "narHash": "sha256-7rTAMNTY1xoBwz0h7ZMtEcd8LELk9R5TzBPoHuhNSCk=",
+ "lastModified": 1743583204,
+ "narHash": "sha256-F7n4+KOIfWrwoQjXrL2wD9RhFYLs2/GGe/MQY1sSdlE=",
"owner": "nixos",
"repo": "nixpkgs",
- "rev": "e3e32b642a31e6714ec1b712de8c91a3352ce7e1",
+ "rev": "2c8d3f48d33929642c1c12cd243df4cc7d2ce434",
"type": "github"
},
"original": {
@@ -76,7 +56,6 @@
"root": {
"inputs": {
"disko": "disko",
- "naersk": "naersk",
"nixos-hardware": "nixos-hardware",
"nixpkgs": "nixpkgs"
}
diff --git a/flake.nix b/flake.nix
index 605017b..a87c3f6 100644
--- a/flake.nix
+++ b/flake.nix
@@ -3,32 +3,18 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
- disko.url = "github:nix-community/disko/v1.6.1";
+ disko.url = "github:nix-community/disko/latest";
disko.inputs.nixpkgs.follows = "nixpkgs";
nixos-hardware.url = "github:nixos/nixos-hardware/master";
-
- # Rust projects
- naersk.url = "github:nix-community/naersk";
- naersk.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, ... } @ inputs:
let
- inherit (builtins)
- attrNames
- listToAttrs
- map
- readDir
- ;
+ inherit (builtins) mapAttrs;
inherit (nixpkgs) lib;
- inherit (nixpkgs.lib)
- mapAttrs
- nixosSystem
- ;
-
systems = [ "x86_64-linux" "aarch64-linux" ];
inherit (import ./lib/depot-tools.nix { inherit inputs systems lib; })
@@ -40,68 +26,39 @@
packages = eachSystem (
{ newScope, ... }:
mapAttrs (pname: { path, ... }: newScope { inherit pname; } path { })
- (importDir ./packages)
+ (importDir ./packages lib.id)
);
- publisherArgs = {
- flake = self;
- inherit inputs;
- };
+ nixosModules = importDir ./modules
+ (mapAttrs (_: { path, ... }: path));
- expectsPublisherArgs =
- module:
- builtins.isFunction module
- && builtins.all (arg: builtins.elem arg (builtins.attrNames publisherArgs)) (
- builtins.attrNames (builtins.functionArgs module)
- );
-
- injectPublisherArgs =
- modulePath:
+ nixosConfigurations = importDir ./machines (
+ entries:
let
- module = import modulePath;
- in
- if expectsPublisherArgs module then
- lib.setDefaultModuleLocation modulePath (module publisherArgs)
- else
- modulePath;
-
- nixosModules = mapAttrs (_: moduleDir: injectPublisherArgs moduleDir)
- (mapAttrs (_: { path, ... }: path) (importDir ./modules));
- in
- {
- inherit packages nixosModules;
+ flake = self;
- nixosConfigurations = listToAttrs (
- map
- (name: {
- inherit name;
- value = nixosSystem rec {
- system = "x86_64-linux";
- specialArgs = {
- inherit inputs;
- inherit (self) outputs;
- inherit (systemArgs.${system}) flake perSystem;
+ defaultModule = { config, ... }:
+ let
+ perSystemArg = system: {
+ _module.args.perSystem = systemArgs.${system}.perSystem;
};
- modules = [
- # Machine's specific configuration
- ./machines/${name}
-
- # Implicitly import xnet
- self.nixosModules.xnet
-
- # Global module
- ({ inputs, ... }: {
+ in
+ {
+ imports = [ (perSystemArg config.nixpkgs.hostPlatform.system) ];
+ };
- # Set system nixpkgs to flake input
- nix.registry = {
- nixpkgs.flake = inputs.nixpkgs;
- depot.flake = self;
- };
- })
+ buildNixOS = hostName: entry:
+ lib.nixosSystem {
+ modules = [
+ defaultModule
+ entry.path
+ nixosModules.xnet
];
+ specialArgs = { inherit inputs flake hostName; };
};
- })
- (attrNames (readDir ./machines))
+ in
+ mapAttrs buildNixOS entries
);
- };
+ in
+ { inherit packages nixosModules nixosConfigurations; };
}
diff --git a/lib/depot-tools.nix b/lib/depot-tools.nix
index 448055a..1a16df9 100644
--- a/lib/depot-tools.nix
+++ b/lib/depot-tools.nix
@@ -21,7 +21,7 @@ let
;
importDir =
- path:
+ path: fn:
let
entries = readDir path;
@@ -51,8 +51,10 @@ let
}
)
entries) [ "__junk" ];
+
+ combined = dirPaths // nixPaths;
in
- dirPaths // nixPaths;
+ fn combined;
# Memoize the args per system
systemArgs = genAttrs systems (
diff --git a/machines/iridium/default.nix b/machines/iridium.nix
index 3cbfc89..03727d7 100644
--- a/machines/iridium/default.nix
+++ b/machines/iridium.nix
@@ -6,6 +6,7 @@ let
;
in
{
+ nixpkgs.hostPlatform.system = "x86_64-linux";
system.stateVersion = "25.05";
networking.hostName = "iridium";
diff --git a/machines/iso/default.nix b/machines/iso.nix
index d27b26e..d3ca992 100644
--- a/machines/iso/default.nix
+++ b/machines/iso.nix
@@ -4,6 +4,7 @@
(modulesPath + "/installer/cd-dvd/channel.nix")
];
+ nixpkgs.hostPlatform.system = "x86_64-linux";
nix.settings = {
experimental-features = [ "nix-command" "flakes" ];
};
diff --git a/machines/natest.nix b/machines/natest.nix
new file mode 100644
index 0000000..1623bd3
--- /dev/null
+++ b/machines/natest.nix
@@ -0,0 +1,13 @@
+{ flake, modulesPath, perSystem, ... }: {
+ imports = [
+ flake.outputs.nixosModules.disk
+ (modulesPath + "/installer/cd-dvd/installation-cd-minimal.nix")
+ (modulesPath + "/profiles/qemu-guest.nix")
+ ];
+
+ nixpkgs.hostPlatform = "x86_64-linux";
+ system.stateVersion = "24.11";
+
+ environment.systemPackages = [ perSystem.self.partitioner ];
+ virtualisation.diskSize = 16384;
+}
diff --git a/machines/radon/default.nix b/machines/radon/default.nix
index 7615be8..e4dc09a 100644
--- a/machines/radon/default.nix
+++ b/machines/radon/default.nix
@@ -19,6 +19,7 @@ in
./pxeboot.nix
];
+ nixpkgs.hostPlatform.system = "x86_64-linux";
system.stateVersion = "24.11";
networking.hostName = "radon";
diff --git a/machines/t1/default.nix b/machines/t1.nix
index 7f375a1..200d1b4 100644
--- a/machines/t1/default.nix
+++ b/machines/t1.nix
@@ -6,14 +6,17 @@ let
common-gpu-amd
;
- inherit (import flake.outputs.nixosModules.users { inherit perSystem pkgs; }) kle;
+ inherit (import flake.outputs.nixosModules.users { inherit perSystem pkgs; })
+ kle;
in
{
imports = [
common-cpu-amd
common-gpu-amd
+ flake.outputs.nixosModules.disk
];
+ nixpkgs.hostPlatform = "x86_64-linux";
system.stateVersion = "24.11";
users.users.kle = kle;
diff --git a/machines/t480/default.nix b/machines/t480.nix
index 24b6bc6..2588bdc 100644
--- a/machines/t480/default.nix
+++ b/machines/t480.nix
@@ -11,6 +11,7 @@ in
lenovo-thinkpad-t480
];
+ nixpkgs.hostPlatform.system = "x86_64-linux";
system.stateVersion = "24.05";
xnet = {
diff --git a/modules/disk.nix b/modules/disk.nix
new file mode 100644
index 0000000..8635888
--- /dev/null
+++ b/modules/disk.nix
@@ -0,0 +1,152 @@
+{ config, pkgs, lib, modulesPath, inputs, ... }:
+let
+ cfg = config.depot.disk;
+
+ inherit (lib) mkOption mkDefault mkIf types;
+in
+{
+ imports = [
+ (modulesPath + "/installer/scan/not-detected.nix")
+ inputs.disko.nixosModules.default
+ ];
+
+ options.depot.disk = {
+ enable = mkOption {
+ type = types.bool;
+ default = false;
+ description = "Apply depot-standard ZFS disk layout.";
+ };
+
+ device = mkOption {
+ type = types.str;
+ description = "Device used for zroot ZFS pool.";
+ };
+ };
+
+ config = mkIf cfg.enable {
+ networking.hostId = builtins.substring 0 8
+ (builtins.hashString "md5" config.networking.hostName);
+
+ services = {
+ zfs.autoScrub.enable = true;
+ zfs.trim.enable = true;
+ sanoid = {
+ enable = true;
+ templates.default = {
+ autosnap = true;
+ autoprune = true;
+ hourly = 24;
+ daily = 14;
+ monthly = 1;
+ };
+ datasets."zroot/persist" = {
+ useTemplate = [ "default" ];
+ recursive = true;
+ };
+ };
+ };
+
+ # With root running in memory, swap should be required unless
+ # otherwise specified
+ zramSwap.enable = mkDefault true;
+
+ boot = {
+ kernelParams = [ "nohibernate" "elevator=none" ];
+ supportedFilesystems = [ "vfat" "zfs" ];
+ zfs.devNodes = mkDefault "/dev/disk/by-partuuid";
+ loader.efi.canTouchEfiVariables = true;
+ loader.systemd-boot = {
+ enable = true;
+ extraFiles."efi/ipxe.efi" = "${pkgs.ipxe}/ipxe.efi";
+ extraEntries."ipxe.conf" = ''
+ title iPXE
+ efi /efi/ipxe.efi
+ sortkey z-ipxe
+ '';
+ };
+ initrd = {
+ systemd.enable = true;
+ availableKernelModules = [
+ "xhci_pci"
+ "ahci"
+ "nvme"
+ "usb_storage"
+ "sd_mod"
+ "sdhci_pci"
+ ];
+ };
+ };
+
+ disko.devices.nodev."/" = {
+ fsType = "tmpfs";
+ mountOptions = [ "defaults" "size=2G" "mode=755" ];
+ };
+
+ disko.devices.disk.main = {
+ type = "disk";
+ device = cfg.device;
+ imageSize = "15G";
+ content = {
+ type = "gpt";
+ partitions.ESP = {
+ size = "1G";
+ type = "EF00";
+ content = {
+ type = "filesystem";
+ format = "vfat";
+ mountpoint = "/boot";
+ };
+ };
+ partitions.ZFS = {
+ size = "100%";
+ content.type = "zfs";
+ content.pool = "zroot";
+ };
+ };
+ };
+
+ disko.devices.zpool.zroot = {
+ type = "zpool";
+ options = {
+ ashift = "12";
+ autotrim = "on";
+ };
+
+ rootFsOptions = {
+ "com.sun:auto-snapshot" = "false";
+ acltype = "posixacl";
+ atime = "off";
+ compression = "on";
+ normalization = "formD";
+ relatime = "off";
+ xattr = "sa";
+ };
+
+ datasets.nix = {
+ type = "zfs_fs";
+ mountpoint = "/nix";
+ options.mountpoint = "legacy";
+ };
+
+ # datasets.reserved = {
+ # type = "zfs_fs";
+ # options = {
+ # refreservation = "10G";
+ # mountpoint = "none";
+ # };
+ # };
+
+ datasets.home = {
+ type = "zfs_fs";
+ mountpoint = "/home";
+ options.mountpoint = "legacy";
+ };
+
+ # datasets.persist = {
+ # type = "zfs_fs";
+ # mountpoint = "/persist";
+ # options.mountpoint = "legacy";
+ # };
+ };
+ };
+}
diff --git a/packages/cv/cv.typ b/packages/cv/cv.typ
index fb36816..524565c 100644
--- a/packages/cv/cv.typ
+++ b/packages/cv/cv.typ
@@ -1,6 +1,6 @@
#set document(author: "Kleidi Bujari", title: "Kleidi's Resume!")
#set text(size: 10pt, lang: "en", ligatures: false)
-#set page(margin: 0.5in, paper: "us-letter")
+// #set page(margin: 0.5in, paper: "us-letter")
#show link: underline
#set par(justify: true)
diff --git a/packages/partitioner.nix b/packages/partitioner.nix
index cd36f5d..df9f37d 100644
--- a/packages/partitioner.nix
+++ b/packages/partitioner.nix
@@ -1,33 +1,82 @@
# Apply standard partition layout to a disk device.
{ pkgs, ... }:
-pkgs.writeShellScriptBin "partitioner" ''
- set -e
+pkgs.writeShellApplication {
+ name = "partitioner";
- if [ $# -ne 1 ]; then
- echo "Usage: $0 <disk-device>"
- exit 1
- fi
+ runtimeInputs = with pkgs; [
+ gptfdisk
+ dosfstools
+ zfs
+ coreutils
+ util-linux
+ ];
- DISK=$1
+ text = ''
+ set -euo pipefail
- # Clear existing partitions
- sgdisk -Z "$DISK"
+ if [ $# -ne 1 ]; then
+ echo "Usage: $0 <device>"
+ echo "Example: $0 /dev/sda or /dev/nvme0n1"
+ exit 1
+ fi
- # 1GB EFI partition (FAT32)
- sgdisk -n 1:0:+1G -t 1:EF00 -c 1:EFI "$DISK"
+ DISK="$1"
- # Rest for ZFS
- sgdisk -n 2:0:0 -t 2:BF01 -c 2:ZFS "$DISK"
+ if [ ! -b "$DISK" ]; then
+ echo "Error: $DISK is not a valid block device"
+ exit 1
+ fi
- mkfs.fat -F32 -nEFI ""
+ echo "creating partition table on $DISK"
+ # create gpt partition table
+ sgdisk --zap-all "$DISK"
- zpool create \
- -o ashift=12 \
- -O compression=on \
- -O acltype=posixacl \
- -O xattr=sa \
- -O relatime=off
- -O normalization=formD \
- zroot "$DISK"
-''
+ echo "creating efi partition"
+ sgdisk --new=1:0:+1G --typecode=1:EF00 --change-name=1:ESP "$DISK"
+
+ echo "creating zfs partition with remaining space"
+ sgdisk --new=2:0:0 --typecode=2:BF00 --change-name=2:ZROOT "$DISK"
+
+ if [[ "$DISK" == *"nvme"* ]]; then
+ EFI_PART="''${DISK}p1"
+ ZFS_PART="''${DISK}p2"
+ else
+ EFI_PART="''${DISK}1"
+ ZFS_PART="''${DISK}2"
+ fi
+
+ sleep 1
+
+ echo "formatting rfi partition ($EFI_PART)"
+ mkfs.fat -F32 -n ESP "$EFI_PART"
+
+ echo "creating pool on $ZFS_PART"
+ zpool create -f \
+ -o ashift=12 \
+ -o autotrim=on \
+ -O acltype=posixacl \
+ -O canmount=off \
+ -O compression=on \
+ -O mountpoint=none \
+ -O normalization=formD \
+ -O relatime=off \
+ -O xattr=sa \
+ zroot "$ZFS_PART"
+
+ # create ZFS datasets
+ echo "Creating datasets"
+
+ zfs create \
+ -o refreservation=10G \
+ -o mountpoint=none \
+ zroot/reserved
+
+ zfs create -o mountpoint=legacy zroot/nix
+ zfs create -o mountpoint=legacy zroot/home
+ zfs create -o mountpoint=legacy zroot/persist
+
+ echo "---"
+ echo "done"
+ '';
+}