haskell - Nix 上的 XMonad - 找不到 xmonad-contrib

标签 haskell ghc xmonad nix

我正在尝试在 ubuntu 上使用 nix,并使用 XMonad 作为我的窗口管理器。 我在一台使用 nixOS 的主机上运行良好,但我有第二台设备尚未准备好支持 nixOS。 Ubuntu 之上的 nix 基本上运行良好,但 xmonad 找不到贡献库。

相关软件包已安装:

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

但是重新编译我的 xmonad.hs,它找不到 contrib 库:

$ 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.

相关文件已安装:

$ 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

通过将 xmonad-contrib 添加到我的 nixpkgs config.nix,我已将这些库添加到 ghc 包注册表中:

$ 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
$

有了这个,这个 ghc(i) 就可以很好地工作:

$ /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 ...

但即使该目录中的 xmonad 版本也找不到库:

$ /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.

我可以通过使用上面的 ghc 进行编译,然后手动将输出移动到 ~/.xmonad/xmonad-x86_64-linux 并运行它来解决这个问题。但这有点hacky,而且肯定没有必要吗?

最佳答案

一位 friend 离线为我解决了这个问题,我在这里为其他有同样问题的人重现这个问题。

本质上,我们需要使用 xmonad-with-packages 并列出包,而不是 ghc-with-packages。

为了实现这一点,我们提供了自己的 xmonad,从 ~/.nixpkgs/config.nix 中引用:

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

并填写~/.nixpkgs/xmonad/default.nix:

{ nixpkgs ? import <nixpkgs> {} }:

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

这会安装一个 xmonad,它知道在哪里可以找到它的库,一切都很好!

关于haskell - Nix 上的 XMonad - 找不到 xmonad-contrib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44778404/

相关文章:

Haskell 堆栈 : Missing C library Xft when using stack building X11-xft?

haskell - xmonad 如何为屏幕分配编号,以及如何将屏幕分配给(两个)显示器

Haskell 基础类

Haskell——标签集分区用什么?

haskell - 为什么 sum 在 haskell 中比 foldl' 慢?

haskell - 如何消除选择器功能的歧义?

haskell - 为 GHC 和 Makefile 样式构建生成正确的链接依赖项

haskell - 从 Get monad 读取位的 Monadic 方式

haskell - haskell 中列表的强制严格性

haskell - XMonad 在不同工作区启动