GHC cannot find xmonad-contrib

I’ve successfully installed xmonad and xfce on my system by adding the following to my configuration.nix

services.xserver.displayManager = {
    lightdm.greeter.enable = true;
    defaultSession = "xfce+xmonad";
    lightdm.enable = true;
    lightdm.extraSeatDefaults =
      ''
      greeter-hide-users = false
      '';
  };

  services.xserver = {
    enable = true;   
    desktopManager = {
      xterm.enable = false;
      xfce = {
        enable = true;
        noDesktop = true;
        enableXfwm = false;
        thunarPlugins = [ pkgs.xfce.thunar-archive-plugin ];
      };
    };
  };

# Xmonad
services.xserver.windowManager.xmonad = 
{
  enableContribAndExtras = true;
  enable = true;
  extraPackages = haskellPackages:
    [ haskellPackages.xmonad
      haskellPackages.xmonad-contrib
      haskellPackages.xmonad-extras
    ];
};

Xmonad and xfce themselves (mostly) work, but when I try to use my own xmonad configuration by running xmonad --recompile, I get errors like

xmonad.hs:19:1: error:
    Could not load module ‘XMonad.Actions.GridSelect’
    It is a member of the hidden package ‘xmonad-contrib-0.16’.
    You can run ‘:set -package xmonad-contrib’ to expose it.
    (Note: this unloads all the modules in the current scope.)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
   |
19 | import           XMonad.Actions.GridSelect
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

So apparently I do have xmonad-contrib, but for some reason it is hidden. Normally I would do something like sudo ghc-pkg expose xmonad-contrib, but ghc-pkg also cannot find xmonad-contrib.
My questions would be

  1. Shouldn’t xmonad --recompile work by default? Is this a bug in the package or in my configuration? How can I make xmonad-contrib visible when compiling xmonad?
  2. In general, how do I make certain packages visible for me? I understand it has something to do with nix-shell and a shell.nix file, but I still do not understand how to use these properly.

I’m using nixos unstable, btw.

I’ve been using XMonad on NixOS for a while now, but I’m not super familiar with how it is working.

However, I will give you my X config, as well as a few things you can do to try to debug your problem.


Here’s my X config:

# This module enables the xserver.

{ config, lib, pkgs, ...}:

{
  imports = [];

  # Enable the X11 windowing system.
  services.xserver.enable = true;
  services.xserver.layout = "us";

  # Enable touchpad support.
  services.xserver.libinput.enable = true;

  services.xserver.windowManager.xmonad.enable = true;
  services.xserver.windowManager.xmonad.enableContribAndExtras = true;
}

In your configuration, it seems strange that you have both enableContribAndExtras and extraPackages specified. Without looking at the underlying module, I’m not sure what this will do.


The xmonad binary you’re running should be a wrapper. Here are a couple commands that I’m running from within my X session (in XMonad):

$ which xmonad
/run/current-system/sw/bin/xmonad
$ cat /run/current-system/sw/bin/xmonad
#! /nix/store/rm1hz1lybxangc8sdl7xvzs5dcvigvf7-bash-4.4-p23/bin/bash -e
export NIX_GHC='/nix/store/rkfqm3hsfdjb82j82p0j94cgq72fs75g-ghc-8.6.5-with-packages/bin/ghc'
export XMONAD_XMESSAGE='/nix/store/sq5fpsgpjp9vk77bcv47nsvv3hial6k4-xmessage-1.0.5/bin/xmessage'
exec "/nix/store/rkfqm3hsfdjb82j82p0j94cgq72fs75g-ghc-8.6.5-with-packages/bin/xmonad"  "${extraFlagsArray[@]}" "$@"

You can see that it exports the NIX_GHC env var.

This points to a GHC environment that should have a package database available with xmonad-contrib.

Here’s how to check this:

$ /nix/store/rkfqm3hsfdjb82j82p0j94cgq72fs75g-ghc-8.6.5-with-packages/bin/ghci
> import XMonad.Actions.GridSelect 

Or just ghc-pkg:

$ /nix/store/rkfqm3hsfdjb82j82p0j94cgq72fs75g-ghc-8.6.5-with-packages/bin/ghc-pkg list | grep -i xmonad
    xmonad-0.15
    xmonad-contrib-0.15
    xmonad-extras-0.15.1

So when you try to run xmonad --recompile, I believe this GHC (and corresponding package db) should be used.


Normally I would do something like sudo ghc-pkg expose xmonad-contrib , but ghc-pkg also cannot find xmonad-contrib .

This is expected. There is no global ghc-pkg, unless you’ve installed ghc to your environment.systemPackages. And if you did install ghc in your environment.systemPackages, it won’t be able to see the xmonad packages, because xmonad is referencing it’s own version of GHC.

(This is one of the benefits of Nix. Different packages can be reference different versions of the same dependency. You could have ghc-8.8 installed globally, while XMonad is still using ghc-8.6, and everything will work fine.)

1 Like

For starters, try to remove haskellPackages.xmonad, this might confuse things. You also don’t need to set both enableContribAndExtras and extraPackages:

# Xmonad
services.xserver.windowManager.xmonad = 
{
  enableContribAndExtras = true;
  enable = true;
};

Source: https://github.com/NixOS/nixpkgs/blob/f30b8adc022558b0852c95a933bca5f559baba59/nixos/modules/services/x11/window-managers/xmonad.nix

1 Like

I removed the extraPackages from my configuration, but that did not make any difference. I can compile xmonad using

$ $NIX_GHC -dynamic -package xmonad-contrib -package xmonad xmonad.hs

(btw, I need the -dynamic flag since I use a package that I had to install with cabal-install with my user. I should eventually make nix instead of cabal-install manage that package…)

Not sure how relevant this is, but the xmonad script is the following:

export NIX_GHC='/nix/store/43blmhnycp1p572k8p6i2940ygc360a3-ghc-8.8.2-with-packages/bin/ghc'
export XMONAD_XMESSAGE='/nix/store/pf8v9m80qfzk6skscjpim0agiw38p8fm-xmessage-1.0.5/bin/xmessage'
exec "/nix/store/43blmhnycp1p572k8p6i2940ygc360a3-ghc-8.8.2-with-packages/bin/xmonad"  "$@"

So for some reason the ghc configuration for xmonad is not exposing the necessary packages, and I have no idea how to expose them.

I removed the extraPackages from my configuration, but that did not make any difference. I can compile xmonad using

$ $NIX_GHC -dynamic -package xmonad-contrib -package xmonad xmonad.hs

(btw, I need the -dynamic flag since I use a package that I had to install with cabal-install with my user. I should eventually make nix instead of cabal-install manage that package…)

This is probably incorrect.

If you want NixOS to deal with XMonad for you, you will not be able to install extra packages directly with cabal-install. You’ll instead have to add any extra packages you need to services.xserver.windowManager.xmonad.extraPackages.

If you have time, I suggest you read some introductions to NixOS (and even better, maybe a blog post or two about how to use XMonad with NixOS). They should help you get your head around how to configure your system with NixOS.

If you want to continue asking for help here, please provide an SSCCE of all the code you’re having problems with, including all error messages and all relevant logs.


Also, I’m just wondering, is the $NIX_GHC in your environment the same $NIX_GHC from the xmonad wrapper?


edit: One more thing:

(btw, I need the -dynamic flag since I use a package that I had to install with cabal-install with my user. I should eventually make nix instead of cabal-install manage that package…)

As far as I am aware, -dynamic just has to do with the creation of dynamic vs. static Haskell libraries. It doesn’t have anything to do with being able to get packages from different package databases?

since xmonad calls ghc you should probably add xmonad and xmonad-contrib to system haskell packages using ghcWithPackages

since xmonad calls ghc you should probably add xmonad and xmonad-contrib to system haskell packages using ghcWithPackages

This is incorrect.

You explicitly don’t have to do this because of how XMonad (and the Haskell stuff in general) works in NixOS.

In general, adding xmonad and xmonad-contrib to environment.systemPackages is a mistake. Do not do this.

Yeah I was wrong. Didn’t realize that the xmonad binary is actually a wrapper

Yes, I know. I just wanted to make it compile before make the setup clean. As I understand, things I do as my user can’t possibly break what is in /nix/store.

That’s the thing. Every place I found basically said to add the following to configuration.nix and everything should work fine:

windowManager = {
        xmonad.enable = true; 
        xmonad.enableContribAndExtras = true;
};

I’ll try to test a minimal configuration later, without xfce and other stuff.

They are indeed different, but I tried both and both work.

Precisely. I configured cabal-install to use dynamic linkage by default, and when I installed the library I wanted it only installed the dynamic version. So for GHC to be able to use it, I had to add -dynamic. I could’ve also installed a static version of the library.

Man, I feel really silly now.

I added the additional package I needed to extraPackages as @cdepillabout said to, and then I removed the file ~/.ghc/x86_64-linux-8.8.2/environments/default, which was the package database which GHC was using, and now it works when I run /run/current-system/sw/bin/xmonad --recompile.

For some reason xmonad is pointing to ~/.nix-profile/bin/xmonad instead, but I think that just some leftover of a mess I must have made with nix-env while trying to get this to work. So I just need to fix that, and I’ll be settled. But I think I can figure that one out on my own.

Thanks a lot for the help!

1 Like