update pkgs documentation

This commit is contained in:
benneti 2021-09-02 11:37:21 +02:00 committed by GitHub
parent 079adc4474
commit 0536d0de90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,18 +13,45 @@ the supported systems listed in the package's `meta.platforms` attribute.
And, as usual, every package in the overlay is also available to any NixOS And, as usual, every package in the overlay is also available to any NixOS
[host](../concepts/hosts.md). [host](../concepts/hosts.md).
Another convenient difference is that it is possible to use
[nvfetcher](https://github.com/berberman/nvfetcher) to keep packages up to
date.
This is best understood by the simple example below.
## Example ## Example
It is possible to specify sources separately to keep them up to date semi
automatically.
The basic rules are specified in pkgs/sources.toml:
```toml
# nvfetcher.toml
[libinih]
src.github = "benhoyt/inih"
fetch.github = "benhoyt/inih"
```
After changes to this file as well as to update the packages specified in there run
nvfetcher (for more details see [nvfetcher](https://github.com/berberman/nvfetcher)).
The pkgs overlay is managed in
pkgs/default.nix:
```nix
final: prev: {
# keep sources first, this makes sources available to the pkgs
sources = prev.callPackage (import ./_sources/generated.nix) { };
# then, call packages with `final.callPackage`
libinih = prev.callPackage ./development/libraries/libinih { };
}
```
Lastly the example package is in
pkgs/development/libraries/libinih/default.nix: pkgs/development/libraries/libinih/default.nix:
```nix ```nix
{ stdenv, meson, ninja, lib, srcs, ... }: { stdenv, meson, ninja, lib, sources, ... }:
let inherit (srcs) libinih; in
stdenv.mkDerivation { stdenv.mkDerivation {
pname = "libinih"; pname = "libinih";
# version will resolve to 53, as specified in the final example below # version will resolve to the latest available on gitub
inherit (libinih) version; inherit (sources.libinih) version src;
src = libinih;
buildInputs = [ meson ninja ]; buildInputs = [ meson ninja ];
@ -32,12 +59,14 @@ stdenv.mkDerivation {
} }
``` ```
pkgs/default.nix:
```nix ## Migration from flake based approach
final: prev: { Previous to nvfetcher it was possible to manage sources via a pkgs/flake.nix, the main changes from there are that sources where in the attribute "srcs" (now "sources") and the contents of the sources where slightly different.
libinih = prev.callPackage ./development/libraries/libinih { }; In order to switch to the new system, rewrite pkgs/flake.nix to a pkgs/sources.toml file using the documentation of nvfetcher,
} add the line that calls the sources at the beginning of pkgs/default.nix, and
``` accomodate the small changes in the packages as can be seen from the example.
The example package looked like:
pkgs/flake.nix: pkgs/flake.nix:
```nix ```nix
@ -51,4 +80,30 @@ pkgs/flake.nix:
} }
``` ```
pkgs/default.nix:
```nix
final: prev: {
# then, call packages with `final.callPackage`
libinih = prev.callPackage ./development/libraries/libinih { };
}
```
pkgs/development/libraries/libinih/default.nix:
```nix
{ stdenv, meson, ninja, lib, srcs, ... }:
let inherit (srcs) libinih; in
stdenv.mkDerivation {
pname = "libinih";
# version will resolve to 53, as specified in the flake.nix file
inherit (libinih) version;
src = libinih;
buildInputs = [ meson ninja ];
# ...
}
```
[pkgs]: https://github.com/NixOS/nixpkgs/tree/master/pkgs [pkgs]: https://github.com/NixOS/nixpkgs/tree/master/pkgs