Alternative Package Manager(s)

Forum rules
Share your brain ;)
User avatar
franksinistra
Ivana Fukalot
Posts: 1093
Joined: Mon Jan 27, 2014 2:03 am
Location: 印尼国

Alternative Package Manager(s)

Unread post by franksinistra » Sun Nov 15, 2015 5:34 pm

Alright since i kept bothering people with Nix/GNU GUIx (GNU Guix is an offshoot of Nix, with all the GNU policy if that's your cup of tea) package manager and blah blah yadda yadda bullshit i talk aloud, and since some people (like sPacE_gaN) is in need for some assistance in installing Krita and the likes (which is currently broken in sid), i'll write a small 'how to for dummies' for you guys:

============================================================================
DISCLAIMER
============================================================================
By installing another package manager alongside the already great apt and some cool wrappers that was built by Bacon and Da Grillaz, you are in risk of bloating your /home or /root dir, symlink hell, lots of hair pulling, thermonuclear war, etc
============================================================================

You could always install other package managers out there (or if you like it super minimal, you could always cross-compile stuff and ask Pidsley how to do it). For the sake of familiarity, this post will guide you thru Nix package manager. I'll refer nix package manager as nix for the rest of this guide.


###########################################################################
Section 1: Installing
###########################################################################

  • 1. The safer way: single user install (meaning nix will be installed as the currently logged in user be it root or whatever your username is)

    Code: Select all

    curl https://nixos.org/nix/install | sh
    then proceed to add these lines to your .*shrc

    Code: Select all

    if [ -e $HOME/.nix-profile/etc/profile.d/nix.sh ]; then . $HOME/.nix-profile/etc/profile.d/nix.sh; fi
    
    note that this code is usually added automatically when you run the previous command.

    2. The dangerous way: Multi user install
    The only available option for this method is install it by source
    • 1. Grab the source

      Code: Select all

       wget http://nixos.org/releases/nix/nix-1.10/nix-1.10.tar.xz 
      Make sure your bbq install has build-essential package installed before you proceed
      2. Extract, and run these

      Code: Select all

       ./configure --prefix=/usr/local --sysconfdir=/etc 
      followed by

      Code: Select all

      make && make install 
      3. Make a new group (name it whatever you like)

      Code: Select all

      sudo groupadd -g 9999 nixjob
      4. Then we need to add user accounts for each build that gets executed simultaneously, this depends on the number of core(s) available for your processor. For the sake of example, mine is 8 so i do it like this:

      Code: Select all

      for i in `seq 1 8`
      do
          sudo useradd -u `expr 9999 + $i` -g nixjob \
            -c "Concurrent nix user $i" -d /var/empty -s /noshell
      done
      
      5. Making nixjob group legal

      Code: Select all

      sudo echo "build-users-group = nixjob" >> /etc/nix/nix.conf
      
      and do this so /nix/store will be owned by root and the nixjob group

      Code: Select all

      $ sudo chgrp nixjob /nix/store
      $ sudo chmod 1775 /nix/store
      
      6. Make sure you enable nix daemon at /etc/init.d/nscd
      7. Setup user profile directory (for your current user)

      Code: Select all

      export NIX_USER_PROFILE_DIR=/nix/var/nix/profiles/per-user/$USER
      
      mkdir -m 0755 -p $NIX_USER_PROFILE_DIR
      if test "$(stat --printf '%u' $NIX_USER_PROFILE_DIR)" != "$(id -u)"; then
          echo "WARNING: bad ownership on $NIX_USER_PROFILE_DIR" >&2
      fi
      
      then

      Code: Select all

      if ! test -L $HOME/.nix-profile; then
          echo "creating $HOME/.nix-profile" >&2
          if test "$USER" != root; then
              ln -s $NIX_USER_PROFILE_DIR/profile $HOME/.nix-profile
          else
              # Root installs in the system-wide profile by default.
              ln -s /nix/var/nix/profiles/default $HOME/.nix-profile
          fi
      fi
      
      8. In single user installations, we add the bin directory of the system-wide Nix profile to PATH. In multi-user installations, we have to do this both for the system-wide and the user profile:

      Code: Select all

      export NIX_PROFILES="/nix/var/nix/profiles/default $HOME/.nix-profile"
      
      for i in $NIX_PROFILES; do
          export PATH=$i/bin:$PATH
      done
      
      9. In single user installations, the user can subscribe itself to the Nixpkgs unstable channel. In multi-user installations only root can do this. Ordinary users can still install from the subscribed channels:

      Code: Select all

      if [ "$USER" = root -a ! -e $HOME/.nix-channels ]; then
          echo "http://nixos.org/channels/nixpkgs-unstable nixpkgs" \
            > $HOME/.nix-channels
      fi
      
      10. We have to create a garbage collector root folder for the user:

      Code: Select all

      NIX_USER_GCROOTS_DIR=/nix/var/nix/gcroots/per-user/$USER
      mkdir -m 0755 -p $NIX_USER_GCROOTS_DIR
      if test "$(stat --printf '%u' $NIX_USER_GCROOTS_DIR)" != "$(id -u)"; then
          echo "WARNING: bad ownership on $NIX_USER_GCROOTS_DIR" >&2
      fi
      
      11. We must also set the default Nix expression, so that we can conveniently install packages from Nix channels:

      Code: Select all

      if [ ! -e $HOME/.nix-defexpr -o -L $HOME/.nix-defexpr ]; then
          echo "creating $HOME/.nix-defexpr" >&2
          rm -f $HOME/.nix-defexpr
          mkdir $HOME/.nix-defexpr
          if [ "$USER" != root ]; then
              ln -s /nix/var/nix/profiles/per-user/root/channels \
                $HOME/.nix-defexpr/channels_root
          fi
      fi
      
      12. Ensure that the unprivileged user can't do shit

      Code: Select all

      if test "$USER" != root; then
          export NIX_REMOTE=daemon
      else
          export NIX_REMOTE=
      
      13. Shit's cooked, enjoy!
FYI, the more complete instruction on multi-user installation can be found here: http://sandervanderburg.blogspot.co.id/ ... ation.html
I just copied it and removing the irrelevant stuff for now

###########################################################################
Section 2: Crash Course
###########################################################################

You can always refer to the nix manual
for the sake of brevity, i'll give you a few hints:

Installing stuff:

Code: Select all

nix-env -i $package-name
Searching stuff:

Code: Select all

nix-env -qaP | grep $package_name
List available channel:

Code: Select all

nix-channel --list
Update repo/channel:

Code: Select all

nix-channel --update
Subscribe to a new channel (for instance stable/unstable channel):

Code: Select all

nix-channel --add $channel_name
Uninstall stuff:

Code: Select all

nix-env -e $package_name
Upgrade stuff:

Code: Select all

 nix-env -u 
Now nix doesn't purge stuff like debian apt do, old version of software will always be kept at /nix/store for when shit hits the fan, you could always rollback to the last known good package. To truly remove it (after you remove the package using nix-env -r) do:

Code: Select all

nix-collect-garbage -d
Alright, to rollback first you need to list all generations (nix term for snapshot) available in your machine

Code: Select all

nix-env --list-generations
then to actually rollback

Code: Select all

nix-env --switch-generation $generation
or

Code: Select all

nix-env -G $generation
there's an even shorter command, to rollback to previous (exactly one generation behind the current generation)

Code: Select all

nix-env --rollback $generation

Okay that's enough for now

###########################################################################
Section 3: Fun stuff begins
###########################################################################

Part 1: Resources for Nix language (the functional language nix package manager use)
nix pills by lethalman
nix manual

Part 2: Creating a new package

Use case example: Frank love wmutils, Frank wanted to install wmutils-opt on his linuxbbq install. Frank could always use git clone, make, make install thingy or create a new debian package. Frank wants more than that, because he's such a bastard. Frank did this instead:

1. Fork nixpkgs repo at https://github.com/nixos/nixpkgs.git
2. Clone it to his local machine
3. Write wmutils expression like this

Code: Select all

{ stdenv, fetchgit, libxcb }:

stdenv.mkDerivation rec {
  name = "wmutils-opt-${version}";
  version = "2015-08-01";

  src = fetchgit {
    url = "git://github.com/wmutils/opt.git";
    rev = "00fb88f80f2c42cdd664dc678430e77587cd392c";
    sha256 = "0938dnx9ql0b91igw9j59grfcjhgn7s31pdvb1ixfs6w4d2g1kcr";
  };

  buildInputs = [ libxcb ];

  installFlags = [ "PREFIX=$(out)" ];

  meta = with stdenv.lib; {
    description = "optional addons to wmutils";
    homepage = https://github.com/wmutils/opt;
    license = licenses.isc;
    platforms = platforms.unix;
  };
}
4. Call wmutils-opt expression on the $FORKED_NIXPKGS_DIR/pkgs/top-level/all-packages.nix

Code: Select all

wmutils-opt = callPackage ../tools/X11/wmutils-opt { };
5. Build the installation .drv (nix term for *.o) using this command

Code: Select all

nix-env -f $FORKED_NIXPKGS_LOCATION --build wmutils-opt
6. Frank install it like this

Code: Select all

nix-env -f $FORKED_NIXPKGS_LOCATION -i wmutils-opt
Part 3: Modifying Packages

Use case example: Frank loves bloatful vim. He's such a bastard that he installs vim-tiny on his linuxbbq machine, only to install another vim with luainterp to be able to use neocomplete for his username only. The following are his methods:

1. He creates .nixpkgs dir on his home folder
2. He proceeds to create a config.nix file.
3. This is its content:

Code: Select all

{
   packageOverrides = pkgs: {
    vim = pkgs.stdenv.lib.overrideDerivation pkgs.vim_configurable (o: {
      name = "myvim";
      luaSupport = true;
    });
  };

}
#######################################################
Section 4: The Blah Blahs
#######################################################

You could do a lot more in nix, including:
1. Debugging nix expressions using nix-repl
2. Subscribe to multiple channels (combining both nix-stable and nix-unstable for instance)
3. Use your configuration anywhere (your mac, your windows, your BSDs, your other Linux install)
3. Use Emacs and install nix-mode
4. Use Emacs (it's important), install nix-mode, and start hacking the repl

Alright that's pretty much it. Thanks for reading, and don't let anyone stop you from giving obscure shit a try.

EDIT: Adding links
EDIT2: Update some instructions
Last edited by franksinistra on Sun Nov 15, 2015 8:03 pm, edited 1 time in total.
rice no more.

User avatar
ivanovnegro
Minister of Truth
Posts: 5448
Joined: Wed Oct 17, 2012 11:12 pm

Re: Alternative Package Manager(s)

Unread post by ivanovnegro » Sun Nov 15, 2015 7:45 pm

*Applause*

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5877
Joined: Tue Sep 03, 2013 7:05 am

Re: Alternative Package Manager(s)

Unread post by GekkoP » Mon Nov 16, 2015 8:51 am

Fantastic work, thank you!

User avatar
franksinistra
Ivana Fukalot
Posts: 1093
Joined: Mon Jan 27, 2014 2:03 am
Location: 印尼国

Re: Alternative Package Manager(s)

Unread post by franksinistra » Mon Nov 16, 2015 9:52 am

thanks both of you!
rice no more.

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: Alternative Package Manager(s)

Unread post by rhowaldt » Mon Nov 16, 2015 11:44 am

definitely, *applause*, well done frank - thanks a lot :)
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
franksinistra
Ivana Fukalot
Posts: 1093
Joined: Mon Jan 27, 2014 2:03 am
Location: 印尼国

Re: Alternative Package Manager(s)

Unread post by franksinistra » Mon Nov 16, 2015 5:22 pm

^ thanks rho!
rice no more.

User avatar
simgin
Meme Fodder
Posts: 1167
Joined: Sun Jan 06, 2013 12:07 am
Location: Bradford-on-Avon, UK

Re: Alternative Package Manager(s)

Unread post by simgin » Mon Nov 16, 2015 10:18 pm

Sweet as hell Frankyboy :)
I have noticed that Nix has a quite vibrant community, think I will make the leap.

cheers
simon
Someone told me that I am delusional, I almost fell off my unicorn.

User avatar
franksinistra
Ivana Fukalot
Posts: 1093
Joined: Mon Jan 27, 2014 2:03 am
Location: 印尼国

Re: Alternative Package Manager(s)

Unread post by franksinistra » Tue Nov 17, 2015 12:37 pm

^ thanks sim! Be sure to checkout guix too, it's like nix only it's configs are in scheme instead of nix
rice no more.

User avatar
simgin
Meme Fodder
Posts: 1167
Joined: Sun Jan 06, 2013 12:07 am
Location: Bradford-on-Avon, UK

Re: Alternative Package Manager(s)

Unread post by simgin » Tue Nov 17, 2015 5:07 pm

^ Thanks for that info Franky :)
I am already reading up on it.

cheers
simon
Someone told me that I am delusional, I almost fell off my unicorn.

sPacE gàN
Saltimbocca-Roller
Posts: 16
Joined: Wed Oct 28, 2015 3:41 am

Re: Alternative Package Manager(s)

Unread post by sPacE gàN » Wed Nov 18, 2015 3:00 am

Thanks very much Frank ! Going to carefully marinade this on the weekend and hopefully resurrect my beloved Krita ;D

Post Reply