[Nix-dev] Debugging nixpkgs

Florian Friesdorf flo at chaoflow.net
Fri Mar 30 06:48:29 CEST 2012


<#secure method=pgpmime mode=sign>

Hi Konrad

On Thu, 29 Mar 2012 13:46:43 +0200, Konrad Hinsen <konrad.hinsen at fastmail.net> wrote:
> Konrad Hinsen writes:
> 
>  > While trying to build some derivations for MacOSX, I hit a problem
>  > which I think is a bug in nixpkgs and which moreover I think I know
>  > how to fix. How would I best go about debugging this? Can I just
>  > copy the source code somewhere, modify some files, and then test-build
>  > and test-run with that modified version? Do I risk messing up my
>  > installation that way? I don't quite see yet how modifying the
>  > source code of nixpkgs fits into the "nothing ever changes" view
>  > of Nix.
> 
> I would still like to see comments on this issue. I understand that most of you
> are working on improving nixpkgs. What's your setup? A checkout of the SVN
> source code on which you work? Do you keep different profiles for the release
> version and your personal working copy? Or is it safe to mix both in a single
> profile?

I have on nixos (on non-nixos /etc/nixos/nixpkgs probably lives
somewhere else and there is no /etc/nixos/nixos - apart from that what
follows should mostly apply):

/etc/nixos/nixpkgs
/etc/nixos/nixos

For both I have a "personal" branch to maintain patches I want to use
system wide, but that are not in a state to be committed to the trunks -
ideally they are empty.

Currently, for nixpkgs that is a patch to make a custom xkeyboard map
available, for nixos a patch to experiment with more aggressive
powermanagement and another to tweak the trackpoint.

I manage the repositories with git svn and just to add new or update
existing expressions I use them directly.

/etc/nixos/nixpkgs is linked to ~/.nix-defexpr/nixpkgs_sys, which seems
to be default on nixos, though I wonder whether the nixpkgs_sys could be
changed to something shorter, however, the pain was not big enough to
investigate yet.

For more experimental stuff (like the python rework currently living at
https://github.com/chaoflow/nixpkgs) I have another checkout/branch of
nixpkgs linked to ~/.nix-defexpr/py.

That means:

* my system is build using the only slightly modified nixos/nixpkgs

* nix-env -iA nixpkgs_sys.xyz  (for installing most things)

* nix-env -iA py.xyz (for testing python rework)

Packages happily coexist in the same profile, but I assume 'nix-env -u
\*' not to do the right thing, which would be "don't change the 'prefix'
during upgrade", so I use multiple profile which I currently manage/use
with a set of wrappers:

pnix-env [1]::

    #!/bin/sh

    # XXX: for some reason this variable is not set in here ?!
    NIX_USER_PROFILE_DIR=/nix/var/nix/profiles/per-user/cfl

    nix-env -p $NIX_USER_PROFILE_DIR/"$@" 

Usage: pnix-env <profilename> <normal nix options and arguments>
Purpose: save you the hassle from typing the full path. The profiles
should live in your NIX_USER_PROFILE_DIR not to be garbage collected.


py27env [2]::

    !/bin/sh

    # XXX: for some reason this variable is not set in here ?!
    NIX_USER_PROFILE_DIR=/nix/var/nix/profiles/per-user/cfl
    nixprofile=$NIX_USER_PROFILE_DIR/py27
    
    export PATH="$HOME/bin:$nixprofile/bin"
    export LD_LIBRARY_PATH="$nixprofile/lib"
    export NIX_LDFLAGS="-L $nixprofile/lib"
    export NIX_CFLAGS_COMPILE="-I $nixprofile/include"
    export PKG_CONFIG_PATH="$nixprofile/lib/pkgconfig"
    export PYTHONPATH="$nixprofile/lib/python2.7/site-packages"
    export PS1="py27 $PS1"
    
    "$@"

Usage: py27env <some program to run in the environment>
Purpose: Fully contain a program to the selected profile, making ~/bin
available to cheat a little bit.

To manage profiles more reproducibly I occassionally use buildEnv [3],
e.g.::

    KernelEnv = pkgs.buildEnv {
      name = "kernelenv";
      paths = [
        pkgs.defaultStdenv
        pkgs.gitAndTools.gitFull
        pkgs.ncurses
      ];
    };

As I sadly encounter too much software in my daily work that I could fix
it that expects /usr, I cheat further and occasionally link a profile to
/usr, but this is bound to cause problems - haven't figured that one out
yet - maybe chroots or virtual machines could be a solution.

I by no means claim that anything here is the best way to do it, it just
worked for me so far - hope it helps and happy to incorporate better
ideas.

regards
florian

[1] https://github.com/chaoflow/skel/blob/master/bin/pnix-env
[2] https://github.com/chaoflow/skel/blob/master/bin/py27env
[3] https://github.com/chaoflow/skel/blob/master/.nixpkgs/config.nix
-- 
Florian Friesdorf <flo at chaoflow.net>
  GPG FPR: 7A13 5EEE 1421 9FC2 108D  BAAF 38F8 99A3 0C45 F083
Jabber/XMPP: flo at chaoflow.net
IRC: chaoflow on freenode,ircnet,blafasel,OFTC


More information about the nix-dev mailing list