[Nix-dev] nix-shell with system pkgs

Fabian Schmitthenner fabian at schmitthenner.eu
Tue Jan 26 16:16:32 CET 2016


Hi Yacine,

On 01/25/2016 11:15 PM, Yacine Hmito wrote:
> Hi,
> 
> Bear with me a minute, because I need to introduce a setup in order
> to make sense to my following questions.
> 
> Say I packaged a piece of software and the derivation is written in a
> mypkg.nix file.
> I want to use the <nixpkgs> provided by the unstable channel and don't want
> to fork the repo and link to it, so I create a nix set in a file myset.nix
> with an attribute `mypkg = callPackage ./mypkg.nix` and use
> `packageOverrides`
> to make it available. The software is installed ; everything works fine.
> 
> Now, say I want to do something like `nix-shell '<nixpkgs>' -A mypkg`.
I don't know how to reference the system's nixpkg. But you can also set
packageOverrides in ~/.nixpkgs/config.nix. Then this command should work.
> Obviously, this will not work, because mypkgs does not belong to the pkgs
> set provided by the channel. However I see no simple way to use nix-shell
> from this derivation.
> 
> So, I did this workaround: I added to NIX_PATH a "custompkgs" field that
> points to a file holding this expression:
> `(import <nixpkgs> { }) // (import ./myset.nix (import <nixpkgs> { }))`.
> Note that myset.nix takes pkgs as an argument because packageOverrides
> requires it.
> `nix-shell '<custompkgs>' -A mypkgs` now works like a charm.
Why not just 'nix-shell ./myset.nix -A mypkgs' and define myset.nix like
that:

{ nixpkgs ? import <nixpkgs> { } }:
...


> Now, let's get to something a tad harder: say I have another package
> in the form of the file myotherpkg.nix.
> Now, myset.nix contains both the mypkg and myotherpkg. Thing is,
> myotherpkg depends on mypkgs!
> Using `packageOverrides` is fine. myotherpkgs finds its dependency when the
> set is made recursive. It installs ; great!
I don't think the set has to be made recursive for this to work. It's
the callPackage function that supplies the arguments from nixpkg and
mypkg is in nixpkgs by packageOverrides.
> But `nix-shell '<custompkgs>' -A myotherpkgs` complains about not finding
> the mypkgs dependency.
As said above, you have to create ~/.nixpkgs/config.nix
> 
> So, after this lengthy introduction, these are my questions:
> 
> - Is it possible for nix-shell to use pkgs as configured by the system
> instead of evaluating '<nixpkgs>'? Would pointing toward the system's
> .drv file
I don't know. A .drv probably won't work. Something like "import
<nixpkgs> { config = (import <nixpkgs/nixos> {}).config.nixpkgs; }"
should probably work to get a properly configured nixpkgs (like it would
evaluate if you did nixos-rebuild now) AFAIK.
> help? If so, how should I proceed?
> - If it is not possible (yet ? :P), can someone explain to me why myotherpkg
> can't find its dependency? This really doesn't make sense to me.
This is because you use the callPackage function from nixpkgs, which
only automatically supplies packages in nixpkgs. You can define your own
callPackage function like in the following example:


  { nixpkgs ? import <nixpkgs> { }}:
  let callPackage = nixpkgs.lib.callPackageWith (nixpkgs // mypkgs);
      mypkgs = {
         A = callPackage ./A.nix { };
         B = callPackage ./B.nix { };
      };
  in mypkgs

or you can just supply it manually.
> 
> Thanks to anyone who'll be kind enough to answer, and to anyone how has made
> this awesome OS.

Cheers,

Fabian
> 
> 
> 
> _______________________________________________
> nix-dev mailing list
> nix-dev at lists.science.uu.nl
> http://lists.science.uu.nl/mailman/listinfo/nix-dev
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
Url : http://lists.science.uu.nl/pipermail/nix-dev/attachments/20160126/7ad33457/attachment.bin 


More information about the nix-dev mailing list