Locked reports whether r is locked. Locked flake references always resolve to the same content. For some flake types, determining if a Ref is locked depends on the local Nix configuration. In these cases, Locked conservatively returns false.
()
| 305 | // depends on the local Nix configuration. In these cases, Locked conservatively |
| 306 | // returns false. |
| 307 | func (r Ref) Locked() bool { |
| 308 | // Search for the implementations of InputScheme::isLocked in the nix |
| 309 | // source. |
| 310 | // |
| 311 | // https://github.com/search?q=repo%3ANixOS%2Fnix+language%3AC%2B%2B+symbol%3AisLocked&type=code |
| 312 | |
| 313 | switch r.Type { |
| 314 | case TypeFile, TypePath, TypeTarball: |
| 315 | return r.NARHash != "" |
| 316 | case TypeGit: |
| 317 | return r.Rev != "" |
| 318 | case TypeGitHub: |
| 319 | // We technically can't determine if a github flake is locked |
| 320 | // unless we know the trust-tarballs-from-git-forges Nix setting |
| 321 | // (which defaults to true), so we have to be conservative and |
| 322 | // check for rev and narHash. |
| 323 | // |
| 324 | // https://github.com/NixOS/nix/blob/3f3feae33e3381a2ea5928febe03329f0a578b20/src/libfetchers/github.cc#L304-L313 |
| 325 | return r.Rev != "" && r.NARHash != "" |
| 326 | case TypeIndirect: |
| 327 | // Never locked because they must be resolved against a flake |
| 328 | // registry. |
| 329 | return false |
| 330 | default: |
| 331 | return false |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | // String encodes the flake reference as a URL-like string. It normalizes the |
| 336 | // result such that if two Ref values are equal, then their strings will also be |