Skip to content

slice/nixfiles

Repository files navigation

nixfiles

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.

Bringup

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.

  1. Install Nix. Let's use Lix:

    curl -sSf -L https://install.lix.systems/lix | sh -s -- install
    

    The 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.
  2. Clone this repository to ~/src/prj/nixfiles. (As you might guess, this path is also hardcoded. For now. Maybe.)

  3. Pop open a fresh shell so the computer knows where nix lives. Then, bootstrap Home Manager:

    nix run home-manager/master -- switch --flake ~/src/prj/nixfiles
    

    and nix-darwin (substitute HOSTNAME as 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 /etc to let nix-darwin manage the environment. Also note that this will explode if Homebrew has already been installed, because nix-homebrew is being used.

  4. Change your shell:

    sudo chsh -s ~/.nix-profile/bin/fish $USER
    
  5. 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 doctor to verify that you don't have conflicting nix binaries in your PATH.
    • Use launchctl to ensure that you only have a single Nix daemon (e.g. launchctl print system, launchctl disable system/…, etc.)
  6. All done.

Usage

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.