How to use nixos container's `path`?

From the doc:

containers.<name>.path
           As an alternative to specifying config, you can specify
           the path to the evaluated NixOS system configuration,
           typically a symlink to a system profile.

           Type: path

           Example: "/nix/var/nix/profiles/per-container/webserver"

I have a container like that, and built the path with nix build someFlake#nixosConfigurations.<name>.config.system.build.toplevel --profile /nix/var/nix/profiles/per-container/webserver
but the container could not start, complaining: /nix/store/<hash>-container-init: line 36: /nix/var/nix/profiles/per-container/webserver/init: No such file or directory even when I can confirm that path exists.

okay, I’ve figured it out. The said path is from inside the container, not the host. I had to bind mount the flake output link path to the container.

1 Like