Nixos configuration imports (absolute) path vs string error: string './config/z_device_P340.nix' doesn't represent an absolute path

device_P340     = "P340" ; 
 imports =

    ./config/z_device_P340.nix # works but isn't proper as it contains a variable as fix string
    "./config/z_device_${device}.nix" # issue 


error: string './config/z_device_P340.nix' doesn't represent an absolute path

builtins.asPath does not change it

What is the current correct way in nixos?

device_P340     = "P340" ; 
 imports =

Probably. Imports expect actual paths, not strings. No, paths are just resolved to be absolute at runtime. Interpolation works on those too, afaik.

Edit: yes, and it’s apparently called anti-quotation: Data Types

Path interpolation is a recent thing.

If path interpolation is not available in OPs version, then building a path programatically is like ./config + "/z_device_${device}.nix"

1 Like
 - system: `"x86_64-linux"`
 - host os: `Linux 5.15.64, NixOS, 22.05 (Quokka), 22.05.2992.45b56b5321a`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.8.1`
 - channels(root): `"home-manager-22.05.tar.gz, nixos-22.05"`
 - channels(a): `""`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
building Nix...
error: syntax error, unexpected '+'
  1. 2.8 does not have path interpolation
  2. you might need to wrap the expression in parenthesis to staisfy the parser. This is especially true in lists

thanks, looks to work as well