This repository demonstrates how to build and cache Nix Home Manager configurations using FlakeHub Cache and GitHub CI for both macOS and Ubuntu systems. It showcases a powerful approach to deploying Nix configurations by pre-building and caching fully evaluated closures.
The repository uses FlakeHub Cache to store pre-built Nix closures of Home Manager configurations.
This enables rapid deployment of configurations using the fh
CLI tool, significantly reducing the time and computational resources needed during deployment.
-
Configuration Structure
- The repository defines Home Manager configurations for both macOS and Ubuntu in a single flake
- Configurations are parameterized by
username
andhostname
- System-specific packages are conditionally included based on the target platform
-
Build Process
- GitHub CI builds the configurations for both platforms
- The build process fully evaluates and realizes the Nix closures
- FlakeHub Cache stores these pre-built closures for later use
-
Deployment
- Users can quickly deploy configurations using:
# Resolve the pre-built closure from FlakeHub Cache fh resolve "determinatesystems/home-manager-example/*#homeConfigurations.linuxUsername@linuxHostname" /nix/store/4rl65vxv427k17nv3fkgqjgpah548b9j-home-manager-generation # Apply the configuration fh apply home-manager /nix/store/4rl65vxv427k17nv3fkgqjgpah548b9j-home-manager-generation
Traditional Nix deployments require each machine to:
- Evaluate the Nix expressions
- Realize the closures
- Download or build missing dependencies
Using pre-built closures from FlakeHub Cache offers several advantages:
- Faster Deployments: Skip local evaluation and building
- Reduced Resource Usage: No need for local compilation
- Consistent Environments: Guarantee identical outputs across machines
- Lower Bandwidth: Download only the required closure
- CI-Verified: Configurations are pre-tested in CI
.
├── flake.nix # Main flake configuration
├── home-manager/
│ └── default.nix # Home Manager configuration
└── lib/ # Helper functions
inputs = {
determinate.url = "https://flakehub.com/f/DeterminateSystems/determinate/*";
fh.url = "https://flakehub.com/f/DeterminateSystems/fh/*";
home-manager.url = "https://flakehub.com/f/nix-community/home-manager/0.2411.*";
nixpkgs.url = "https://flakehub.com/f/nixos/nixpkgs/0.2411.*";
};
homeConfigurations = {
"macUsername@macHostname" = helper.mkHome {
username = "macUsername";
hostname = "macHostname";
platform = "darwin-aarch64";
};
"linuxUsername@linuxHostname" = helper.mkHome {
username = "linuxUsername";
hostname = "linuxHostname";
platform = "linux-x86_64";
};
};
This same technique can be extended to:
- NixOS Configurations: Cache system configurations for faster server deployments
- nix-darwin Configurations: Pre-build macOS system configurations
- Development Environments: Cache development shells and tooling
The benefits of using FlakeHub Cache become even more pronounced with these larger configurations, as they typically involve more packages and longer build times.
- Fork this repository
- Update the usernames and hostnames in
flake.nix
- Modify the Home Manager configuration in
home-manager/default.nix
- Push your changes to trigger the CI build
- Deploy using
fh resolve
andfh apply home-manager