18

All the instructions I find for creating a local repository of Nix packages involve creating a local clone of the main nixpkgs repository and adding to that.

Is there a way I can create a small repository just containing my local add-on packages?

Chris Stryczynski
  • 5,178
  • 5
  • 40
  • 80
Michael Ekstrand
  • 2,064
  • 3
  • 21
  • 23

3 Answers3

7

Yes, just create an expression for the single package. You can get dependencies from nixpkgs by pkgs = import <nixpkgs> {};.

Vladimír Čunát
  • 1,258
  • 7
  • 11
7

This blog post have some details: http://sandervanderburg.blogspot.no/2014/07/managing-private-nix-packages-outside.html

For more low-level from-the-ground-up details there's the nix-pill series: http://lethalman.blogspot.no/2014/07/nix-pill-1-why-you-should-give-it-try.html

But I think the basic approach is to create your own version of ~/.nix-defexpr/channels_root/nixos/pkgs/top-level/all-packages.nix, say mypkgs.nix adding dependencies from the default "repo" by importing <nixpkgs>.

Install packages by doing nix-env -f mypkgs.nix -i DERIVATION_NAME

But since nix is based on a full-blown language there's infinity ways you could do it I guess.

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
olejorgenb
  • 881
  • 11
  • 11
2

I'm by no means a Nix expert so I don't know if this is the best way, but it's what I do. I have a local repo for packages in $HOME/nix-local, which contains a number of package files vault/default.nix, blackbox/default.nix etc and a config.nix file which defines packageOverrides to call them. So something like:

$ cat nix-local/config.nix
{
  packageOverrides = pkgs: rec {
    vault = pkgs.callPackage ./vault {};
    blackbox = pkgs.callPackage ./blackbox {};
    # ...
}

$ export NIXPKGS_CONFIG=$HOME/nix-local/config.nix    

You can see the full repo at https://github.com/telent/nix-local

telent
  • 131
  • 2
  • 7
    To anyone reading this since about 2017, this repo is not currently maintained and I would strongly suggest you read up on "overlays", a much cleaner way to do what packageOverrides used to do – telent Oct 03 '18 at 12:49