Skip to main content
  1. Blogs/

Allow unfree in a shell.nix

·230 words·2 mins·
linux nix code gpu

I recently made a switch to NixOS on my primary laptop, and have been exploring the use of nix-shell to build and run declarative, ephemeral environments. Each environment comes with different packages installed.

For those unfamiliar with NixOS, it’s a Linux distribution that takes a unique approach to package and configuration management. And nix-shell is a tool that lets you create environments isolated from each other. However, I hit a roadblock when I attempted to use an “unfree” package, CUDA, in one of my experiments.

“Unfree” refers to software that doesn’t meet “free software” criteria. By default, NixOS restricts the installation of such packages. The solutions I’ve found online suggested setting an environment variable to allow the installation of unfree packages, but I wanted a solution within the nix shell file itself. After a bit of tinkering, I managed to find a way. Here it is:

  # Configure Nix to allow unfree packages.
  config = {
    allowUnfree = true;
  pkgs = import <nixpkgs> { inherit config; };
pkgs.mkShell {
  buildInputs = with pkgs; [

    python3Packages.tensorflowWithCuda # this is the problematic line



  # Automatically run jupyter when entering the shell.
  shellHook = "jupyter-lab";

Here, the let section is importing nixpkgs with the config.allowUnfree option set to true.

After that, running nix-shell succeeded with installing the cuda packages.


Clever preprocessor macro in HLSL
·457 words·3 mins
hlsl code tips gpu
How to Use systemd-nspawn for Lightweight Linux Containers
·181 words·1 min
Unity: Getting GUILAyout: Mismatched LayoutGroup.repaint? Try EventType.Repaint
·259 words·2 mins
unity code c#
Yes, you CAN serialize abstract classes in Unity
·1206 words·6 mins
unity code c#
A single method that can work with either a List or an Array (IEnumerable and ICollection)
·296 words·2 mins
unity code tips c#
Round a number to some multiple of another number
·201 words·1 min
code tips