简体   繁体   English

如何使用 cabal/haskell 设置多个环境变量?

[英]How to set multiple environment variables with cabal/haskell?

I am making use of postgresql-typed library which needs multiple environment variables to be set before it runs.我正在使用postgresql-typed库,它需要在运行之前设置多个环境变量。

Right now, I am manually setting them using the shell profile script (zsh profile) before I can run any of the cabal commands like cabal build or cabal run .现在,我正在使用 shell 配置文件脚本(zsh 配置文件)手动设置它们,然后才能运行任何 cabal 命令,如cabal buildcabal run

But this is clumsy and doesn't work across all the platforms.但这很笨拙并且不适用于所有平台。 Is there a idiomatic Haskell/Cabal way of doing this (For example, adding them from .env file or something)?是否有惯用的 Haskell/Cabal 方法来执行此操作(例如,从.env文件或其他文件中添加它们)?

As far as I know, cabal does not have a generalized tool for mucking about with environment variables.据我所知,cabal 没有一个通用的工具来处理环境变量。 In my opinion, this is good design, of the "do one thing and do it well" variety -- there are already good external tools for setting up environment variables, some of which are quite large and complicated, and duplicating that work inside cabal is not called for.在我看来,这是一个很好的设计,属于“做一件事并做好”的变体——已经有很好的外部工具来设置环境变量,其中一些非常大和复杂,并在 cabal 中复制该工作不需要。

Cabal does set a few environment variables on your behalf, but only those an external tool has no way to set properly, such as file system pointers to intermediate build products or intended installation directories. Cabal 确实为您设置了一些环境变量,但只有那些外部工具无法正确设置的环境变量,例如指向中间构建产品或预期安装目录的文件系统指针。

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

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