How to Install a Private Package in NixOS

451 views Asked by At

I compiled a package from my private git repository in NixOS. How can I install that package on a NixOS machine? I want to install my package and keep it private. Is there a command to install a private package in NixOS?

Constraint: I don't want to make my package publicly available on Nixpkgs.

2

There are 2 answers

0
l0b0 On

Absolutely, you can use all the build tools available inside nixpkgs in your private configuration.nix. One easy way is to

  1. find a suitably similar build script within nixpkgs,
  2. put it in the relevant list of packages (environment.systemPackages, users.users.<username>.packages, or some services.<name>.package) like any other package,
  3. verify that everything is wired correctly by checking that the new configuration builds,
  4. change the build script to refer to your package instead, then
  5. rebuild the system.

For example, in case of a Python package the entry in the package list would look something like this:

(pkgs.python3Packages.buildPythonPackage rec {
    pname = "my-package";
    version = "1.2.3";
    src = ./my-package;
  }
)

(As an aside, usually nixpkgs builds are from source, not simply copying an already built package. I'd recommend that, to make it easier to port your package to future versions of nixpkgs without manually recompiling.)

0
Peter Bergman On

If you are able to build your nix package like so...

nix-build default.nix

...then you can easily install it using the nix-env command.

nix-env --install --file default.nix

That should install your package based on your nix expression file (default.nix in the example I gave).

Your package will NOT be added to Nixpkgs. Your package will NOT be publicly available, unless you are serving packages from your local nix store (which I doubt is the case).

I hope this helps :)