Nix Notes

1 Cheat sheet

1.1 Install/upgrade nix

Date: 2017-05-06


bash <(curl


$ curl | sh

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 Java

2.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/.

2.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.

3 Glossary

The official glossary is located in the Nix documentation here: