NixOS installation in Ubuntu Hirsute

When I try to download nixOS, I get this error, and the downloaded tar ball gets automatically deleted. I am using ubuntu hirsute.

HP-Pavilion:/home$ curl -L https://nixos.org/nix/install | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  2619  100  2619    0     0   6191      0 --:--:-- --:--:-- --:--:--  6191
downloading Nix 2.3.15 binary tarball for x86_64-linux from 'https://releases.nixos.org/nix/nix-2.3.15/nix-2.3.15-x86_64-linux.tar.xz' to '/tmp/nix-binary-tarball-unpack.mYPOHwGbIZ'...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 25.6M  100 25.6M    0     0  3032k      0  0:00:08  0:00:08 --:--:-- 3605k
/tmp/nix-binary-tarball-unpack.mYPOHwGbIZ/unpack/nix-2.3.15-x86_64-linux/install: $HOME is not set

Then I set $HOME as my /home/user directory with the env command. But it shows the same error.

env only changes the environment for its childs, so if you want to use env you need to do it like this:

$ curl -L https://nixos.org/nix/install | env 'HOME=/home/user' sh

Or alternatively use your shells environment management tools to set HOME like this:

$ export HOME=/home/user
$ curl -L https://nixos.org/nix/install | sh

Though I am wondering why HOME is not already set…

Ok even I don’t know why it says $HOME wasn’t set, but now that i set it in the code and ran it as you suggested, I am getting a different error:

HP-Pavilion:/home $ curl -L https://nixos.org/nix/install | env 'HOME=/home/user' sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  2619  100  2619    0     0    814      0  0:00:03  0:00:03 --:--:--   941
downloading Nix 2.3.15 binary tarball for x86_64-linux from 'https://releases.nixos.org/nix/nix-2.3.15/nix-2.3.15-x86_64-linux.tar.xz' to '/tmp/nix-binary-tarball-unpack.sBCCmnvjjI'...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 25.6M  100 25.6M    0     0  5494k      0  0:00:04  0:00:04 --:--:-- 5736k
Note: a multi-user installation is possible. See https://nixos.org/nix/manual/#sect-multi-user-installation
performing a single-user installation of Nix...
copying Nix to /nix/store...

error: could not set permissions on '/nix/var/nix/profiles/per-user' to 755: Operation not permitted
/tmp/nix-binary-tarball-unpack.sBCCmnvjjI/unpack/nix-2.3.15-x86_64-linux/install: unable to register valid paths