Basic Nix Tips

I use Nix as a package manager that works across MacOS & Linux. I add a shell.nix file to the root of each project with its dependencies - that way, as I move between machines (or share repos with other people!), I don’t have to stress about what needs to be installed.

Follow the instructions to install and enable flakes (important!).

Let’s say your project requires Go and Python. (Find other packages on Nixpkgs.)

Create a shell.nix file in your project’s root:

{ pkgs ? import <nixpkgs> {} }:
  pkgs.mkShell {
    nativeBuildInputs = with pkgs.buildPackages; [
        go
        python3
    ];
}

Then run nix-shell to fetch and set up a shell environment with those packages installed. Best thing - once you exit the shell, the installations are gone (through cached!), and your system does not feel cluttered :)

When offline, it attempts to fetch the current registry a few times, but eventually give up and use whatever you’ve downloaded.