Overview of the Nix Language: Difference between revisions

imported>Roberth
imported>Mickours
Line 427: Line 427:


This trick might be helpful in combination with [https://nixos.org/nix/manual/#builtin-getEnv <code>builtins.getEnv</code>], which returns a string (which might be a path). Be careful, depending on environment variables introduces heavy non-determinism and might lead to rebuilds!
This trick might be helpful in combination with [https://nixos.org/nix/manual/#builtin-getEnv <code>builtins.getEnv</code>], which returns a string (which might be a path). Be careful, depending on environment variables introduces heavy non-determinism and might lead to rebuilds!
If you need to '''build a path from a mix of paths and strings variables''', you can concatenate strings and paths, but you need to be careful of the evaluation order because Nix removes trailing  <code>/</code>.
For example if you need to concatenate <code>/data</code> with a variable call <code>my_var</code> you need to add parenthesis:
<syntaxHighlight lang=nix>
nix-repl> let my_var = "tmp"; in /data + "/" + my_var  # WRONG
/datatmp
nix-repl> let my_var = "tmp"; in /data + ("/" + my_var) # Better :)
/data/tmp
</syntaxHighlight>


=== Writing update scripts / Referencing a relative path as string ===
=== Writing update scripts / Referencing a relative path as string ===