[Nix-dev] Getting started with nix-build

Peter Simons simons at cryp.to
Tue Mar 24 15:29:58 CET 2015


Hi Oliver,

make sure that you're building changes relative to some version of
Nixpkgs for which binary packages are already available. If you're
running NixOS, for example, switch your repository to the version that
you're currently running:

  $ git checkout -b my-patches origin/master
  $ git reset --hard $(nixos-version --revision)

Now cherry-pick the Git commit you'd like to test-build into that branch:

  $ git cherry-pick your-hash-here

And build it:

  $ nix-build . -A myNewPackage

Note that the use of "." assumes that you're currently in upper-most
directory of your Nixpkgs repository. If that's not the case, then you
must give the appropriate path, i.e.

  $ nix-build ~/src/nixpkgs -A myNewPackage

Once you're happy with the changes you've made, commit them and run

  $ git rebase origin/master

to bring the branch into shape for pushing.

Note that there's also https://github.com/NixOS/nixpkgs-channels. That
Git repository is a clone of Nixpkgs that provides several branches that
correspond to the latest available version of the binary channels from
hydra.nixos.org, i.e. there's a "nixos-unstable" branch that gives you
the latest possible version of Nixpkgs for which binaries can be
downloaded.

Last but not least, you can usually work fine on "master", if you add
the flag "--option extra-binary-caches http://hydra.nixos.org" to the
nix-build command line. You'll hardly ever have to compile fundamental
packages like glibc, but you may have to build other, more obscure stuff
locally because these are still waiting in the Hydra queue.

I hope this helps,
Peter



More information about the nix-dev mailing list