Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I nix-env install a derivation from a nix expression file?

Tags:

nix

nixos

I've got a default.nix file that builds a derivation (at least my understanding of it).

{ nixpkgs ? import <nixpkgs> {}, compiler ? "ghc864" } :
nixpkgs.pkgs.haskell.packages.${compiler}.callCabal2nix "bhoogle" (./.) {}

I can successfully nix-build this. Is there a way I can install this into my user profile with nix-env directly? For example something like nix-env -i -f default.nix.

Otherwise I need to define a package in my system profile with something like:

  example = pkgs.callPackage /home/chris/example/default.nix {};
like image 286
Chris Stryczynski Avatar asked Jul 08 '19 11:07

Chris Stryczynski


1 Answers

Quite literally my initial guess (thanks @Robert):

nix-env -i -f default.nix

Documented in nix --help:

   --file / -f path
       Specifies the Nix expression (designated below as the active Nix expression) used by the --install, --upgrade, and --query

--available operations to obtain derivations. The default is ~/.nix-defexpr.

       If the argument starts with http:// or https://, it is interpreted as the URL of a tarball that will be downloaded and

unpacked to a temporary location. The tarball must include a single top-level directory containing at least a file named default.nix.

like image 69
Chris Stryczynski Avatar answered Oct 17 '22 19:10

Chris Stryczynski