加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

在NixOS中从Haskell运行shell命令

发布时间:2020-12-15 17:00:15 所属栏目:安全 来源:网络整理
导读:我是NixOS的新手,我正在尝试使用以下函数从 Haskell程序调用emacs: ediff :: String - String - String - IO ()ediff testName a b = do a' - writeSystemTempFile (testName ++ ".expected") a b' - writeSystemTempFile (testName ++ ".received") b let
我是NixOS的新手,我正在尝试使用以下函数从 Haskell程序调用emacs:
ediff :: String -> String -> String -> IO ()
ediff testName a b = do
  a' <- writeSystemTempFile (testName ++ ".expected") a
  b' <- writeSystemTempFile (testName ++ ".received") b
  let quote s = """ ++ s ++ """
  callCommand $"emacs --eval '(ediff-files " ++ quote a' ++ quote b' ++ ")'"

当我运行使用堆栈测试调用此命令的程序时,我得到以下结果(穿插单元测试结果):

/bin/sh: emacs: command not found
Exception: callCommand: emacs --eval '(ediff-files "/run/user/1000/ast1780695788709393584.expected" "/run/user/1000/ast4917054031918502651.received")'

当我运行无法从我的shell运行上面的命令时,它运行完美.如何从NixOS中的Haskell运行进程,就像我直接调用它们一样,以便它们可以访问与我的用户相同的命令和配置?

你的shell和callCommand都使用PATH环境变量,所以看起来堆栈正在改变它.事实证明,默认情况下堆栈使用纯nix shell,但您也想访问您的用户环境,这是“不纯”.

引用stack documenation

By default,stack will run the build in a pure Nix build environment (or shell),which means the build should fail if you haven’t specified all the dependencies in the packages: section of the stack.yaml file,even if these dependencies are installed elsewhere on your system. This behaviour enforces a complete description of the build environment to facilitate reproducibility. To override this behaviour,add pure: false to your stack.yaml or pass the –no-nix-pure option to the command line.

另一个解决方案是在stack.yaml中将Emacs添加到nix.dependencies(感谢@chepner).它的好处是,当开发人员运行测试时,某些版本的Emacs将始终可用,但Emacs可能不是他们想要使用的Emacs.您可以使用?/ .config / nixpkgs / config.nix之类的东西来解决这个问题,除非他们已经在其他地方配置了他们的Emacs,比如系统配置或主管理器.我更喜欢简单但不纯的$PATH解决方案.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读