devos/pkgs
Timothy DeHerrera d51cd34fb7
subflakes: make first class citizens
Subflakes should provide their wares as outputs, so wire up the pkgs
flake to reflect that.

Due to the unstable nature of flakes, updating the root flake doesn't
currently update the subflake lock file. Therefore, add additional
logic to flk update script in order to do this behind the scenes.

Nix is now pulled in from the "nix" registry flake in order for users
to take advantage of improvements to the UI since its last update in
nixpkgs.
2021-03-14 21:27:58 -06:00
..
tools/package-management/nix nix: patch nix directly for experimental features 2021-02-17 12:54:41 -07:00
default.nix create core branch without any profiles 2021-02-03 18:58:58 -07:00
flake.lock subflakes: make first class citizens 2021-03-14 21:27:58 -06:00
flake.nix subflakes: make first class citizens 2021-03-14 21:27:58 -06:00
README.md treewide cleanups and refactoring for initial tests (#157) 2021-03-14 07:10:51 +00:00

Packages

Similar to modules, the pkgs directory mirrors the upstream nixpkgs/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 host.

Automatic Source Updates

There is the added, but optional, convenience of declaring your sources in pkgs/flake.nix as an input. You can then access them from the srcs package. This allows updates to be managed automatically by simply updating the lock file. No more manually entering sha256 hashes!

As an added bonus, version strings are also generated automatically from either the flake ref, or the date and git revision of the source. For examples, definitely checkout the community branch.

Example

pkgs/development/libraries/libinih/default.nix:

{ stdenv, meson, ninja, lib, srcs, ... }:
let inherit (srcs) libinih; in
stdenv.mkDerivation {
  pname = "libinih";

  # version will resolve to 53, as specified in the final example below
  inherit (libinih) version;

  src = libinih;

  buildInputs = [ meson ninja ];

  # ...
}

pkgs/default.nix:

final: prev: {
  libinih = prev.callPackage ./development/libraries/libinih { };
}

pkgs/flake.nix:

{
  description = "Package sources";

  inputs = {
    libinih.url = "github:benhoyt/inih/r53";
    libinih.flake = false;
  };
}