2. Quick Start to Adding a Package

To add a package to Nixpkgs:

  1. Checkout the Nixpkgs source tree:

    $ git clone git://github.com/NixOS/nixpkgs.git
    $ cd nixpkgs
    
  2. Find a good place in the Nixpkgs tree to add the Nix expression for your package. For instance, a library package typically goes into pkgs/development/libraries/, while a web browser goes into pkgs/applications/networking/browsers/. See ? for some hints on the tree organisation. Create a directory for your package, e.g.

    $ mkdir pkgs/development/libraries/libfoo
    
  3. In the package directory, create a Nix expression — a piece of code that describes how to build the package. In this case, it should be a function that is called with the package dependencies as arguments, and returns a build of the package in the Nix store. The expression should usually be called default.nix.

    $ emacs pkgs/development/libraries/libfoo/default.nix
    $ git add pkgs/development/libraries/libfoo/default.nix
    

    You can have a look at the existing Nix expressions under pkgs/ to see how it’s done. Here are some good ones:

    Some notes:

    The exact syntax and semantics of the Nix expression language, including the built-in function, are described in the Nix manual in the chapter on writing Nix expressions.

  4. Add a call to the function defined in the previous step to `pkgs/top-level/all-packages.nix <https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/all-packages.nix>`__ with some descriptive name for the variable, e.g. libfoo.

    $ emacs pkgs/top-level/all-packages.nix
    

    The attributes in that file are sorted by category (like “Development / Libraries”) that more-or-less correspond to the directory structure of Nixpkgs, and then by attribute name.

  5. To test whether the package builds, run the following command from the root of the nixpkgs source tree:

    $ nix-build -A libfoo
    

    where libfoo should be the variable name defined in the previous step. You may want to add the flag -K to keep the temporary build directory in case something fails. If the build succeeds, a symlink ./result to the package in the Nix store is created.

  6. If you want to install the package into your profile (optional), do

    $ nix-env -f . -iA libfoo
    
  7. Optionally commit the new package, or send a patch to nix-dev@cs.uu.nl.

  8. If you want the TU Delft build farm to build binaries of the package and make them available in the `nixpkgs channel <http://nixos.org/releases/nixpkgs/channels/nixpkgs-unstable/>`__, add it to `pkgs/top-level/release.nix <https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/release.nix>`__.