Nix Notes

1 Cheat sheet

1.1 Install/upgrade nix

Date: 2017-05-06


bash <(curl


$ curl | sh

1.1.1 Error setting certificate verify locations

Date: 2017-05-24


If you get this error while trying to install Nix using curl, install the ca-certificates package via apt-get (or the appropriate package manager for your system).

If the error persists, verify that ca-certificates.crt is in the correct location and, if not, create a symlink to it.

Expected location: /etc/pki/tls/certs/ca-bundle.crt Location on my system: /etc/ssl/certs/ca-certificates.crt

1.2 Activate a nix user profile

source ~/.nix-profile/etc/profile.d/

1.3 Search for packages

nix-env -qaP | grep python3-3

1.4 List all installed packages

nix-env -q

1.5 Garbage collect


1.6 Create a shell environment with the jdk package

nix-shell -p jdk

The -p argument specifies the packages to include in the environment.

2 Python

2.1 Convert pip packages to nix expressions

Date: 2017-05-23


First clone and install pip2nix:

git clone
nix-env -f pip2nix/release.nix -iA pip2nix.python35  # Same Python as target packages

Ensure that pythonXX matches the Python version to be used with the target package.

Next, generate the python-packages.nix file with

pip2nix generate -r requirements.txt

where requirements.txt is for the desired package.

3 Java

3.1 Packaging Maven projects

Date May 12, 2017



IMPORTANT Unfortunately, the workaround for authenticated flag problem in mvn2nix does not work for me. The directions in this section might work for you since others have reported success with it. I decided to install pre-built .jars using nix instead of building the source.

To use the mvn2nix plugin, you need to have Maven >= 3.2.5. On May 12, 2017, this required installing from jessie-backports on Debian:

sudo apt-get -t jessie-backports install maven

Next, generate the project-info.json file that build-maven.nix will use the Nix expression for your package. To do this, run the following command from inside the Maven project's root directory.

mvn -Dmaven.repo.local=$(mktemp -d -t mavenXXX) org.nixos.mvn2nix:mvn2nix-maven-plugin:mvn2nix

Important note: on my Debian Jessie system, mktemp requires at least three X's appended to the end of the output file, hence the $(mktemp -d -t mavenXXX) above. Alternatively, you can just drop the template argument altogether.

The output of the above command will be a file named project-info.json. Move this some convenient directory inside your project's hierarchy, such as app/.

3.2 Installing pre-built .jars

Instead of building Java source code, you could get away with simply installing prebuilt .jars using Nix. Here is a short expression I used to copy the ImageJ 1.51j .jar file into the Nix store.

with import <nixpkgs> {};

stdenv.mkDerivation {
  name = "ij-1.51j";
  src = (builtins.toPath ./ij-1.51j.jar);
  phases = "installPhase";

  installPhase = ''
    mkdir -p $out/java/share
    cp -v $src $out/java/share/

  meta = {
    description = "Open source scientific multidimensional image processing";
    homepage =;

It's important to specify the phases attribute because stdenv.mkDerivation will attempt to run a build phase by default. This means it will try to run configure, make, make install, etc. on contents of the src attribute. By specifying that we only want an install phase, we can simply copy the .jar to the store.

4 Glossary

The official glossary is located in the Nix documentation here: