Personal dotfiles managed with a hybrid approach using GNU Stow and Nix.
Designed to:
- Work on non-Nix (that is, imperative package manager-powered) systems with GNU Stow
- Integrate cleanly into Nix-based setups (Home Manager / NixOS)
- how to
stowsomewhere other than$HOME:
sudo stow -t <target_dir> <source_dir>
Nix has a somewhat steep learning curve. These notes are primarily for myself to help with building a stable mental model of how the system is structured.
2. Nix language
3. NixOS
The main question Nix answers:
how does one build and deploy software in a fully reproducible, conflict-free way?
Nix package manager is the central element of the solution. A "package" is just a Nix (the language) build expression
that produces some files in /nix/store with a name that includes a specific hash
based on all inputs used to build the package (as opposed to, for example, outputs that are used to
ensure the integrity of the build artefacts transferred over an untrusted channel)
Use case:
Replacement of the native package manager apt, pacman, etc.
How:
nix+flakes+home manager
(There's an outdated method that involves using nix-env. It is imperative and
results in configurations that are not easily reproducible)
-
Install
home manager:nix run home-manager/master -- init --switch- installation creates
~/.config/home-manager/home.nix - configure
home.nix(Nix language, declarative) - apply config:
home-manager switch
- installation creates
-
Flakes: use
flake.nixfile inside the Home Manager's working dir (~/.config/home-manager/flake.nix) Nix generatesflake.lock, pins the packages to a specific commit -
To update packages (e.g.
nixpkgsas named inflake.nix):nix flake update(if using flakes) ornix-channel --update- switch
Note:
Flakes address the class of problems similar to what Cargo.toml and package-json.lock do.
They are a modern way to pin particular versions of packages (and other inputs) used in
the (reproducible) system.
Home Manager is a layer on top of Nix that manages user packages and (optionally) dotfiles.
Points of concern:
programs.<program>.enableand BYOC (bring your own config) will create conflict as Home Manager will try to "own" the path.- external config files must live either inside Home Manager's dir or within
nix/store. The so-called pure evaluation has to be unset in order for absolute paths to work
TODO: write as you go
Why:
Reproducible system configuration: kernel, services, packages, config files.
Everything is described in configuration.nix
Running nixos-rebuild switch makes the system match the declaration exactly.
nix-shellwith ashell.nixdeclarationflakesdevShells