Files
nix-config-ryan4yin/modules
Ryan Yin 7dc4e7a39f feat(security): harden homelab SSH, services and audit trail
The homelab hosts accept root SSH with long-lived file keys, run several
exposed services with almost no systemd sandboxing, and keep no audit trail of
privileged actions. Close those three gaps, weighing each measure against its
cost instead of adopting a policy wholesale.

SSH
- Turn off KbdInteractiveAuthentication: nixpkgs defaults it to true and PAM
  then still accepts the Unix password despite PasswordAuthentication = false.
- authorizedKeysInHomedir = false: only keys declared in Nix take effect;
  youko keeps Gitea's forced-command file through `Match User gitea`.
- Pin aquamarine's passphrase-free remote-builder keys to
  `restrict,command="nix-daemon --stdio --store daemon"`, so builds run in the
  system daemon instead of an audited root login session.

systemd sandboxing
- Add the mylib.systemdHardening preset and apply it to the exposed, weakly
  sandboxed services: caddy 7.8 -> 1.5, vmalert 8.2 -> 1.4, rustfs 6.6 -> 1.4,
  whisper-asr 7.7 -> 1.6. An eval test pins the key restrictions.
- Rejected: a global all-keys policy (<=0.2 score gains on services nixpkgs
  already sandboxes) and per-service confinement (bind paths to maintain).

auditd on all four hosts, reusing nixpkgs' loader and unit
- Audit login sessions only: a first `-a never,task -F auid=unset` rule keeps
  services out of the per-syscall audit path. A compromised service is
  therefore unrecorded until it opens a session.
- Record root commands, credential and host-key access, writes to SSH, account,
  PAM, Nix-trust and audit configuration, module loads and session denials.
- Rejected: global denial logging, service-UID watches and
  --loginuid-immutable (the kernel already records loginuid changes).

Verified on all four hosts after deployment: zero failed units, k3s 6/6 Ready,
and the exposed services healthy.

Assisted-by: Claude Code (claude-opus-5-5)
2026-10-31 01:09:15 +08:00
..
2026-10-28 13:51:16 +08:00

NixOS / Nix-Darwin's Submodules

This directory contains modular NixOS and Nix-Darwin configurations organized by platform and functionality.

Current Structure

modules/
├── README.md
├── base/                    # Common configuration for all platforms
│   ├── default.nix
│   ├── fonts.nix           # System font configuration
│   ├── nix.nix            # Nix package manager settings
│   ├── overlays.nix       # Package overlays
│   ├── packages.nix       # Essential system packages
│   ├── security.nix       # Basic security settings
│   └── users.nix          # User management
├── darwin/                  # macOS-specific modules
│   ├── README.md
│   ├── apps.nix           # macOS applications
│   ├── default.nix
│   ├── nix-core.nix       # Core Nix configuration
│   ├── security.nix       # macOS security settings
│   ├── ssh.nix           # SSH configuration
│   ├── system.nix        # System-level settings
│   └── users.nix         # macOS user management
└── nixos/                   # NixOS-specific modules
    ├── base/               # Base NixOS configuration
    │   ├── auditd.nix     # Audit trail for root sessions and credentials
    │   ├── btop.nix       # System resource monitor
    │   ├── btrbk.nix      # Local btrfs snapshots
    │   ├── core.nix       # Core system settings
    │   ├── default.nix
    │   ├── i18n.nix       # Internationalization
    │   ├── locate.nix     # locate/updatedb file search
    │   ├── monitoring.nix # System monitoring
    │   ├── networking/    # Network configuration
    │   ├── nix.nix        # Nix settings
    │   ├── packages.nix   # System packages
    │   ├── restic-backup.nix # Encrypted off-host backups (see ../BACKUP.md)
    │   ├── ssh.nix        # SSH daemon configuration
    │   ├── trash.nix      # Trash retention cleanup
    │   ├── user-group.nix # User and group management
    │   └── zram.nix       # ZRAM swap configuration
    ├── desktop.nix         # Desktop environment configuration
    ├── desktop/            # Desktop-specific modules
    │   ├── canokey.nix    # CanoKey hardware token
    │   ├── computer-use.nix # Headless X11/i3 session for AI agents
    │   ├── default.nix
    │   ├── fhs.nix        # FHS environment
    │   ├── fonts.nix      # Desktop fonts
    │   ├── gaming.nix     # Gaming support
    │   ├── misc.nix       # Miscellaneous desktop settings
    │   ├── networking/    # Network-related desktop configs
    │   ├── nix.nix        # Desktop Nix settings
    │   ├── peripherals.nix # Peripheral device configuration
    │   ├── power.nix      # Power management
    │   ├── security.nix   # Desktop security settings
    │   ├── ssh.nix        # Desktop SSH configuration
    │   ├── containers.nix # Container engines (podman/docker)
    │   └── xdg.nix       # XDG base directory settings
    └── server/             # Server-specific modules
        ├── qemu-guest-hardware-configuration.nix
        ├── qemu-guest.nix  # VM guest base module (libvirt/QEMU guests)
        ├── server-aarch64.nix
        └── server.nix

System hardening modules (kernel baseline, AppArmor, app sandboxes) live under ../hardening/.

Module Categories

1. Base Modules (base/)

Common configuration shared between NixOS and macOS:

  • System fonts and localization
  • Essential packages and tools
  • Basic security settings
  • User management
  • Package overlays

2. macOS Modules (darwin/)

macOS-specific configuration:

  • macOS applications and system settings
  • Security configurations tailored for macOS
  • SSH and system-level settings
  • Package compatibility fixes

3. NixOS Modules (nixos/)

Platform-specific NixOS configuration:

  • Base: Core system settings and services
  • Desktop: Desktop environment and GUI applications
  • Server: Server-specific optimizations and services

Usage

There is no automatic platform detection. Each host's entry under outputs/<system>/src/ lists its imports explicitly:

  • NixOS Systems: import nixos/ modules
  • macOS Systems: import darwin/ modules
  • Both: import base/ modules for shared configuration