Nix (language): Difference between revisions

imported>Colemickens
add helpful bit about paths and interpolation
imported>Colemickens
mNo edit summary
Line 508: Line 508:


Sometimes you need to interpolate the value of a Nix variable into the path for an import, however these will not work:
Sometimes you need to interpolate the value of a Nix variable into the path for an import, however these will not work:
* <code>./desktop-${desktop}.nix</code>
* <code>./desktop-${desktop}.nix</code> (invalid curly, can't interpolate outside of a string in this location)
* <code>"./desktop-${desktop}.nix"</code>
* <code>"./desktop-${desktop}.nix"</code> (nix paths must be absolute)
* <code>./. + "./desktop-${desktop}.nix"</code>
* <code>./. + "desktop-${desktop}.nix"</code> (missing slash at the start of the string part)
* <code>./. + "./desktop-${desktop}.nix"</code> (can't have the dot in front of that same slash)


Instead, use this construction:
Instead, use this construction:
Line 533: Line 534:
}
}
</syntaxHighlight>
</syntaxHighlight>
```
 
Note that this requires <code>./.</code> to refer to the current directory, but also importantly requires the leading slash on the quoted-string-path part.


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