feat: Rihla | add secure boot and impermanence options

This commit is contained in:
2025-02-16 19:33:15 +05:00
parent ecce02959b
commit f335ca5c52
2 changed files with 43 additions and 9 deletions

View File

@@ -2,6 +2,7 @@
inputs, inputs,
pkgs, pkgs,
lib, lib,
config,
... ...
}: }:
@@ -26,10 +27,12 @@
# #
inputs.disko.nixosModules.disko inputs.disko.nixosModules.disko
(lib.custom.relativeToRoot "hosts/common/disks/rihla.nix") { (lib.custom.relativeToRoot "hosts/common/disks/rihla.nix") {
device = "/dev/nvme0n1"; _module.args = {
withSwap = true; device = "/dev/nvme0n1";
swapSize = 64; withSwap = true;
label = "nixos"; swapSize = 64;
label = "nixos";
};
} }
# #
@@ -42,7 +45,7 @@
# #
# ========= Optional Configs ========= # ========= Optional Configs =========
# #
(map (config: lib.custom.relativeToRoot "hosts/common/optional/${config}.nix") [ (map (c: lib.custom.relativeToRoot "hosts/common/optional/${c}.nix") [
"1password" "1password"
"dconf" "dconf"
"docker" "docker"
@@ -56,7 +59,7 @@
# #
# ========= Optional Services ========= # ========= Optional Services =========
# #
(map (service: lib.custom.relativeToRoot "hosts/common/optional/services/${service}.nix") [ (map (s: lib.custom.relativeToRoot "hosts/common/optional/services/${s}.nix") [
"audio" "audio"
"bluetooth" "bluetooth"
"firmware" "firmware"
@@ -73,6 +76,7 @@
hostSpec = { hostSpec = {
hostName = "rihla"; hostName = "rihla";
useYubikey = lib.mkForce true; useYubikey = lib.mkForce true;
secureBoot = true;
}; };
networking = { networking = {
@@ -83,12 +87,37 @@
boot = { boot = {
loader = { loader = {
# Set this to true on first install. This must be false for secure boot. # Set this to true on first install. This must be false for secure boot.
systemd-boot.enable = lib.mkForce false; systemd-boot.enable = lib.mkForce (!config.hostSpec.secureBoot);
efi.canTouchEfiVariables = true; efi.canTouchEfiVariables = true;
}; };
initrd.postResumeCommands = lib.mkIf config.hostSpec.impermanance (lib.mkAfter ''
mkdir /btrfs_tmp
mount /dev/crypt_vg/root /btrfs_tmp
if [[ -e /btrfs_tmp/root ]]; then
mkdir -p /btrfs_tmp/old_roots
timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/root)" "+%Y-%m-%-d_%H:%M:%S")
mv /btrfs_tmp/root "/btrfs_tmp/old_roots/$timestamp"
fi
delete_subvolume_recursively() {
IFS=$'\n'
for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do
delete_subvolume_recursively "/btrfs_tmp/$i"
done
btrfs subvolume delete "$1"
}
for i in $(find /btrfs_tmp/old_roots/ -maxdepth 1 -mtime +30); do
delete_subvolume_recursively "$i"
done
btrfs subvolume create /btrfs_tmp/root
umount /btrfs_tmp
'');
lanzaboote = { lanzaboote = {
enable = true; enable = config.hostSpec.secureBoot;
pkiBundle = "/var/lib/sbctl"; pkiBundle = "/var/lib/sbctl";
}; };
}; };

View File

@@ -40,7 +40,12 @@
description = "The home directory of the user"; description = "The home directory of the user";
default = "/home/${config.hostSpec.username}"; default = "/home/${config.hostSpec.username}";
}; };
impermenance = lib.mkOption { secureBoot = lib.mkOption {
type = lib.types.bool;
description = "Whether or not secure boot has been enabled";
default = false;
};
impermanance = lib.mkOption {
type = lib.types.bool; type = lib.types.bool;
description = "Whether or not to enable impermenance"; description = "Whether or not to enable impermenance";
default = false; default = false;