This command will fetch the latest revision of the Nixpkgs 23.05 release branch.
In the current directory it will generate `nix/sources.json`, which will contain a pinned reference to the obtained revision.
It will also create `nix/sources.nix`, which exposes those dependencies as an attribute set.
Import the generated `nix/sources.nix` as the default value for the argument to the function in `default.nix` and use it to refer to the Nixpkgs source directory:
```nix
{ sources ? import ./nix/sources.nix }:
let
pkgs = import sources.nixpkgs {};
build = pkgs.hello;
in {
inherit build;
}
```
`nix-build` will call the top-level function with the empty attribute set `{}`, or with the attributes passed via [`--arg`](https://nixos.org/manual/nix/stable/command-ref/nix-build#opt-arg) or [`--argstr`](https://nixos.org/manual/nix/stable/command-ref/nix-build#opt-argstr).
This pattern allows [overriding remote sources](overriding-sources-niv) programmatically.
Add niv to the development environment for your project to have it readily available:
Also add a `shell.nix` to enter that environment more conveniently:
```nix
(import ./. {}).shell
```
See [](./sharing-dependencies) for details, and note that here you have to pass an empty attribute set to the imported expression, since `default.nix` now contains a function.
(overriding-sources-niv)=
## Overriding sources
As an example, we will use the previously created expression with an older version of Nixpkgs.
Enter the development environment, create a new directory, and set up niv with a different version of Nixpkgs: