Nix code that is responsible for managing the configuration and environment of my personal machines.
Mostly documented for my own sake. I am trapped in a prison of my own design.
Warning
This procedure has only been tested on Macs with Apple silicon.
Important
nix-darwin configurations will only work if your hostname matches a
corresponding configuration in flake.nix.
-
Install Nix. Let's use Lix:
curl -sSf -L https://install.lix.systems/lix | sh -s -- installThe installer will describe what it intends to do before prompting you to continue. However, in general, it:
- Creates a new APFS volume for the Nix store.
- Creates and registers Launch Daemons that mount the volume and spawn the Nix daemon.
- Downloads and unpacks Nix.
- Creates Nix build users and groups.
- Writes the necessary shell profiles to make Nix usable.
-
Clone this repository to
~/src/prj/nixfiles. (As you might guess, this path is also hardcoded. For now. Maybe.) -
Pop open a fresh shell so the computer knows where
nixlives. Then, bootstrap Home Manager:nix run home-manager/master -- switch --flake ~/src/prj/nixfilesand nix-darwin (substitute
HOSTNAMEas appropriate):nix build ~/src/prj/nixfiles#darwinConfigurations.HOSTNAME.system --verbose sudo ./result/sw/bin/darwin-rebuild switch --flake ~/src/prj/nixfiles unlink result
You will likely have to mess with some files in
/etcto let nix-darwin manage the environment. Also note that this will explode if Homebrew has already been installed, because nix-homebrew is being used. -
Change your shell:
sudo chsh -s ~/.nix-profile/bin/fish $USER -
If you set up nix-darwin, then you probably have two Nix installations now, which needs to be fixed.
This can be accomplished by removing the Nix that was used to bootstrap, which basically boils down to uninstalling a package from
root's user environment:sudo nix-env --uninstall lix-2.93.0
(Nix is required to bootstrap nix-darwin, but nix-darwin essentially acts as a Nix installation in and of itself by managing a Nix daemon for you. Furthermore, a nix-darwin module is used to version-manage Nix, which will conflict with the Nix binary that was previously used to bootstrap this entire setup.)
Guidance:
- Use
nix doctorto verify that you don't have conflictingnixbinaries in yourPATH. - Use
launchctlto ensure that you only have a single Nix daemon (e.g.launchctl print system,launchctl disable system/…, etc.)
- Use
-
All done.
This repository is a flake mostly because it makes pinning dependencies
easier. However, flake.nix doesn't do much; in fact, it can largely be boiled
down to:
outputs = inputs: {
packages.aarch64-darwin.homeConfigurations.skip = import ./home/bootstrap.nix {
inherit inputs;
system = "aarch64-darwin";
username = "skip";
};
packages.x86_64-linux.homeConfigurations.skip = import ./home/bootstrap.nix {
inherit inputs;
system = "x86_64-linux";
username = "skip";
};
# ... etc. ...
};To instantiate the homeManagerConfiguration outside of a flake context,
home/bootstrap.nix can be used like so:
import "${<nixfiles>}/home/bootstrap.nix" {
system = "aarch64-darwin";
inputs = {
inherit nixpkgs home-manager; # etc.
};
server = "infer"; # all Macs are workstations
};Check out that file for more details.