Overview of the Nix Language: Difference between revisions
imported>Caretcafe mNo edit summary |
imported>Colemickens add helpful bit about paths and interpolation |
||
Line 504: | Line 504: | ||
/data/tmp | /data/tmp | ||
</syntaxHighlight> | </syntaxHighlight> | ||
=== Coercing a relative path with interpolated variables to an absolute path (for imports) === | |||
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> | |||
* <code>./. + "./desktop-${desktop}.nix"</code> | |||
Instead, use this construction: | |||
* <code>./. + "./desktop-${desktop}.nix"</code> | |||
As a fuller example: | |||
<syntaxHighlight lang=nix> | |||
let | |||
desktops = [ "elementary" "gnome" "plasma" "sway" ]; | |||
in | |||
{ | |||
config.specialisation = | |||
pkgs.lib.genAttrs desktops (desktop: { | |||
configuration = { | |||
boot.loader.grub.configurationName = "${desktop}"; | |||
imports = [ | |||
(./. + "/desktop-${desktop}.nix") | |||
]; | |||
}; | |||
}); | |||
} | |||
</syntaxHighlight> | |||
``` | |||
=== Writing update scripts / Referencing a relative path as string === | === Writing update scripts / Referencing a relative path as string === |