As I understand, the purpose of a lock file is to list the exact version of each input used by a flake. This is why the lock file contains where the input source is from and its revision hash. (In flakes with many inputs, this could result in many different versions of some dependencies, which is why the .inputs.nixpkgs.follows
feature exists to deduplicate versions.) Having all the inputs locked to a version means that the flake is deterministic and reusable: there is no fear that a later version could break, since the rev is pinned in the lock file.
This all makes sense to me, which makes the following behavior of nix flake show
confusing. The first command below fails because it can’t write a lock file – but why is it trying to write a lock file at all, when the lock file is right there in the git repo? (I did check that flake.lock
was committed to the repo in question.) The second command explains why it’s trying to write a lock file: it’s updating the nixpkgs input to the latest rev. Doesn’t that defeat the whole purpose of a lock file? Why would nix update the dependencies just to display the contents of the flake?
This seems like a pretty obvious bug, so I feel like I must be misunderstanding something above.
$ nix flake show github:nix-community/NixOS-WSL
error: cannot write modified lock file of flake 'github:nix-community/NixOS-WSL' (use '--no-write-lock-file' to ignore)
(use '--show-trace' to show detailed location information)
$ nix flake show github:nix-community/NixOS-WSL --no-write-lock-file
warning: not writing modified lock file of flake 'github:nix-community/NixOS-WSL':
• Updated input 'nixpkgs':
'github:NixOS/nixpkgs/e8ec26f41fd94805d8fbf2552d8e7a449612c08e' (2022-12-09)
→ 'github:NixOS/nixpkgs/0938d73bb143f4ae037143572f11f4338c7b2d1c' (2022-12-17)
github:nix-community/NixOS-WSL/fab2833c091e059fd75e0c2cd570279500e76351
├───checks
│ ├───aarch64-linux
│ │ ├───nixpkgs-fmt: derivation 'check-nixpkgs-fmt'
│ │ ├───shfmt: derivation 'check-shfmt'
│ │ └───side-effects: derivation 'empty-file'
│ └───x86_64-linux
│ ├───nixpkgs-fmt: derivation 'check-nixpkgs-fmt'
│ ├───shfmt: derivation 'check-shfmt'
│ └───side-effects: derivation 'empty-file'
├───devShell
│ ├───aarch64-linux: development environment 'nix-shell'
│ └───x86_64-linux: development environment 'nix-shell'
├───nixosConfigurations
│ └───mysystem: NixOS configuration
└───nixosModules
└───wsl: NixOS module