Problem creating a nixosConfiguration flake for a remote machine on non-nixos

I am building with a flake nixosConfiguration for other machine. In my nixos machine all works like expected:

nixos-rebuild build --flake '.#rpi'

I tested on other non-nixos machine:

I open a shell with nixos-rebuild:
`nix-shell -E “with import {}; mkShell { buildInputs = [ (nixos {}).nixos-rebuild ]; }”

$ nixos-rebuild build --flake ‘.#rpi
error: unrecognised flag ‘–experimental-features’
Try ‘nix --help’ for more information
This machine is non-nixos, Can I run this using “nix build” command?
Is it possible to fix “nixos-rebuild --flake”?

AFAIK you also need to pull nixFlakes and nixUnstable into the shell to actually get those features.

Right now both are one and the same, and I feel the ecosystem has grown enough that nixUnstable won’t ship without flakes anymore.

But yes, nix-env -iA nixpkgs.nixFlakes should do it in a standard setup.

I get the same error with nixFlakes package at shell:

nix-shell -E "with import <nixpkgs> {}; mkShell { buildInputs = [ (nixos {}).nixos-rebuild nixFlakes ]; }"
$ nix --version
nix (Nix) 3.0pre20201020_e0ca98c

$nixos-rebuild build --flake '.#rpi'
error: unrecognised flag '--experimental-features'
Try 'nix --help' for more information.

$ nix flake show
warning: Git tree 'xxxx' is dirty
│   └───x86_64-linux: development environment 'nix-shell-arm-unknown-linux-gnueabihf'
│   └───rpi: NixOS configuration
└───overlay: Nixpkgs overlay

I have check nix version and that “nix flake” command is running correctly.

The nice thing is, if you only want to build, then you can use nix build like I do on CI:

That’s because nixos-rebuild uses the NixOS configuration’s Nix, not the one in your environment. Thus:

(nixos { nix.package = nixFlakes; }).nixos-rebuild

(I didn’t know you didn’t need though…)

@NobbZ Solution is good enough for me now.

It is in a non-nixos system (debian). Could be a problem with nixos-rebuild calling the wrong version of nix? I suspect that because of the error: