NixOS Notes

I had bought a new laptop recently, which was a perfect opportunity to take a fresh look at my NixOS setup.

As usual, there are some hacks and not obvious things which I would like to document just in case :)

If it does not work, update

Ive tried installed a stable 16.09 version first, but live CD didnt manage to start the X server properly. This was easy to fix by switching to the then beta 17.03.

UEFI

It is my first system which uses UEFI instead of BIOS, and I was pleasantly surprised by how everything just worked. Documentation contains only a short paragraph about UEFI, but its everything you need. The only hiccup on my side happened when I enabled GRUB together with systemd-boot: you dont need GRUB at all, system-boot is a bootloader which handles everything.

If it does not work, fix the obvious problem

After Ive installed everything, I was presented with a blank screen instead of my desktop environment (with the live CD everything worked). It took me ages to debug the issue, while the fix was super trivial: add videoDrivers = [ "intel" ]; to xserver config and "noveau" to blacklistedKernelModules.

Rust

While nix is the best way to manage Linux desktop I am aware of, rustup is the most convenient way of managing Rust toolchains. Unfortunately its not easy to make rustup play nicely with NixOS (UPDATE: rustup is now packaged in nixpkgs and just works). Rustup downloads binaries of the compiler and Cargo, but it is impossible to launch unmodified binaries on NixOS because it a lacks conventional loader.

The fix I came up with is a horrible hack which goes against everything in NixOS. Here it is:

environment.extraInit = let loader = "ld-linux-x86-64.so.2"; in ''
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/run/current-system/sw/lib:${pkgs.stdenv.cc.cc.lib}/lib"
  ln -fs ${pkgs.stdenv.cc.libc.out}/lib/${loader} /lib64/${loader}
'';

It makes the loader and shared libraries (rustup needs zlib) visible to binaries compiled for x64 Linux.

Idea

Another software which I wish to update somewhat more frequently than other packages is IntelliJ IDEA (I write a fair amount of Kotlin and Rust). NixOS has a super convenient mechanism to do this: packageOverrides. Here is my ~/nixpkgs/config.nix:

{
  packageOverrides = pkgs: rec {
    idea-community = let
      version = "2017.1";
      sha256 = "750b517742157475bb690c1cc8f21ac151a754a38fec5c99a4bb473efd71da5d";
    in
      pkgs.idea.idea-community.overrideDerivation (attrs: rec {
        inherit version;
        name = "idea-community-${version}";
        src = pkgs.fetchurl {
          inherit sha256;
          url = "https://download.jetbrains.com/idea/ideaIC-${version}.tar.gz";
        };
      });
  };
}

It allows to use the most recent IDEA with the stable NixOS channel.