[Nix-dev] some basic questions from a new NixOS user

Linus Arver linusarver at gmail.com
Sat Nov 26 23:42:03 CET 2011


On Fri, Nov 25, 2011 at 12:35:01AM +0100, Nicolas Pierron wrote:
> Hi Linus,
> 
> On Thu, Nov 24, 2011 at 22:44, Linus Arver <linusarver at gmail.com> wrote:
> > On Thu, Nov 24, 2011 at 07:00:29PM +0100, Nicolas Pierron wrote:
> >> Hi Linus,
> >>
> >> On Thu, Nov 24, 2011 at 07:24, Linus Arver <linusarver at gmail.com> wrote:
> >> > I'm new to this list.
> >>
> >> Great.
> >>
> >> > 1a. I've added a new user account with "useradd," per the manual, and
> >> > have done a couple installations of software with `nix-env -i'. This is
> >> > great, but I'm curious --- what is the preferred way to install
> >> > software? The wiki page at http://nixos.org/wiki/Install/remove_software
> >> > says that there are two ways to install software --- system-wide (by
> >> > editing environment.systemPackages), and per-user (by just doing nix-env
> >> > -i [package]). My understanding is that in order to get the advertised
> >> > advantages of NixOS's rollback functionality, you have to do system-wide
> >> > installs because the whole "nixos-rebuild" command only looks at
> >> > /etc/nixos/configuration.nix. I.e., there is no way to rollback the
> >> > system on a per-user basis. So, do most people on here have a very long
> >> > environment.systemPackages definition in their configuration.nix,
> >> > defining all system-wide packages?
> >>
> >> Using either per-user install or system-wide install depends on what
> >> you want to do.  Personally I use both.
> >>
> >> NixOS is build on top of Nix and relies on the nix-env command to
> >> update the system profile and also to do rollbacks (have a look at the
> >> end of nix-env man page).  One advantage of per-user profiles is that
> >> the root account does not see (in its default PATH) the user installed
> >> software and also the opposite.  This difference is not a big security
> >> protection but it helps to separate the administrative tools from the
> >> commonly used tools.
> >>
> >> On my case, I am using user profiles to install software that I don't
> >> want to see under the root user (inkscape, gimp, firefox, …) and I am
> >> also using user-profiles (not the default ~/.nix-profile) to test
> >> compilation with different tool-chains (x64-gcc45, x86-gcc46, …), in
> >> which case I reset the environment and rebuild it from scratch with
> >> only this user profile.
> >>
> >
> > Thanks, this cleared up a lot of things. I just learned from reading the
> > Nix manual that you can create new profiles by just doing
> >
> >    nix-env --switch-profile /nix/var/nix/profiles/foo
> >
> > and it will create "foo" if it doesn't exist already. I'm having trouble
> > understanding the hierarchy of folders/files in the profiles folder,
> > though. For my system, there appear to be 3 distinct profiles
> >
> >    1. /nix/var/nix/profiles/default (3 generations)
> >    2. /nix/var/nix/profiles/system (7 generations)
> >    3. /nix/var/nix/profiles/per-user/l/profile (11 generations)
> >    4. /nix/var/nix/profiles/per-user/root (no files)
> >
> > I can tell that #3 is what I'm currently using (if I do "nix-env
> > --list-generations" I get 11 generatios). If I do a "su" to change into
> > root and then do "nix-env --list-generations" I get 3 generations, so
> > that would correspond to #1. So my question is --- why does #4 exist? Is
> > it to house new, custom-created profiles for the root user? Perhaps
> > these different profiles should be documented in the Nix manual...
> 
> And easier way to find your current profile is to use
> 
> $ ls -l ~/.nix-profile

I eventually learned that I could do

    nix-env -p /nix/var/nix/profiles/xyz --list-generations

to get the information I wanted (although the above command is just a
wrapper for inspecting the /nix/var/nix/profiles directory, it's still
nice to know!). The man page for nix-env should tell users
to provide the full path to the profile for the "-p" flag (otherwise, it
just silently fails without any message).

> >> > 1b. If I wanted zsh, git, and rxvt-unicode to be available system-wide,
> >> > can I do:
> >> >
> >> >    environment.systemPackages = [
> >> >        pkgs.zsh
> >> >        pkgs.git
> >> >        pkgs.rxvt-unicode
> >> >    ];
> >> >
> >> > in my configuration.nix? There does not seem to be any documentation
> >> > regarding the syntax for this.
> >>
> >> Sure, you can do it, except that the papckages names are extracted
> >> from /etc/nixos/nixpkgs/pkgs/top-level/all-packages.nix .  Thus you
> >> should not use the package name, but the key listed in this file.  So
> >> you will need to replace
> >>
> >> >        pkgs.rxvt-unicode
> >>
> >> by    pkgs.rxvt_unicode
> >>
> >
> > Thanks, that makes sense --- I was getting errors with the former form.
> > Is the path
> > "/etc/nixos/nixpkgs/pkgs/top-level/all-packages.nix" documented
> > somewhere so I can learn more about it?
> 
> Not directly, but multiple reference are made to it in Nixpkgs documentation.
> 
> http://nixos.org/nixpkgs/docs.html

A direct reference should be made in the NixOS manual when it mentions
"environment.systemPackages" for the first time... I feel that new users
should not need to dig through the documentation to find out important
rules like this.

> >> Don't hesitate to give us your feedback if you think that some steps
> >> are not clear and took you time to figure out.  I'll update the wiki
> >> page to fix one mistake and to separate the uninstall from the
> >> removal.
> >
> > Thanks! The biggest problem for me is the lack of practical
> > documentation --- right now the NixOS docs are concerned more about the
> > technical advantages of NixOS and do not really help actual users trying
> > out the system. Of course, this will improve as more users install
> > NixOS, but it's the same chicken-and-egg problem that all Linux distros
> > have to face.
> >
> > Anyway, my #1 goal right now is to get Xmonad installed and started on
> > boot. I don't want to bother with logging in manually with SLIM --- I
> > just want to stare at a blank rxvt-unicode terminal from Xmonad when I
> > start up. In my Arch Linux boxes, I have a /etc/inittab which deals with
> > how all of this is handled (automatic logging in, startx, etc.), but I'm
> > not so sure how to translate this setup into NixOS.
> 
> In NixOS, you have to set options inside your
> /etc/nixos/configuration.nix file.  Based on your goals I guess you
> will be interested by the following list of options:
> 
> # enable Xmonad
> services.xserver.windowManager.xmonad.enable
> 
> # Automatic logging
> services.xserver.displayManager.auto.enable
> services.xserver.displayManager.auto.user
> 
> To start rxvt, I recommend you to copy the
> /etc/nixos/nixos/modules/services/x11/desktop-managers/xterm.nix nix
> expression and adapt it to your shell, and enable it inside your
> configuration.  This module start XTerm at the beginning of the
> session.

Thank you for leading me in the right direction. Unfortunately, I have
not succeeded in reaching my #1 goal yet with configuration.nix. I have
this in my configuration.nix:

    services.xserver = {
        enable = true;
        layout = "us";

        # Automatic login as regular user (no need to put up with entering
        # password)
        displayManager = {
            auto = {
                enable = true;
                user = "l"; # login as "l"
            };
        };

        # Enable XMonad
        windowManager = {
            xmonad.enable = true;
        };
    };

I did a "nixos-rebuild switch", but xmonad does not get started. It's
not even in any path! It's weird because Nix downloaded the ghc and
xmonad packages (they are present in /nix/store), so they do exist in my
system...

I thought that maybe

    /etc/nixos/nixos/modules/services/x11/desktop-managers/xterm.nix

was getting in my way (since it is enabled by default) by starting up an
xterm on boot (therefore bypassing the windowManager.session stuff), but
when I disable the xterm with

    desktopManager.xterm.enable = false;

I get an infinite loop of login/logout (caused by my
displayManager.auto.enable setting).

So my conclusion right now is that the xmonad-related stuff in
configuration.nix is broken...

As a desperate measure, I tried installing ghc/xmonad with nix-env
instead, and it did work that way, but I have to manually type in
"xmonad" into the xterm that starts up. It would be nice if I could just
do it all inside configuration.nix.

Hmm, but now that I think about it, xmonad is supposed to be compiled
out of a user's ~/.xmonad/xmonad.hs configuration file (I already have
one I've been using from Arch for over a year now), so I don't
understand how "windowManager.xmonad.enable" makes any sense --- which
xmonad.hs file does it compile and load up?

If anyone on this mailing list has a working xmonad setup, please share
your configuation with us NixOS newbies!

> > My #2 goal is to get firefox installed. Right now if I do "nix-env -i
> > firefox", it fails because install_flash_player_10_linux.tar.gz cannot
> > be downloaded from any mirror. Maybe this is only affecting i686
> > platforms.
> 
> In the mean time you can change the options to avoid installing the
> flash player.  You can copy the following into ~/.nixpkgs/config.nix .
>  This file would be loaded by all-packages.nix.
> 
> {
>   firefox = {
>     enableAdobeFlash = false;
>   };
> }

Thanks --- incidentally, I found that the NixOS manual mentions the
nixpkgs.config option, which seems related. I'll read the manuals more
before asking more questions...

> > Curiously, zsh does not give me any problems in this regard. It's not
> > really a problem for me, because I use zsh whenever possible (and will
> > set it to my login shell as soon as I figure out chsh for my regular
> > user...)
> 
> chsh does not work if you reference your user inside NixOS
> configuration file, the reason is that each time you boot, NixOS
> activation script will update /etc/passwd file with the list of users
> and shells.  But you can update your shell inside your
> configuration.nix file.  Have a look at one module of my
> configurations:
> 
> https://svn.nixos.org/repos/nix/configurations/trunk/misc/nicolas.b.pierron/common/user.nix

Thanks for this. I adapted the

  users.extraUsers = [
    { name = "nicolas";
      uid = 1000;
      group = "users";
      extraGroups = [ "wheel" "share" ];
      description = "Nicolas Pierron";
      home = "/home/nicolas";
      shell = pkgs.zsh + "/bin/zsh";
    }
  ];

  users.extraGroups = [
    { name = "share";
      gid = 1001;
    }
  ];

  environment.systemPackages = [
    pkgs.zsh
  ];

portion into my configuration.nix and it now uses zsh as the login shell
now for my regular user. It also allows me to use "sudo", too, which is
an added bonus! (I was using "su" earlier to get around this limitation).

Thanks for your help, again.

-Linus


More information about the nix-dev mailing list