|
|
Line 175: |
Line 175: |
| </syntaxHighlight> | | </syntaxHighlight> |
| and <code>nativeBuildInputs</code> would be for the native platform, while <code>buildInputs</code> would be for the foreign platform. That's a much more practical distinction: any tool that's miscategorized one won't be able to run, and any library that's miscategorized one won't be able to link! | | and <code>nativeBuildInputs</code> would be for the native platform, while <code>buildInputs</code> would be for the foreign platform. That's a much more practical distinction: any tool that's miscategorized one won't be able to run, and any library that's miscategorized one won't be able to link! |
|
| |
| == direnv ==
| |
|
| |
| One of the limitations of nix-shell is that you can't use a shell other than bash. Thankfully, there is Direnv [[https://direnv.net/]] with the support of Nix[[https://github.com/direnv/direnv/wiki/Nix]] to overcome this limitation. Also, Direnv provides some nice features like loading the environment automatically when you enter your project directory and show the loaded variables to you (explicit is always better;-)).
| |
|
| |
| First, install Direnv:
| |
| <syntaxHighlight lang=bash>
| |
| nix-env -i direnv
| |
| </syntaxHighlight>
| |
|
| |
| Now, you need to add one more file in the root of your repository named <code>.envrc</code> that contains only this:
| |
| <syntaxHighlight lang=bash>
| |
| use_nix
| |
| </syntaxHighlight>
| |
|
| |
| Then depending on the shell you are using, you need to add a line in your configuration file. See the ''Setup'' section of the doc[https://direnv.net/]. For example, for Zsh put in your <code>~/.zshrc.local</code>:
| |
| <syntaxHighlight lang=bash>
| |
| eval "$(direnv hook zsh)"
| |
| </syntaxHighlight>
| |
|
| |
| Then, still at the root of your repository, run:
| |
| <syntaxHighlight lang=bash>
| |
| $ direnv allow .
| |
| direnv: loading .envrc
| |
| direnv: using nix
| |
| [...]
| |
| +SIZE +SOURCE_DATE_EPOCH +STRINGS +STRIP +TEMP +TEMPDIR +TMP +TMPDIR +_PATH +buildInputs +builder +checkPhase +cmakeFlags +configureFlags +doCheck +enableParallelBuilding +name +nativeBuildInputs +out +postCheck +preCheck +preConfigure +propagatedBuildInputs +propagatedNativeBuildInputs +shell +src +stdenv +system +testInputs +version ~PATH
| |
| </syntaxHighlight>
| |
|
| |
| Bonus: you can see all the variables set by the nix-shell :)
| |
|
| |
| Now you can leave your project and the environment will be unloaded:
| |
| <syntaxHighlight lang=bash>
| |
| $ cd ..
| |
| direnv: unloading
| |
| </syntaxHighlight>
| |
|
| |
| No need to use <code>direnv allow</code> anymore, the next time you go to your project the environment will be loaded!
| |
|
| |
| More explanation and configuration tweaks can be found in the Direnv wiki [https://github.com/direnv/direnv/wiki/Nix].
| |
|
| |
|
| == Troubleshooting == | | == Troubleshooting == |