Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

System

Platforms: The user, the account, Nix, git, the locale, the persistence registry and the Home Manager, Stylix and secrets adapters run on NixOS and nix-darwin. The bootloader, disko, impermanence, hardening, the kernel, networking and automatic upgrades are NixOS only. See Darwin.

Core system modules under othrys.system.*, located in modules/system/. Each is toggled by its own enable option (except user, which only declares the identity option) and configures a fundamental part of the machine.

The disk, impermanence, bootloader, and secrets modules have dedicated pages under System Infrastructure, and the rest are summarized here.

Available Modules

ModuleOptionDescription
User identityothrys.system.user.namePrimary user account name, required, replaces the legacy username specialArg
Usersothrys.system.usersUser account creation, shell, password wiring
Home Manager adapterothrys.system.users.homeManagerHands every module’s user configuration to Home Manager. Exported as nixosModules.home and not part of default, see Host Configuration
Localeothrys.system.localeTimezone, locale, console font/keymap (defaults are identity-neutral: UTC)
Auto-upgradeothrys.system.autoUpgradeUnattended nixos-rebuild from the fleet flake
Nixothrys.system.nixNix settings, GC/nh, substituters, optional Cachix
Kernelothrys.system.kernelKernel package selection (disabled → NixOS default kernel)
Hardeningothrys.system.hardeningOpt-in kernel and sysctl hardening profile, with the costly switches kept separate
Networkingothrys.system.networkingsystemd-networkd: per-interface DHCP/static + bridges/VLANs (router topology)
Gitothrys.system.gitGit identity and aliases (home-manager)
Persistenceothrys.system.persistenceThe persistence registry, and the system/user state declarations for impermanence
Impermanenceothrys.system.impermanenceRoot wipe on boot and the old-roots recovery tool. The bind mounts come from nixosModules.impermanence, which is not part of default, see Impermanence
Diskoothrys.system.diskoDisk layout with LUKS and BTRFS subvolumes, exported as nixosModules.disko and not part of default, see Disko
Bootloaderothrys.system.bootloaderLimine, systemd-boot or GRUB, with optional Secure Boot, see Bootloader & Secure Boot
Secretsothrys.system.secretssops-nix wiring and the manual-editing age identity, exported as nixosModules.secrets and darwinModules.secrets and not part of default, see Secrets Management
Themeothrys.themeThe palette, fonts, opacity and wallpaper every module reads, see Theming
Stylix adapterothrys.system.stylixStylix configured from othrys.theme, exported as nixosModules.stylix and darwinModules.stylix and not part of default
Shellothrys.system.shell.{bash,zsh,starship}Interactive shells and prompt, see Shell
Default editorothrys.system.defaultEditorThe command behind EDITOR and VISUAL, vim by default

On darwin, othrys.system.users writes only the home directory and the primary user, and the password, group and mutableUsers options have no effect there. othrys.system.users.uid exists only on darwin, where it hands the account to nix-darwin, and the generated reference marks it nix-darwin only. othrys.system.locale sets the timezone and LANG there, and its console options have no effect. See Darwin.

Notes

  • User identity: modules read config.othrys.system.user.name. It is a required option with no default and no username specialArg fallback, so set it per host. See the consumer contract in the repository AGENTS.md. The name starts with a lowercase letter or an underscore and continues with lowercase letters, digits, underscores and hyphens. Any other value, such as Alice, is refused at evaluation.
  • Home directory: the XDG user directories and the persisted home follow users.users.<name>.home, so a host that places the account outside /home sets that option and nothing else.
  • Git identity: othrys.system.git.name and othrys.system.git.email default to null and are required together on a host where Home Manager manages the primary user, since that is where the identity is written. Enabling git without them fails an assertion that names both options. A host without a managed user installs git and needs neither.
  • Bridge and vlan references: othrys.system.networking.interfaces.<name>.bridge and every entry of interfaces.<name>.vlans have to name a netdev the host declares, under bridges or vlans or as a netdev of that kind in systemd.network.netdevs. A name that matches none fails an assertion naming the interface and the missing netdev, where systemd-networkd would leave the port unconfigured without a report.
  • State version: othrys.system.nix.stateVersion is likewise required with no default. It records the release a host was first installed at, so the library cannot supply one on the host’s behalf.
  • Identity-neutral defaults: locale.timezone defaults to UTC and nix.nh.flake defaults to null; set them per host. These are examples of the library’s “sane, non-personal defaults” policy.

Auto-upgrade

Unattended nixos-rebuild from the fleet flake on a schedule (daily 04:00 by default, randomized delay so a fleet doesn’t stampede the repo host). Reboots are opt-in and window-confined, and failures push through othrys-notify when the notify module is enabled.

Signature verification

Verification is off by default. With it off, nixos-rebuild follows whatever flake resolves to and nothing checks a signature, so whoever can push to the repository or answer the fetch decides what the host runs as root.

With verify.enable on, flake stays unset and the host names a git URL instead. A oneshot unit, othrys-auto-upgrade-verify.service, fetches that URL and verifies the target before every upgrade. nixos-upgrade.service requires the unit and is ordered after it, so a failed verification means no rebuild. The unit carries the same othrys-notify failure hook as the upgrade. The rebuild then reads a local checkout of the verified commit and never the network.

othrys.system.autoUpgrade = {
  enable = true;
  verify = {
    enable = true;
    url = "https://example.com/alice/hosts.git";
    publicKeys = [./keys/alice.asc];
  };
};
  • What is verified: in commit mode the tip of verify.ref has to pass git verify-commit. Only the tip is checked, since a signer who signs a commit vouches for the history beneath it. In tag mode the highest tag matching verify.tagPattern by version sort has to pass git verify-tag, and the host upgrades to the commit it points at. A newer tag that is unsigned or lightweight stops upgrades until it is removed, because falling back to an older tag would let anyone with push access hold a host back.
  • Which keys count: only the files in verify.publicKeys, or the entries of verify.allowedSigners for format = "ssh". OpenPGP keys are imported into a keyring that exists for one run, and the unit reads no other git or GnuPG configuration. A signature in the format that is not configured fails. These keys are trust roots, so they belong in the host configuration. The generation a host currently runs fixes them, which means rotating a key takes a commit signed by a key that is still listed. The unit never takes a key from the repository it is verifying.
  • What the signature covers: the commit, which includes flake.lock. The lock file pins every input by hash, so one signature fixes every input along with the repository’s own files. Flags that let the evaluation or the build escape it (--update-input, --recreate-lock-file, --override-input, --override-flake, --option, --impure) fail an assertion when verify is on.
  • Staleness: a source that stops advancing verifies cleanly every night, so verify.maxAge (default 30 days) has the unit log a warning once the verified commit is older than that, and send a notification when the notify module is on. The upgrade still runs, and a notification that cannot be sent is logged as a second warning. Null turns the report off.
  • Rollback rule: the last verified commit id is kept in /var/lib/othrys-auto-upgrade-verify/last-verified. A new target that does not descend from it fails the unit, which stops a validly signed but older commit from being replayed. After a deliberate history rewrite, delete that file and the next run accepts the new history. The directory is persisted when impermanence is on.
  • Failure behaviour: any failure leaves the previous checkout in place, exits non-zero and logs one line naming the reason.

The fetch is anonymous, so the repository has to be readable without credentials. The unit is sandboxed like notify-failure@ but runs as root without capabilities, because Nix refuses to read a git repository owned by another user and the rebuild reads the checkout as root.

Options

  options.othrys.system.autoUpgrade = {
    enable = lib.mkEnableOption "unattended nixos-rebuild from the host configuration flake";

    flake = lib.mkOption {
      type = lib.types.nullOr lib.types.str;
      default = null;
      example = "github:example/hosts";
      description = "Flake URI the host upgrades from (the host configuration flake, not this library). Identity-shaped, set from the consuming host. Private repos need fetch credentials (e.g. a netrc via secrets). Nothing checks a signature on this path. Leave it null and use verify for that.";
    };

    dates = lib.mkOption {
      type = lib.types.str;
      default = "04:00";
      description = "systemd calendar expression for the upgrade timer (daily at 04:00 by default, since servers want security fixes promptly).";
    };

    allowReboot = lib.mkOption {
      type = lib.types.bool;
      default = false;
      description = "Reboot when the new generation requires it (kernel/systemd changes). Off by default, so enable deliberately with a rebootWindow.";
    };

    rebootWindow = lib.mkOption {
      type = lib.types.nullOr (lib.types.attrsOf lib.types.str);
      default = null;
      example = {
        lower = "03:00";
        upper = "05:00";
      };
      description = "Time window reboots are confined to (with allowReboot). Null reboots whenever the upgrade lands.";
    };

    randomizedDelaySec = lib.mkOption {
      type = lib.types.str;
      default = "30min";
      description = "Random delay added to the timer so a fleet doesn't hit the flake host simultaneously.";
    };

    flags = lib.mkOption {
      type = lib.types.listOf lib.types.str;
      default = [];
      description = "Extra flags passed to nixos-rebuild.";
    };

    verify = {
      enable = lib.mkEnableOption "signature verification of the host configuration repository before every upgrade";

      url = lib.mkOption {
        type = lib.types.str;
        example = "https://example.com/alice/hosts.git";
        description = "Git URL the verify unit fetches. The fetch is anonymous, so the repository has to be readable without credentials.";
      };

      ref = lib.mkOption {
        type = lib.types.str;
        default = "main";
        description = "Branch followed in commit mode. Its tip has to carry a good signature.";
      };

      mode = lib.mkOption {
        type = lib.types.enum ["commit" "tag"];
        default = "commit";
        description = "What carries the signature. commit verifies the tip of ref with git verify-commit. tag takes the highest tag matching tagPattern by version sort, verifies it with git verify-tag and upgrades to the commit it points at, so an unsigned newer tag stops upgrades until it is removed.";
      };

      tagPattern = lib.mkOption {
        type = lib.types.str;
        default = "v*";
        description = "Glob selecting the tags considered in tag mode.";
      };

      format = lib.mkOption {
        type = lib.types.enum ["openpgp" "ssh"];
        default = "openpgp";
        description = "Signature format that is accepted. A signature in the other format fails verification.";
      };

      maxAge = lib.mkOption {
        type = lib.types.nullOr lib.types.ints.positive;
        default = 30;
        example = 90;
        description = ''
          Days after which a verified commit counts as stale. A source that
          stops advancing verifies cleanly every night, so once the commit the
          host follows is older than this the unit logs a warning and, with
          the notify module on, sends a notification. The upgrade itself still
          runs. Null turns the report off.
        '';
      };

      publicKeys = lib.mkOption {
        type = lib.types.listOf lib.types.path;
        default = [];
        example = lib.literalExpression "[./keys/alice.asc]";
        description = "ASCII-armoured OpenPGP public key files, used when format is openpgp. These are the only keys whose signatures pass. A path literal is copied into the store, while a string such as \"/run/secrets/signer.asc\" is read at run time.";
      };

      allowedSigners = lib.mkOption {
        type = lib.types.nullOr lib.types.path;
        default = null;
        example = lib.literalExpression "./keys/allowed_signers";
        description = "OpenSSH allowed signers file, used when format is ssh. Path literals and runtime path strings are handled as in publicKeys.";
      };

      attribute = lib.mkOption {
        type = lib.types.str;
        default = config.networking.hostName;
        defaultText = lib.literalExpression "config.networking.hostName";
        description = "The nixosConfigurations attribute of the verified repository that the host builds.";
      };
    };
  };

Hardening

othrys.system.hardening is an opt-in profile. With enable off, which is the default, the module sets nothing. With it on, the host gets the sysctls below, which cost nothing on an ordinary workstation or server.

sysctlValueEffect
kernel.kptr_restrict2Kernel pointers are hidden from every user, root included
kernel.dmesg_restrict1Reading the kernel log needs CAP_SYSLOG
kernel.unprivileged_bpf_disabled1Only privileged processes load BPF programs
net.core.bpf_jit_harden2The BPF JIT blinds constants for all users
kernel.yama.ptrace_scope1A process attaches only to its own descendants
kernel.kexec_load_disabled1No new kernel can be loaded with kexec until reboot
net.ipv4.conf.{all,default}.rp_filter2Loose reverse path filtering
net.ipv4.conf.{all,default}.accept_redirects0ICMP redirects are ignored
net.ipv4.conf.{all,default}.secure_redirects0Redirects from listed gateways are ignored as well
net.ipv4.conf.{all,default}.send_redirects0The host sends no ICMP redirects
net.ipv6.conf.{all,default}.accept_redirects0IPv6 redirects are ignored
net.ipv4.conf.{all,default}.accept_source_route0Source-routed IPv4 packets are dropped
net.ipv6.conf.{all,default}.accept_source_route0Source-routed IPv6 packets are dropped
net.ipv4.tcp_syncookies1SYN cookies are used when the SYN queue overflows
net.ipv4.icmp_echo_ignore_broadcasts1Broadcast pings are ignored
net.ipv4.tcp_rfc13371A reset does not end a connection in TIME-WAIT
fs.suid_dumpable0A setuid process writes no core dump
fs.protected_fifos, fs.protected_regular2A FIFO or file in a sticky world-writable directory is not opened across owners
vm.unprivileged_userfaultfd0Only root uses userfaultfd
dev.tty.ldisc_autoload0Opening a tty loads no line discipline module
dev.tty.legacy_tiocsti0A process cannot push input into its terminal
kernel.perf_event_paranoid2Unprivileged perf sees user space only

The profile also adds three kernel parameters through othrys.system.hardening.kernelParams, which are slab_nomerge, page_alloc.shuffle=1 and vsyscall=none. A list option merges every definition, so a host changes them by setting that option and not by assigning boot.kernelParams. init_on_free=1 and debugfs=off are left out, since the first costs on every free and the second breaks tooling.

