No description
  • Nix 94.3%
  • Shell 5.7%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Dimitrije Petkovic 3bacb91707 opencloud rclone
2026-10-22 15:18:41 +02:00
modules opencloud rclone 2026-10-22 15:18:41 +02:00
.gitignore initial commit 2026-10-04 16:12:07 +02:00
flake.lock some cleanup 2026-10-22 14:43:33 +02:00
flake.nix initial commit 2026-10-04 16:11:49 +02:00
README.md Initialize README 2026-10-04 16:14:46 +02:00

NixOS configuration (dendritic pattern, flake-parts)

One repo for the whole laptop: system, Home Manager, Niri, DMS and the programs I use. Organized by feature, not by module type.

How it works

  • flake.nix declares inputs and calls flake-parts with import-tree ./modules. It never lists features.
  • Every .nix file under modules/ is a flake-parts module. import-tree finds them automatically. Non-.nix files (like config.kdl) sit next to them and are ignored. Paths containing /_ are skipped.
  • Files write NixOS and Home Manager modules into a shared registry: flake.modules.nixos.<target> and flake.modules.homeManager.<target>. Several files can write to the same target and the module system merges them.
  • Targets are laptop (the NixOS host) and dimi (the Home Manager user). A feature enables itself just by existing in the tree.
  • New files must be git added before Nix can see them.

Layout

flake.nix            inputs + mkFlake (inputs can only live here)
modules/
  flake-parts.nix    plumbing: flakeModules.modules, systems
  hosts/laptop/      assembles the machine (configuration.nix, hardware.nix)
  users/dimi/        the account and Home Manager baseline, general packages
  system/            host-wide plumbing, one flat file per concern
  features/          one directory per tool, with native config files beside it

Rule of thumb: a directory when a tool has companion files (config.kdl, foot.ini), a flat file for plumbing.

Native configs stay native (KDL, INI, JSONC, fish). Home Manager links them with xdg.configFile."<path>".source = ./file; and they are read-only store symlinks.

Daily use

nh os switch          # rebuild and activate
nh os test            # activate without making it the boot default
nh os boot            # build for next boot
nh clean all          # garbage collect (also runs weekly)
nix flake update      # update inputs, then switch

Checks before switching:

git add -A
nixos-rebuild build --flake .#laptop

Adding a feature

  1. Create modules/features/<name>/default.nix.
  2. Write into the registry:
{
  flake.modules.nixos.laptop = { /* system part */ };
  flake.modules.homeManager.dimi = { pkgs, ... }: { /* user part */ };
}
  1. Put native config files next to it and link them with xdg.configFile.
  2. git add -A, then nh os switch.

Header rules: the outer function header ({ inputs, config, ... }:) is only needed if the file reads from flake-parts. The inner header ({ pkgs, ... }:) is only needed if the module uses NixOS or Home Manager arguments.

To disable a feature, move its directory out of modules/ or prefix it with _.

Reinstalling from scratch

Boot the NixOS installer, then:

  1. Partition, format and mount the target at /mnt (boot partition at /mnt/boot).

  2. Clone this repo, for example into /mnt/home/dimi/nixos.

  3. Regenerate the hardware config. Disk UUIDs change on a fresh install, so the committed hardware.nix will not boot.

    nixos-generate-config --root /mnt --show-hardware-config
    

    Paste the output into modules/hosts/laptop/hardware.nix, inside the wrapper and without the generated file's own header line:

    {
      flake.modules.nixos.laptopHardware =
        { config, lib, pkgs, modulesPath, ... }:
        {
          # body of the generated file goes here
        };
    }
    
  4. Install from the flake:

    git add -A
    nixos-install --flake /mnt/home/dimi/nixos#laptop
    

    If flakes are not enabled in the installer, run it with NIX_CONFIG="experimental-features = nix-command flakes".

  5. Set the password before rebooting, and fix ownership of the clone:

    nixos-enter --root /mnt -c 'passwd dimi'
    nixos-enter --root /mnt -c 'chown -R dimi:users /home/dimi/nixos'
    
  6. Reboot and log in. Restore personal data from backup.

The repo is expected at ~/nixos (programs.nh.flake points there).

First-switch notes

  • The old generation stays in the systemd-boot menu. The timeout is 1 second: tap Space or an arrow key at power-on to pick an older generation.
  • Ctrl+Alt+F2 gives a text login if the greeter or Niri fails.
  • home-manager.backupFileExtension = "backup" renames pre-existing files that would block Home Manager. If a .backup already exists at the same path, delete it by hand.
  • system.stateVersion and home.stateVersion must never be changed.