Common pitfalls and solutions for issues I’ve run into while using NixOS and Nix-Darwin.

NixOS

Unfree software

To run unfree software on NixOS without installing it globally, we can use:

NIXPKGS_ALLOW_UNFREE=1 nix run --impure nixpkgs#ookla-speedtest

Darwin

We can check darwin specific nix options on MyNixOS.

Building Changes

On darwin, we don’t use nixos-rebuild to apply changes, instead we use nix-darwin to switch to a new configuration.

nix run nix-darwin -- switch --flake .

Tip

We can also use nh to do all this stuff but in a more user-friendly way.

Rust / C++ DevShell

Apple bundles a C++ toolchain with Xcode, which doesn’t behave well with Nix if we are using a different C++ compiler, such as gcc or stdenv.cc.

= note: ld: library not found for -liconv
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)

To resolve this, we can simply remove the conflicting compiler from our devShell definition.

flake.nix
...
devShells.default = pkgs.devshell.mkShell {
  env = [
    {
      name = "DEVSHELL_NO_MOTD";
      value = 1;
    }
  ];
 
  packages = with pkgs; [
    # stdenv.cc
    rustStable
  ];
};
...