Reverse path filtering

rp_filter is loose (2) rather than strict (1). Strict mode drops a packet when the route back to its sender leaves through a different interface, which is the normal state of a Tailscale exit node client and of a multi-homed router. The kernel applies this check regardless of the firewall, so a strict sysctl would also undo the loose networking.firewall.checkReversePath that NixOS selects when othrys.services.tailscale is on. Loose mode still drops packets whose source is unreachable through any interface.

othrys.services.router assigns its own values, and they win over the profile. The kernel validates a packet with the higher of conf.all and the interface’s own value, so the router sets all to 0, its WAN interface to strict and everything else to loose. A router with the profile on keeps strict filtering on its WAN.

Overriding one value

Every sysctl is written at priority 900. That is above the mkDefault definitions NixOS ships for kernel.kptr_restrict and, under security.protectKernelImage, for kernel.kexec_load_disabled. It is below a plain assignment, so a host changes one value by assigning it, with no mkForce.

{
  othrys.system.hardening.enable = true;

  # A debugger has to attach to processes it did not start.
  boot.kernel.sysctl."kernel.yama.ptrace_scope" = 0;
}

The costly switches

Two further options stay off unless the host asks for them, because each one breaks something.

  • lockKernelModules sets security.lockKernelModules. No module loads after boot, so hardware plugged in later, and VPN or filesystem modules that were not loaded at boot, stop working until the next reboot. List the modules the host needs later in boot.kernelModules.
  • protectKernelImage sets security.protectKernelImage. Hibernation and kexec are disabled. Evaluation fails when the host sets boot.resumeDevice or passes resume= in boot.kernelParams.

The profile has no switch for unprivileged user namespaces. nixpkgs removed security.unprivilegedUsernsClone together with the hardened kernels that carried the sysctl. The remaining upstream switch, security.allowUserNamespaces, turns user namespaces off for every user and conflicts with the Nix build sandbox, so a host that wants it sets it directly.

Options

  options.othrys.system.hardening = {
    enable =
      lib.mkEnableOption "the kernel and sysctl hardening profile"
      // {
        description = ''
          Apply the low-cost kernel and network sysctl hardening profile. The
          profile is opt-in, and nothing is set while this is off.

          Every sysctl is written below the priority of a plain assignment, so a
          host overrides any single value by setting the same key under
          `boot.kernel.sysctl`. The values restrict kernel pointer and dmesg
          exposure, unprivileged BPF, ptrace and kexec, and turn off ICMP
          redirects and source routing.

          `rp_filter` is set to loose mode (2) rather than strict (1). Strict
          mode drops replies that arrive on a different interface from the
          route back to the sender, which breaks Tailscale exit nodes and
          multi-homed routers. It also overrides the loose
          `networking.firewall.checkReversePath` that the Tailscale module
          selects, since the kernel check runs regardless of the firewall.
          `othrys.services.router` assigns loose mode to `all` and `default`
          as well, and strict mode to its WAN interface alone.

          `lockKernelModules` and `protectKernelImage` are separate options
          because each one breaks something, and neither is implied by
          `enable`.
        '';
      };

    kernelParams = lib.mkOption {
      type = lib.types.listOf lib.types.str;
      default = ["slab_nomerge" "page_alloc.shuffle=1" "vsyscall=none"];
      description = ''
        Kernel command-line parameters the profile adds. The defaults cost
        nothing measurable: slab_nomerge keeps caches apart so an overflow in
        one stays in it, page_alloc.shuffle randomises the page allocator's
        free lists, and vsyscall=none removes the fixed-address legacy
        syscall page. init_on_free and debugfs=off are not here, since the
        first costs on every free and the second breaks tooling, and a host
        that wants them adds them. Set the list to change it, since a list
        option merges rather than overrides.
      '';
    };

    lockKernelModules = lib.mkOption {
      type = lib.types.bool;
      default = false;
      description = ''
        Set `security.lockKernelModules`, which disables kernel module loading
        once the system has booted.

        No module can load after boot. Hardware plugged in later, and VPN or
        filesystem modules that were not loaded at boot, stop working until
        the next reboot. List every module the host needs later in
        `boot.kernelModules` so it is loaded before the lock.
      '';
    };

    protectKernelImage = lib.mkOption {
      type = lib.types.bool;
      default = false;
      description = ''
        Set `security.protectKernelImage`, which prevents the running kernel
        image from being replaced.

        Hibernation and kexec are disabled. Evaluation fails on a host that
        sets `boot.resumeDevice` or passes `resume=` in `boot.kernelParams`,
        since such a host would lose the ability to resume.
      '';
    };
  };