简体   繁体   English

Nix上的XMonad-找不到xmonad-contrib

[英]XMonad on Nix - cannot find xmonad-contrib

I am trying to use nix on ubuntu, with XMonad as my window manager. 我正在XMonad作为窗口管理器,试图在ubuntu上使用nix。 I have this working well on one host using nixOS, but I have a second device that isn't yet ready for nixOS. 我可以在使用nixOS的一台主机上很好地工作,但是我还没有第二台设备可用于nixOS。 nix on top of Ubuntu is mostly working well there, but xmonad cannot find contributory libraries. 在Ubuntu之上的nix在那里通常可以很好地工作,但是xmonad无法找到贡献性库。

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

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: 通过将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
$

with this, this ghc(i) works well: 这样,此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 ...

But even the version of xmonad in that dir cannot find the libs: 但是,即使该目录中的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.

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. 我可以通过使用上述ghc进行编译,然后将输出手动移至〜/ .xmonad / xmonad-x86_64-linux并运行它来解决此问题。 But this is a wee bit hacky, and surely shouldn't be necessary? 但是,这有点棘手,当然应该没有必要吗?

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. 本质上,我们需要使用xmonad-with-packages并列出软件包,而不是ghc-with-packages。

To achieve this, we provide our own xmonad, referenced from within ~/.nixpkgs/config.nix : 为此,我们提供了自己的xmonad,它在~/.nixpkgs/config.nix引用:

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

And fill out ~/.nixpkgs/xmonad/default.nix thus: 然后填写~/.nixpkgs/xmonad/default.nix

{ 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! 这将安装一个xmonad,它知道在哪里可以找到其库,一切都很好!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM