`nix flake update --flake /etc/nixos` failed

$ sudo nix flake update --flake /etc/nixos
error: unrecognised flag '--flake'
Try 'nix --help' for more information.

But in nix flake update - Nix Reference Manual, it stated that:

Update only a single input of a flake in a different directory:

 nix flake update nixpkgs --flake ~/repos/another
warning: updating lock file '/home/myself/repos/another/flake.lock':
β€’ Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/3d2d8f281a27d466fa54b469b5993f7dde198375' (2023-06-30)
  β†’ 'github:NixOS/nixpkgs/a3a3dda3bacf61e8a39258a0ed9c924eeca8e293' (2023-07-05)

and

Options
–flake flake-url
The flake to operate on. Default is the current directory.

but in nix flake update --help, the --flake flag is missing.
How can I run nix flake update without cd to that directory?
Thank for your help!!

What version of nix are you using? This is a recent change.

For nix older than 2.19 you have to use nix flake $location.

1 Like

Yes, I am on NixOS 23.11, with nix version 2.18.1.
Installed nixVersions.nix_2_19. Thanks!

Set nix.package to a newer version.

$ nix eval nixpkgs#nixVersions --apply builtins.attrNames --json | jq '.[]' -r
…
nix_2_10
nix_2_11
nix_2_12
nix_2_13
nix_2_14
nix_2_15
nix_2_16
nix_2_17
nix_2_18
nix_2_19
nix_2_3
nix_2_4
nix_2_5
nix_2_6
nix_2_7
nix_2_8
nix_2_9
…
stable
unstable

These are the available versions and stable is whatever is considered the current stable release for NixOS.

This usually changes exactly once during a release cycle on unstable and never on stable.

1 Like

I totally missed the nix.package option.
Set it to nix.package = pkgs.nixVersions.nix_2_19; the it is upgraded to the latest version.
Thank you very much!