Add NixOS modules: boot, users, AMD, disko layout, secrets, Hyprland, Steam
- my.disks generates disko: NVMe btrfs (@root/@home/@nix/@log/@swap) + SATA SSD btrfs with one subvolume per ~/Games, Downloads, Documents, Music, Pictures, Videos, Storage (nofail) - lanzaboote Secure Boot, systemd initrd, latest kernel - AMD CPU/GPU: amdgpu initrd, OpenCL, LACT, optional ROCm - agenix with host-key identity, optional password and SSH key secrets - Hyprland (UWSM, XWayland) + greetd/tuigreet, Noctalia services, PipeWire, fonts - Steam + Proton-GE, gamescope, gamemode - overlays: compose Hyprland's hyprland-packages + hyprland-extras (upstream default lacks the hyprwm dependency overlays) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J1cugeLkfFLZMpiztQ8TyN
This commit is contained in:
21 files changed
+972
-4
No files matched your search
@@ -0,0 +1,71 @@
|
||||
# AMD CPU + Radeon GPU. nixos-hardware (common-cpu-amd, -pstate, -gpu-amd,
|
||||
# -pc-ssd) is imported by the host; defaults that overlap use mkDefault.
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.my.hardware.amd;
|
||||
in
|
||||
{
|
||||
options.my.hardware.amd = {
|
||||
enable = lib.mkEnableOption "AMD CPU and Radeon GPU support";
|
||||
|
||||
rocm.enable = lib.mkEnableOption "ROCm/HIP compute stack (rocminfo, rocm-smi, /opt/rocm/hip)";
|
||||
|
||||
lact.enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
description = "LACT daemon for GPU monitoring, fan curves and overclocking.";
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable (
|
||||
lib.mkMerge [
|
||||
{
|
||||
hardware = {
|
||||
graphics = {
|
||||
enable = true;
|
||||
# Steam/Proton and Wine need the 32-bit Mesa drivers.
|
||||
enable32Bit = true;
|
||||
};
|
||||
|
||||
amdgpu = {
|
||||
initrd.enable = lib.mkDefault true;
|
||||
opencl.enable = true;
|
||||
};
|
||||
|
||||
cpu.amd.updateMicrocode = lib.mkDefault true;
|
||||
};
|
||||
|
||||
boot.kernelModules = [ "kvm-amd" ];
|
||||
|
||||
environment.systemPackages = with pkgs; [
|
||||
vulkan-tools
|
||||
mesa-demos
|
||||
radeontop
|
||||
nvtopPackages.amd
|
||||
lm_sensors
|
||||
];
|
||||
}
|
||||
|
||||
(lib.mkIf cfg.lact.enable {
|
||||
services.lact.enable = true;
|
||||
# LACT needs the overdrive bit in amdgpu.ppfeaturemask to tune clocks.
|
||||
hardware.amdgpu.overdrive.enable = true;
|
||||
})
|
||||
|
||||
(lib.mkIf cfg.rocm.enable {
|
||||
environment.systemPackages = with pkgs.rocmPackages; [
|
||||
rocminfo
|
||||
rocm-smi
|
||||
];
|
||||
|
||||
# Many HIP applications look for the runtime in /opt/rocm/hip.
|
||||
systemd.tmpfiles.rules = [ "L+ /opt/rocm/hip - - - - ${pkgs.rocmPackages.clr}" ];
|
||||
})
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
# Declarative disk layout, generated into `disko.devices` from `my.disks`.
|
||||
#
|
||||
# system disk (NVMe): ESP + btrfs "nixos" with @root @home @nix @log @swap
|
||||
# data disk (SATA): btrfs "data", one subvolume per home folder, each
|
||||
# mounted inside the user's home (~/Games, ~/Music, ...)
|
||||
#
|
||||
# `disko-install` / the install script partitions the disks from this; on a
|
||||
# running system the same data produces the matching `fileSystems` entries.
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.my.disks;
|
||||
inherit (lib) mkOption types;
|
||||
|
||||
user = config.my.user.name;
|
||||
home = "/home/${user}";
|
||||
folders = cfg.data.homeFolders;
|
||||
hasFolders = cfg.data.enable && folders != { };
|
||||
|
||||
# Compression keeps the NVMe small-write friendly; noatime avoids metadata writes.
|
||||
btrfsOptions = [
|
||||
"compress=zstd:1"
|
||||
"noatime"
|
||||
];
|
||||
|
||||
placeholderDevices = lib.filter (d: lib.hasInfix "CHANGE-ME" d) (
|
||||
[ cfg.system.device ] ++ lib.optional cfg.data.enable cfg.data.device
|
||||
);
|
||||
in
|
||||
{
|
||||
options.my.disks = {
|
||||
enable = lib.mkEnableOption "the disko-managed disk layout";
|
||||
|
||||
system = {
|
||||
device = mkOption {
|
||||
type = types.str;
|
||||
example = "/dev/disk/by-id/nvme-Samsung_SSD_990_PRO_1TB_S6XXXXXXXXXXXX";
|
||||
description = "Whole disk for the ESP and the btrfs root. Use a stable /dev/disk/by-id path.";
|
||||
};
|
||||
|
||||
espSize = mkOption {
|
||||
type = types.str;
|
||||
default = "2G";
|
||||
description = "Size of the EFI system partition (mounted on /boot).";
|
||||
};
|
||||
|
||||
swapSize = mkOption {
|
||||
type = types.str;
|
||||
default = "16G";
|
||||
description = "Size of the swapfile in the @swap subvolume.";
|
||||
};
|
||||
};
|
||||
|
||||
data = {
|
||||
enable = lib.mkEnableOption "the second (data) disk";
|
||||
|
||||
device = mkOption {
|
||||
type = types.str;
|
||||
example = "/dev/disk/by-id/ata-Samsung_SSD_870_EVO_2TB_S6XXXXXXXXXXXX";
|
||||
description = "Whole disk holding the home folder subvolumes.";
|
||||
};
|
||||
|
||||
mountOptions = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [
|
||||
"compress=zstd:1"
|
||||
"noatime"
|
||||
# The machine still boots (to the system disk) if the SSD is missing.
|
||||
"nofail"
|
||||
"x-systemd.device-timeout=10s"
|
||||
];
|
||||
description = "Mount options of every data subvolume.";
|
||||
};
|
||||
|
||||
homeFolders = mkOption {
|
||||
type = types.attrsOf (
|
||||
types.submodule (
|
||||
{ name, ... }:
|
||||
{
|
||||
options.subvolume = mkOption {
|
||||
type = types.str;
|
||||
default = "@" + lib.toLower name;
|
||||
defaultText = lib.literalExpression ''"@" + lib.toLower name'';
|
||||
description = "Btrfs subvolume backing this folder.";
|
||||
};
|
||||
}
|
||||
)
|
||||
);
|
||||
default = { };
|
||||
example = lib.literalExpression ''{ Games = { }; Music.subvolume = "@tunes"; }'';
|
||||
description = ''
|
||||
Folders of the home directory that live on the data disk. The attribute
|
||||
name is the folder name and is mounted at /home/<user>/<name>.
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable (
|
||||
lib.mkMerge [
|
||||
{
|
||||
disko.devices.disk.system = {
|
||||
type = "disk";
|
||||
inherit (cfg.system) device;
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
ESP = {
|
||||
size = cfg.system.espSize;
|
||||
type = "EF00";
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "vfat";
|
||||
mountpoint = "/boot";
|
||||
# Only root may read the ESP (random seed, lanzaboote images).
|
||||
mountOptions = [ "umask=0077" ];
|
||||
};
|
||||
};
|
||||
|
||||
root = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "btrfs";
|
||||
extraArgs = [
|
||||
"-f"
|
||||
"-L"
|
||||
"nixos"
|
||||
];
|
||||
subvolumes = {
|
||||
"@root" = {
|
||||
mountpoint = "/";
|
||||
mountOptions = btrfsOptions;
|
||||
};
|
||||
"@home" = {
|
||||
mountpoint = "/home";
|
||||
mountOptions = btrfsOptions;
|
||||
};
|
||||
"@nix" = {
|
||||
mountpoint = "/nix";
|
||||
mountOptions = btrfsOptions;
|
||||
};
|
||||
"@log" = {
|
||||
mountpoint = "/var/log";
|
||||
mountOptions = btrfsOptions;
|
||||
};
|
||||
# No compression on the swapfile's subvolume.
|
||||
"@swap" = {
|
||||
mountpoint = "/swap";
|
||||
mountOptions = [ "noatime" ];
|
||||
swap.swapfile.size = cfg.system.swapSize;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
# Logs must be mounted before journald starts in stage 2.
|
||||
fileSystems."/var/log".neededForBoot = true;
|
||||
|
||||
services.btrfs.autoScrub = {
|
||||
enable = true;
|
||||
interval = "monthly";
|
||||
fileSystems = [
|
||||
"/"
|
||||
]
|
||||
++ lib.optional hasFolders "${home}/${lib.head (lib.attrNames folders)}";
|
||||
};
|
||||
|
||||
warnings = lib.optional (placeholderDevices != [ ]) ''
|
||||
my.disks still has placeholder device paths (${lib.concatStringsSep ", " placeholderDevices}).
|
||||
Run `nix run .#install`, or edit hosts/desktop/disk-ids.json, before installing.
|
||||
'';
|
||||
}
|
||||
|
||||
(lib.mkIf cfg.data.enable {
|
||||
disko.devices.disk.data = {
|
||||
type = "disk";
|
||||
inherit (cfg.data) device;
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions.data = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "btrfs";
|
||||
extraArgs = [
|
||||
"-f"
|
||||
"-L"
|
||||
"data"
|
||||
];
|
||||
subvolumes = lib.mapAttrs' (
|
||||
name: folder:
|
||||
lib.nameValuePair folder.subvolume {
|
||||
mountpoint = "${home}/${name}";
|
||||
inherit (cfg.data) mountOptions;
|
||||
}
|
||||
) folders;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
# Subvolume roots are created root-owned; hand them to the user. The
|
||||
# home directory itself is listed first so the mount points have a parent.
|
||||
systemd.tmpfiles.rules = [
|
||||
"d ${home} 0700 ${user} users -"
|
||||
]
|
||||
++ lib.mapAttrsToList (name: _: "d ${home}/${name} 0755 ${user} users -") folders;
|
||||
})
|
||||
]
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user