The code for this flake is designed to be as simple and readable as possible. It is also designed to support all of the features that I want from a personal flake:
- NixOS configurations for my hosts.
- Home Manager configurations for my hosts whether or not on NixOS.
- Development shells for my software projects.
- Packaged software not yet supported in nixpkgs.
Additionally, I want to impose some additional contraints upon this flake:
- Package definitions should be available to system configurations.
- Development shells should be available to system configurations.
- Nixpkgs should be configured to my needs and shared across configurations.
- The packages used by Home Manager on NixOS systems should be in sync.
This flake contains a small nix library that supports the needs of a flake. It is designed to load itself and support loading and working with nix modules. Additionally, it has configuration-specific helper functions for use with NixOS and Home Manager configurations.
The configurations in this flake have a specific structure, but none of the code in the flake and the library are tied to that structure. It can be used with any nix code that is stored in modules.
My NixOS and Home Manager configurations are split into configurations, profiles, and roles.
A NixOS or Home Manager configuration is a nix module containing a function
that can be used to configure a system (standard configuration format).
Additionally, the configurations in this repository are required to contain
a file called system
that specify the system they are expected to work with
(e.g. x86_64-linux
).
These are just collections of nix modules from the profiles specified below. They are a convenience to enable quickly composing related features into groups.
This is where any shareable configuration nix code belongs. These modules may be grouped into roles for consumption on multiple machines (e.g. desktop-only modules, laptop-only modules) or imported directly for machines with specific needs.
The library in this flake is broken down into three files:
This is the code that looks the most magic, and is the least written by me. It bootstraps itself using the module loading code, and then exports all of functionality from all of the files using nixpkgs extensibility.
This module consists of only two functions:
findModules
recurses through a directory to collect all nix modules contained within, and exports them all at the top level as an attribute set that maps module name to the path of the module.loadModules
takes a list of paths and returns an attribute set of path names to modules by callingfindModules
on each path.
This module contains three functions which are useful to the flake:
mkPackages
takes a nixpkgs input, a package configuration, a list of overlays, and a system (e.g.x86_64-linux
), then imports and configures the nixpkgs.mkHomeConfig
takes a configured nixpkgs import, an attribute set of module arguments (these become arguments to all modules in the configuration), the name of the configuration (unused argument but makes this function compatible with mapAttrs) and the path to nix module containing a Home Manager configuration.mkNixosConfig
takes a configured nixpkgs import, an attribute set of module arguments (these become arguments to all modules in the configuration), the name of the configuration (unused argument but makes this function compatible with mapAttrs) and the path to nix module containing a NixOS configuration.
These instructions are out of date. When I next bootstrap a machine, I will update them here. In the meantime, you can read an overview of the process:
- Follow the NixOS installation instructions in order to get started.
- Copy the bootstrap NixOS configuration from nixos-configs folder over the generated configuration files.
- Build the system with the bootstrapped configuration.
- Clone this flake into the user's home directory and follow the steps below.
- Install the Nix package manager
- Instantiate the home-manager command
- Use home-manager to install this flake
- Use sudo to install this flake's NixOS configuration.
F=--extra-experimental-features V="nix-command flakes" bash -c 'nix $F "$V" run home-manager -- $F "$V" switch --flake .#<hostname>'