Home Explore Blog Models CI



nix

src/nix/flake-lock.md
72453b09fe8f4339bf03e20eb28a52386a3ee9465834c3b300000003000004e9
R""(

# Examples

* Create the lock file for the flake in the current directory:

  ```console
  # nix flake lock
  warning: creating lock file '/home/myself/repos/testflake/flake.lock':
  • Added input 'nix':
      'github:NixOS/nix/9fab14adbc3810d5cc1f88672fde1eee4358405c' (2023-06-28)
  • Added input 'nixpkgs':
      'github:NixOS/nixpkgs/3d2d8f281a27d466fa54b469b5993f7dde198375' (2023-06-30)
  ```

* Add missing inputs to the lock file for a flake in a different directory:

  ```console
  # nix flake lock ~/repos/another
  warning: updating lock file '/home/myself/repos/another/flake.lock':
  • Added input 'nixpkgs':
      'github:NixOS/nixpkgs/3d2d8f281a27d466fa54b469b5993f7dde198375' (2023-06-30)
  ```

  > **Note**
  >
  > When trying to refer to a flake in a subdirectory, write `./another`
  > instead of `another`.
  > Otherwise Nix will try to look up the flake in the registry.

# Description

This command updates the lock file of a flake (`flake.lock`)
so that it contains an up-to-date lock for every flake input specified in
`flake.nix`. Lock file entries are already up-to-date are not modified.

If you want to update existing lock entries, use
[`nix flake update`](@docroot@/command-ref/new-cli/nix3-flake-update.md)

)""

Chunks
f492aadf (1st chunk of `src/nix/flake-lock.md`)
Title: nix flake lock Command: Examples and Description
Summary
This section details the `nix flake lock` command, which is used to create or update the `flake.lock` file for a Nix flake. Its primary function is to ensure that the lock file contains up-to-date lock entries for all flake inputs specified in `flake.nix`, only modifying entries that are missing or out-of-date. The text provides examples for creating a lock file in the current directory and adding missing inputs for a flake in a different directory, along with a note on referring to subdirectories. It also distinguishes this command from `nix flake update`, which is used to update *existing* lock entries.