Question
Is there a way to compose multiple flake-based system configurations where the base configuration is in a fixed location (e.g. /etc/nixos/flake.nix
or some predefined flake registry alias) and the overlay configuration is copied to an arbitrary disk location at runtime?
Background
When using CI/CD systems managed by Nix (e.g. NixOS, non-NixOS Linux distributions + system-manager, macOS + nix-darwin), a user might want to layer their own system modules/configurations on top of the provided ones describing the base CI/CD environment.
For example, the base CI/CD system might have a minimal set of system services up and running but a specific repository’s CI/CD jobs may want extra virtualization system services (e.g. Docker daemon, libvirtd), additional kernel modules, or different driver versions (e.g. PCIe device driver testing).
Some of the out-of-the-box services, however, can’t be restarted when applying the user-defined system configuration (with nixos-rebuild
/system-manager
/darwin-rebuild switch
). For example, GitLab Runner’s autoscaling executors work by having a runner manager SSH into a (usually ephemeral) runner. Restarting sshd
on the runner will break the connection and unintentionally fail the CI/CD job.
GitLab Runner
In the context of GitLab Runner specifically, the repository a CI/CD job is for is cloned to a dynamic path (docs). For example, a setup using the instance
auto-scaling executor on AWS EC2 might have a runner that looks like this:
/
│ # GitLab Runner build directory.
└── builds/
└── {runner token key}/
└── {concurrent project ID}/
└── {namespace}/
│ # 📍 CI/CD job script working directory.
└── {project name}/
│ # Clojure project.
├── inputs/
│ └── main/
│ └── clojure/
│ └── hello.cljc
├── bb.edn
├── deps.edn
│
│ # Nix configuration.
├── flake.nix
└── flake.lock
Ideally, there’s some way to refer to the base system configuration flake (e.g. /etc/nixos/flake.nix
or some predefined flake registry alias) in the project’s flake such that:
- The base system configuration and repository’s system configuration inputs aren’t mixed (i.e. they can use their own
nixpkgs
revisions).- This is to prevent applies from restarting
sshd
and other system services that maintain the job connection.
- This is to prevent applies from restarting
- Doesn’t require users to write files/values to magical places.
- Essentially, users only need to do
nixos-rebuild
/system-manager
/nix-darwin switch --flake .
in their job scripts.
- Essentially, users only need to do
Maybe there’s some magic we can do with nixPath
or extraArgs
/specialArgs
?