This repository contains all of my personal configurations. You are welcome to use my configurations!
The way things are structured here is:
- config: This folder contains all configurations. It is organized
into the following subdirectories:
- machines/<name>: These folders contain
machine-specific configurations. Each folder should contain a
default.nix
, which is the entry point to the nixos configuration (this file is used as/etc/nixos/configuration.nix
). - modules: The meat of the configuration, this directory contains all the different configs for the OS, services, and applications. For the most part, modules in here are not actually loaded directly but instead collected into profiles, which are consumed by machine configurations (see below).
- profiles: This directory contains collections of modules packaged into common configuration sets. For the most part, machine configs import profiles, which then import modules.
- machines/<name>: These folders contain
machine-specific configurations. Each folder should contain a
- lib: This folder contains various utility functions that are used throughout the codebase.
- modules: This folder contains custom abstract configuration modules. They provide configuration for programs and systems that are missing in nixos or home-manager. In some cases, things in here are things I’d eventually like to polish off and send as pull requests to nixos or home-manager. In other cases they are experimental ideas that likely don’t actually belong upstream, like configuring the whole system’s color theme in one place.
- overlays: This directory contains nixpkgs overlays.
- pkgs: This directory contains custom packages.
To initialize a new machine into the network, follow these steps:
- Follow the NixOS installation guide to install & boot into a minimal bootable
NixOS on the new machine. Make sure to set the hostname, and make sure to
enable sshd. Also make sure your ssh key is authorized to login as root.
For example, the
configuration.nix
may look like:{ config, pkgs, ... }: { imports = [ ./hardware-configuration.nix ]; networking.hostName = "foobar"; services.sshd.enable = true; users.users.root.openssh.authorizedKeys.keys = [ "..." ]; }
- Create a new machine configuration in this repository for the new machine (make sure the folder name for the machine configuration matches the hostname of the new machine).
- Deploy the configuration to the new machine:
nix-shell --run 'deploy --on <new machine>'
This one is pretty simple:
nix-shell --run deploy
You can also deploy to only the machines you want to touch:
nix-shell --run 'deploy --on crux'
While this isn’t strictly necessary, with this configuration you can remove your nixpkgs channels–this configuration manages nixpkgs versions (and other dependencies) via niv. To remove the channels that NixOS installs by default, run:
nix-channel remove nixpkgs
The way this repository is able to work without channels has two parts:
NIX_PATH
is overridden when deploying in shell.nix. This ensures that, when deploying, the version of nixpkgs pinned by niv is used.- The system nix path is set in nix/default.nix. This enables using things
like
nix-shell -p foo
or<nixpkgs>
on a deployed machine, with a guarantee that the version ofnixpkgs
used for those tools is the same as the version that was deployed to the system.