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:
Claude committed 2026-10-11 12:38:52 +00:00
1 parent c76925b3ba
commit 0ce9943d56
21 files changed
+972 -4

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
# Bootloader: lanzaboote (Secure Boot) or plain systemd-boot, plus kernel.
{
config,
lib,
pkgs,
...
}:
let
cfg = config.my.boot;
in
{
options.my.boot.secureBoot.enable = lib.mkEnableOption ''
Secure Boot through lanzaboote. Keys live in /var/lib/sbctl (create them
with `sbctl create-keys` before the first boot). When disabled the system
uses plain systemd-boot
'';
config = lib.mkMerge [
{
boot = {
loader.efi.canTouchEfiVariables = true;
initrd.systemd.enable = true;
kernelPackages = lib.mkDefault pkgs.linuxPackages_latest;
};
}
(lib.mkIf cfg.secureBoot.enable {
boot = {
lanzaboote = {
enable = true;
pkiBundle = "/var/lib/sbctl";
configurationLimit = 10;
};
# lanzaboote installs the boot entries itself.
loader.systemd-boot.enable = lib.mkForce false;
};
environment.systemPackages = [ pkgs.sbctl ];
})
(lib.mkIf (!cfg.secureBoot.enable) {
boot.loader.systemd-boot = {
enable = true;
configurationLimit = 10;
editor = false;
};
})
];
}
+57
View File
@@ -0,0 +1,57 @@
# Time zone, locale and keyboard layout (also used by the console and by the
# home-manager Hyprland module through osConfig).
{ config, lib, ... }:
let
cfg = config.my.locale;
inherit (lib) mkOption types;
in
{
options.my.locale = {
timeZone = mkOption {
type = types.str;
example = "Europe/Moscow";
description = "IANA time zone name.";
};
defaultLocale = mkOption {
type = types.str;
default = "en_US.UTF-8";
description = "Default system locale (LANG).";
};
keyboardLayouts = mkOption {
type = types.listOf types.str;
default = [ "us" ];
example = [
"us"
"ru"
];
description = "XKB layouts, in switching order.";
};
keyboardOptions = mkOption {
type = types.listOf types.str;
default = [ ];
example = [ "grp:alt_shift_toggle" ];
description = "XKB options such as the layout toggle shortcut.";
};
};
config = {
time.timeZone = cfg.timeZone;
i18n = {
inherit (cfg) defaultLocale;
# Russian stays available for apps and games even with an English UI.
extraLocales = [ "ru_RU.UTF-8/UTF-8" ];
};
services.xserver.xkb = {
layout = lib.concatStringsSep "," cfg.keyboardLayouts;
options = lib.concatStringsSep "," cfg.keyboardOptions;
};
# TTY and initrd keymap follow the XKB layout above.
console.useXkbConfig = true;
};
}
+8
View File
@@ -0,0 +1,8 @@
# NetworkManager with the default (closed) firewall. The user joins the
# `networkmanager` group in users.nix.
{
networking = {
networkmanager.enable = true;
firewall.enable = true;
};
}
+54
View File
@@ -0,0 +1,54 @@
# Nix daemon settings, binary caches, garbage collection and flake registry.
{
config,
inputs,
...
}:
{
nix = {
settings = {
experimental-features = [
"nix-command"
"flakes"
];
auto-optimise-store = true;
# root is already trusted by default; this adds the admin group.
trusted-users = [ "@wheel" ];
warn-dirty = false;
# Same caches as flake.nixConfig, so the system keeps using them after
# install without the "untrusted flake settings" prompt.
extra-substituters = [
"https://nix-community.cachix.org"
"https://noctalia.cachix.org"
];
extra-trusted-public-keys = [
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
"noctalia.cachix.org-1:pCOR47nnMEo5thcxNDtzWpOxNFQsBRglJzxWPp3dkU4="
];
};
gc = {
automatic = true;
dates = "weekly";
options = "--delete-older-than 14d";
};
# `nix shell nixpkgs#foo` and <nixpkgs> use the exact nixpkgs of this flake
# instead of fetching a different revision.
channel.enable = false;
registry.nixpkgs.flake = inputs.nixpkgs;
nixPath = [ "nixpkgs=${inputs.nixpkgs}" ];
};
programs = {
# Nicer `nixos-rebuild` front-end that knows where the flake lives.
nh = {
enable = true;
flake = "/home/${config.my.user.name}/nixos-config";
};
# Lets prebuilt binaries (editors' language servers, game launchers) run.
nix-ld.enable = true;
};
}
+89
View File
@@ -0,0 +1,89 @@
# The primary (only) interactive user.
{
config,
lib,
pkgs,
...
}:
let
cfg = config.my.user;
inherit (lib) mkOption types;
passwordSecret = "${cfg.name}-password";
hasPasswordSecret = config.age.secrets ? ${passwordSecret};
in
{
options.my.user = {
name = mkOption {
type = types.str;
example = "faumaray";
description = "Login name of the primary user.";
};
fullName = mkOption {
type = types.str;
description = "Display name (GECOS), also used for git.";
};
email = mkOption {
type = types.str;
description = "E-mail address, used for git.";
};
uid = mkOption {
type = types.int;
default = 1000;
description = "Numeric user id.";
};
extraGroups = mkOption {
type = types.listOf types.str;
default = [ ];
description = "Groups in addition to the ones every desktop user gets.";
};
sshAuthorizedKeys = mkOption {
type = types.listOf types.str;
default = [ ];
description = "Public keys allowed to log in over SSH.";
};
};
config = {
users.mutableUsers = true;
users.users.${cfg.name} = {
isNormalUser = true;
inherit (cfg) uid;
description = cfg.fullName;
extraGroups = [
"wheel"
"networkmanager"
"video"
"audio"
"input"
"render"
]
++ lib.optional config.my.gaming.enable "gamemode"
++ cfg.extraGroups;
shell = pkgs.zsh;
openssh.authorizedKeys.keys = cfg.sshAuthorizedKeys;
# Real password comes from agenix; otherwise a throwaway one so the first
# boot can never lock the user out.
hashedPasswordFile = lib.mkIf hasPasswordSecret config.age.secrets.${passwordSecret}.path;
initialPassword = lib.mkIf (!hasPasswordSecret) "changeme";
};
# Required by `shell = pkgs.zsh` (puts zsh into /etc/shells).
programs.zsh.enable = true;
security.sudo.wheelNeedsPassword = true;
warnings = lib.optional (!hasPasswordSecret) ''
User "${cfg.name}" has the temporary password "changeme". Run `passwd` after
the first login, or add secrets/${passwordSecret}.age (hashed with
`mkpasswd -m yescrypt`, encrypted with agenix) and `git add` it.
'';
};
}
+24
View File
@@ -0,0 +1,24 @@
# Every NixOS module of this flake (exported as `nixosModules.default`).
# Each file declares its own `my.*` options and is inert until enabled.
{
imports = [
./core/nix.nix
./core/boot.nix
./core/locale.nix
./core/users.nix
./core/networking.nix
./hardware/amd.nix
./hardware/disks.nix
./security/secrets.nix
./security/ssh.nix
./desktop/hyprland.nix
./desktop/noctalia.nix
./desktop/audio.nix
./desktop/fonts.nix
./gaming/steam.nix
];
}
+24
View File
@@ -0,0 +1,24 @@
# PipeWire as the single audio server (ALSA, PulseAudio and JACK clients).
{ config, lib, ... }:
{
config = lib.mkIf config.my.desktop.hyprland.enable {
services = {
pipewire = {
enable = true;
alsa = {
enable = true;
# 32-bit ALSA clients: Wine/Proton games.
support32Bit = true;
};
pulse.enable = true;
jack.enable = true;
wireplumber.enable = true;
};
pulseaudio.enable = false;
};
# Lets PipeWire take realtime scheduling for low-latency audio.
security.rtkit.enable = true;
};
}
+27
View File
@@ -0,0 +1,27 @@
# System fonts and the default families fontconfig falls back to.
{
config,
lib,
pkgs,
...
}:
{
config = lib.mkIf config.my.desktop.hyprland.enable {
fonts = {
packages = with pkgs; [
noto-fonts
noto-fonts-cjk-sans
noto-fonts-color-emoji
inter
nerd-fonts.jetbrains-mono
nerd-fonts.symbols-only
];
fontconfig.defaultFonts = {
monospace = [ "JetBrainsMono Nerd Font" ];
sansSerif = [ "Inter" ];
emoji = [ "Noto Color Emoji" ];
};
};
};
}
+74
View File
@@ -0,0 +1,74 @@
# Hyprland session: UWSM-managed compositor, greetd login, portals, keyring and
# the small system services a desktop needs. Noctalia, audio and fonts are
# separate files gated on the same option.
{
config,
lib,
pkgs,
...
}:
let
cfg = config.my.desktop.hyprland;
in
{
options.my.desktop.hyprland.enable = lib.mkEnableOption "the Hyprland desktop session";
config = lib.mkIf cfg.enable {
# package/portalPackage stay default: the overlay swaps in the flake builds.
programs.hyprland = {
enable = true;
withUWSM = true;
xwayland.enable = true;
};
services.greetd = {
enable = true;
# Keeps boot messages from drawing over the greeter.
useTextGreeter = true;
settings.default_session = {
command = lib.concatStringsSep " " [
(lib.getExe pkgs.tuigreet)
"--time"
"--remember"
"--remember-user-session"
"--asterisks"
"--sessions ${config.services.displayManager.sessionData.desktops}/share/wayland-sessions"
];
user = "greeter";
};
};
xdg.portal.extraPortals = [ pkgs.xdg-desktop-portal-gtk ];
security.polkit.enable = true;
services.gnome.gnome-keyring.enable = true;
security.pam.services.greetd.enableGnomeKeyring = true;
programs.dconf.enable = true;
# Electron/Chromium apps use native Wayland.
environment.sessionVariables.NIXOS_OZONE_WL = "1";
# Removable drives and trash/mounts in the file manager.
services.udisks2.enable = true;
services.gvfs.enable = true;
hardware.bluetooth = {
enable = true;
powerOnBoot = true;
};
environment.systemPackages = with pkgs; [
wl-clipboard
cliphist
grim
slurp
brightnessctl
playerctl
pavucontrol
nautilus
hyprpicker
];
};
}
+19
View File
@@ -0,0 +1,19 @@
# Noctalia shell, system side. The user service is started by home-manager
# (modules/home), so `programs.noctalia.systemd` stays off here.
{
config,
lib,
pkgs,
...
}:
{
config = lib.mkIf config.my.desktop.hyprland.enable {
programs.noctalia = {
enable = true;
package = pkgs.noctalia;
# NetworkManager, Bluetooth, UPower and power-profiles-daemon, which the
# shell's panels talk to.
recommendedServices.enable = true;
};
};
}
+57
View File
@@ -0,0 +1,57 @@
# Steam + Proton, gamescope, gamemode and MangoHud.
{
config,
lib,
pkgs,
...
}:
let
cfg = config.my.gaming;
in
{
options.my.gaming.enable = lib.mkEnableOption "the gaming stack (Steam, Proton-GE, gamescope, gamemode)";
config = lib.mkIf cfg.enable {
programs = {
steam = {
enable = true;
remotePlay.openFirewall = true;
localNetworkGameTransfers.openFirewall = true;
dedicatedServer.openFirewall = false;
gamescopeSession.enable = true;
extraCompatPackages = [ pkgs.proton-ge-bin ];
protontricks.enable = true;
# Steam Input on Wayland (controllers acting as keyboard/mouse).
extest.enable = true;
};
gamescope = {
enable = true;
# Lets gamescope raise its own priority.
capSysNice = true;
};
gamemode = {
enable = true;
settings = {
general.renice = 10;
gpu = {
apply_gpu_optimisations = "accept-responsibility";
gpu_device = 0;
amd_performance_level = "high";
};
};
};
};
hardware.steam-hardware.enable = true;
environment.systemPackages = with pkgs; [
mangohud
protonplus
];
# Some Proton games exhaust the default map count and crash.
boot.kernel.sysctl."vm.max_map_count" = 2147483642;
};
}
+71
View File
@@ -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}" ];
})
]
);
}
+216
View File
@@ -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;
})
]
);
}
+72
View File
@@ -0,0 +1,72 @@
# agenix secrets. Every secret file is optional: a secret is only declared when
# its .age file exists in `my.secrets.dir`, so a fresh clone still evaluates.
#
# <user>-password.age hashed login password (mkpasswd -m yescrypt)
# ssh-<key>.age private SSH key, installed for the user (home-manager
# links it to ~/.ssh/<key>)
{
config,
inputs,
lib,
pkgs,
...
}:
let
cfg = config.my.secrets;
user = config.my.user.name;
secretFile = name: cfg.dir + "/${name}.age";
exists = name: builtins.pathExists (secretFile name);
passwordSecrets = lib.optionalAttrs (exists "${user}-password") {
"${user}-password" = {
file = secretFile "${user}-password";
mode = "0400";
};
};
sshSecrets = lib.listToAttrs (
map (
key:
lib.nameValuePair "ssh-${key}" {
file = secretFile "ssh-${key}";
owner = user;
mode = "0400";
}
) (lib.filter (key: exists "ssh-${key}") cfg.userSshKeys)
);
in
{
options.my.secrets = {
enable = lib.mkEnableOption "agenix secrets from the repository's secrets/ directory";
dir = lib.mkOption {
type = lib.types.path;
default = ../../../secrets;
defaultText = lib.literalExpression "../../../secrets";
description = ''
Directory holding the *.age files. In a flake only files tracked by git
are visible, so `git add` new secrets before building.
'';
};
userSshKeys = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ "id_ed25519" ];
description = "SSH key names; each maps to secrets/ssh-<name>.age if present.";
};
};
config = lib.mkIf cfg.enable {
# The host key is generated on the install USB (`create-keys`) and copied
# to the target, so secrets can be decrypted on the very first boot.
age.identityPaths = [ "/etc/ssh/ssh_host_ed25519_key" ];
age.secrets = passwordSecrets // sshSecrets;
environment.systemPackages = [
inputs.agenix.packages.${pkgs.stdenv.hostPlatform.system}.default
pkgs.age
];
};
}
+21
View File
@@ -0,0 +1,21 @@
# Key-only OpenSSH server. The host key is also the agenix identity.
{
services.openssh = {
enable = true;
openFirewall = true;
settings = {
PasswordAuthentication = false;
KbdInteractiveAuthentication = false;
PermitRootLogin = "no";
};
hostKeys = [
{
type = "ed25519";
path = "/etc/ssh/ssh_host_ed25519_key";
}
];
};
# The keyring (NixOS) and home-manager provide the agent.
programs.ssh.startAgent = false;
}