Lxc exec problem with nixos-rebuild

Hello,

I’m using ansible to deploy and first configure my containers but I’m having a problem with NixOS :

$ lxc exec gaia50012 -- nixos-rebuild switch
error: file 'nixpkgs/nixos' was not found in the Nix search path (add it using $NIX_PATH or -I), at (string):1:13
[...]
$ lxc exec gaia50012 -- bash -c 'nixos-rebuild switch'
error: file 'nixpkgs/nixos' was not found in the Nix search path (add it using $NIX_PATH or -I), at (string):1:13
[...]

When I run the command after going to the container, it works:

$ lxc exec gaia50012 -- bash
[root@gaia50012:~]# nixos-rebuild switch 
building Nix...
building the system configuration...
[...]

Do you have any ideas?

Thank you for reading and to anyone who can help me.

Most likely bash sources some system configuration which extends PATH.

You may be able to workaround this issue by setting the correct environment.PATH config key on the instance so all lxc exec commands get the correct PATH env variable.