5

I am trying to use nix on ubuntu, with XMonad as my window manager. I have this working well on one host using nixOS, but I have a second device that isn't yet ready for nixOS. nix on top of Ubuntu is mostly working well there, but xmonad cannot find contributory libraries.

The relevant packages are installed:

$ nix-env -q | grep xmonad
xmonad-0.13
xmonad-contrib-0.13
xmonad-extras-0.12.1

But recompiling my xmonad.hs, it cannot find the contrib libs:

$ xmonad --recompile
Error detected while loading xmonad configuration file: /home/martyn/.xmonad/xmonad.hs

xmonad.hs:32:1: error:
Failed to load interface for ‘XMonad.Layout.NoBorders’
Use -v to see a list of the files searched for.

...

Please check the file for errors.

The relevant files are installed:

$ ls /nix/store/*xmonad-contrib*/lib/**/NoBorders*
/nix/store/4xrrwsm6362xkn9jn1b17kd891kv9z3a-xmonad-contrib-0.13/lib/ghc-8.0.2/xmonad-contrib-0.13/XMonad/Actions/NoBorders.dyn_hi
/nix/store/4xrrwsm6362xkn9jn1b17kd891kv9z3a-xmonad-contrib-0.13/lib/ghc-8.0.2/xmonad-contrib-0.13/XMonad/Actions/NoBorders.hi
/nix/store/4xrrwsm6362xkn9jn1b17kd891kv9z3a-xmonad-contrib-0.13/lib/ghc-8.0.2/xmonad-contrib-0.13/XMonad/Layout/NoBorders.dyn_hi
/nix/store/4xrrwsm6362xkn9jn1b17kd891kv9z3a-xmonad-contrib-0.13/lib/ghc-8.0.2/xmonad-contrib-0.13/XMonad/Layout/NoBorders.hi

By adding xmonad-contrib to my nixpkgs config.nix, I have gotten these libs added to the ghc package registry:

$ cat ~/.config/nixpkgs/config.nix 
with (import <nixpkgs> {});
{
  packageOverrides = pkgs: with pkgs; {

    myHaskellEnv = pkgs.haskellPackages.ghcWithPackages (haskellPackages: with haskellPackages; [ xmonad-contrib ]);
  };
}
$ nix-env -iA nixpkgs.myHaskellEnv
$ ghc-pkg list | grep xmonad
  xmonad-0.13
  xmonad-contrib-0.13
$

with this, this ghc(i) works well:

$ /nix/store/7mkxsq7ydqcgnjbs59v1v47wfxpwrav5-ghc-8.0.2-with-packages/bin/ghc ~/.xmonad/xmonad.hs
[1 of 1] Compiling Main             ( /home/martyn/.xmonad/xmonad.hs, /home/martyn/.xmonad/xmonad.o ) [flags changed]
Linking /home/martyn/.xmonad/xmonad ...

But even the version of xmonad in that dir cannot find the libs:

$ /nix/store/7mkxsq7ydqcgnjbs59v1v47wfxpwrav5-ghc-8.0.2-with-packages/bin/xmonad --recompile
Error detected while loading xmonad configuration file: /home/martyn/.xmonad/xmonad.hs

xmonad.hs:32:1: error:
  Failed to load interface for ‘XMonad.Layout.NoBorders’
  Use -v to see a list of the files searched for.

I can work around this by compiling using the ghc as above, and moving the output by hand to ~/.xmonad/xmonad-x86_64-linux, and running that. But this is a wee bit hacky, and surely shouldn't be necessary?

user3416536
  • 1,429
  • 9
  • 20
  • Isn't that particular `xmonad.hs` part of your configuration and should therefore get compiled "within" nix (from a configuration management point of view)? – Zeta Jun 27 '17 at 11:15
  • I'm not a xmonad user myself but here is the xmonad config file of @Ptival on NixOS: https://github.com/Ptival/config/blob/master/xmonad.nix – Zimm i48 Jun 27 '17 at 12:22
  • Possibly xmonad.hs would be better managed "within" nix, but I'm not yet competent to achieve that, and as shown with nixOS, it should be possible to choose not to but still work (whether or not it is wise). – user3416536 Jun 27 '17 at 18:45
  • Thanks for the link - but that configuration is for a nixOS installation, rather than nix on top of ubuntu. – user3416536 Jun 27 '17 at 18:46

1 Answers1

7

A friend solved this for me offline, I reproduce this here for others with the same issue.

Essentially, we need to use xmonad-with-packages, and list the packages, rather than ghc-with-packages.

To achieve this, we provide our own xmonad, referenced from within ~/.nixpkgs/config.nix:

{
  packageOverrides = pkgs_: with pkgs_; {
    xmonad            = import ./xmonad { nixpkgs = pkgs_; };
  };
}

And fill out ~/.nixpkgs/xmonad/default.nix thus:

{ nixpkgs ? import <nixpkgs> {} }:

nixpkgs.xmonad-with-packages.override {
  packages = hPkgs: with hPkgs; [ xmonad-contrib ];
}

This installs an xmonad that knows where to find its libraries, and everything's good!

user3416536
  • 1,429
  • 9
  • 20
  • 1
    Just to point out that after this one should install xmonad with `nix-env -iA nixpkgs.xmonad`, which wasn't clear until I read through the code in the question. – A.P. Mar 29 '18 at 15:23