2021-02-14 02:38:20 +00:00
|
|
|
# Packages
|
2021-04-19 02:26:27 +00:00
|
|
|
Similar to [modules](./modules.md), the pkgs directory mirrors the upstream
|
2021-02-14 02:38:20 +00:00
|
|
|
[nixpkgs/pkgs][pkgs], and for the same reason; if you ever want to upstream
|
|
|
|
your package, it's as simple as dropping it into the nixpkgs/pkgs directory.
|
|
|
|
|
|
|
|
The only minor difference is that, instead of adding the `callPackage` call to
|
|
|
|
`all-packages.nix`, you just add it the the _default.nix_ in this directory,
|
|
|
|
which is defined as a simple overlay.
|
|
|
|
|
|
|
|
This overlay is set as the default `overlay` output attribute for the flake.
|
|
|
|
And all the packages are exported via `packages.<system>.<pkg-name>`, for all
|
|
|
|
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
|
2021-04-19 02:26:27 +00:00
|
|
|
[host](../concepts/hosts.md).
|
2021-02-14 02:38:20 +00:00
|
|
|
|
2021-02-23 02:49:31 +00:00
|
|
|
## Automatic Source Updates
|
|
|
|
There is the added, but optional, convenience of declaring your sources in
|
2021-03-14 07:10:51 +00:00
|
|
|
_pkgs/flake.nix_ as an input. You can then access them from the `srcs` package.
|
|
|
|
This allows updates to be managed automatically by simply
|
2021-04-19 02:26:27 +00:00
|
|
|
[updating](../flk/update.md#updating-package-sources) the lock file. No
|
2021-03-14 07:10:51 +00:00
|
|
|
more manually entering sha256 hashes!
|
2021-02-23 02:49:31 +00:00
|
|
|
|
2021-03-14 07:10:51 +00:00
|
|
|
As an added bonus, version strings are also generated automatically from either
|
2021-04-19 02:26:27 +00:00
|
|
|
the flake ref, or the date and git revision of the source.
|
2021-02-23 02:49:31 +00:00
|
|
|
|
2021-02-14 02:38:20 +00:00
|
|
|
## Example
|
|
|
|
pkgs/development/libraries/libinih/default.nix:
|
|
|
|
```nix
|
2021-02-23 02:49:31 +00:00
|
|
|
{ stdenv, meson, ninja, lib, srcs, ... }:
|
2021-03-14 07:10:51 +00:00
|
|
|
let inherit (srcs) libinih; in
|
2021-02-14 02:38:20 +00:00
|
|
|
stdenv.mkDerivation {
|
|
|
|
pname = "libinih";
|
|
|
|
|
2021-03-14 07:10:51 +00:00
|
|
|
# version will resolve to 53, as specified in the final example below
|
|
|
|
inherit (libinih) version;
|
2021-02-14 02:38:20 +00:00
|
|
|
|
2021-03-14 07:10:51 +00:00
|
|
|
src = libinih;
|
2021-02-14 02:38:20 +00:00
|
|
|
|
2021-03-14 07:10:51 +00:00
|
|
|
buildInputs = [ meson ninja ];
|
2021-02-14 02:38:20 +00:00
|
|
|
|
2021-03-14 07:10:51 +00:00
|
|
|
# ...
|
2021-02-14 02:38:20 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
pkgs/default.nix:
|
|
|
|
```nix
|
|
|
|
final: prev: {
|
|
|
|
libinih = prev.callPackage ./development/libraries/libinih { };
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2021-02-23 02:49:31 +00:00
|
|
|
pkgs/flake.nix:
|
|
|
|
```nix
|
|
|
|
{
|
|
|
|
description = "Package sources";
|
|
|
|
|
|
|
|
inputs = {
|
|
|
|
libinih.url = "github:benhoyt/inih/r53";
|
|
|
|
libinih.flake = false;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2021-02-14 02:38:20 +00:00
|
|
|
[pkgs]: https://github.com/NixOS/nixpkgs/tree/master/pkgs
|