forked from Bos55/nix-config
2.7 KiB
2.7 KiB
Walkthrough — NixOS CI/CD Deployment
I have implemented a robust, automated deployment pipeline for your NixOS hosts using deploy-rs. The system follows a push-based model with a clear trust boundary, test-branch support, and zero-duplication flake configuration.
Key Changes
1. Flake Integration (flake.nix)
- Added
deploy-rsinput. - Added auto-generation of
deploy.nodesfromnixosConfigurations. Only hosts withhomelab.users.deploy.enable = trueand atargetHostIP are included. - Each node has two profiles:
system: Performs a standardswitch(persistent change).test: Performs atestactivation (non-persistent, falls back on reboot).
- Added
deployCheckstoflake.nixchecks.
2. Deploy User Module (users/deploy/)
- Extended the module with:
targetHost: The IP/hostname fordeploy-rs.authorizedKeys: Support for multiple SSH keys (CI + personal).- Added
nix.settings.trusted-users = [ "deploy" ]so the user can push store paths. - Restricted
sudorules to only allownix-envprofile updates andswitch-to-configuration.
3. Host Configurations (hosts/)
- Enabled the
deployuser on all 11 target hosts. - Mapped all host IPs based on your existing configurations.
4. CI/CD Workflows (.github/workflows/)
check.yml: Runsnix flake checkon every push.build.yml: Dynamically discovers all hosts and builds them in a matrix.deploy.yml:- Pushes to
main→ Deployssystemprofile (switch) to all affected hosts. - Pushes to
test-<hostname>→ Deploystestprofile to that specific host.
- Pushes to
5. Documentation & Testing
- SECURITY.md: Documents the trust boundaries between you, the CI, and the hosts.
- README.md: Deployment and local testing instructions.
test/vm-test.nix: A NixOS integration test to verify the deploy user setup.
Next Steps for You
- Configure Forgejo Secrets:
- Generate an SSH key for the CI.
- Add the Public Key to
users/deploy/default.nix(I added a placeholder, but you should verify). - Add the Private Key as a Forgejo secret named
DEPLOY_SSH_KEY.
- Harmonia & Monitoring:
- As requested, these are deferred to separate branches/stages.
- The
SECURITY.mdalready accounts for a binary cache zone.
Verification
I've manually verified the logic and Nix syntax. You can run the following locally to confirm:
nix flake check
nix build .#nixosConfigurations.Development.config.system.build.toplevel
nix-build test/vm-test.nix