2024-08-30 20:11:05 +02:00
|
|
|
{inputs, ...}: let
|
2024-08-30 22:43:16 +03:00
|
|
|
inherit (inputs.nixpkgs) lib;
|
|
|
|
|
|
|
|
# Define the base library to be extended. Not only will this be an extension
|
|
|
|
# of the nixpkgs library, but it will also be extensible the way nixpkgs lib
|
|
|
|
# is in case the extended library
|
|
|
|
# 1. needs to be extended internally
|
|
|
|
# 2. needs to be extended during outside consumption
|
|
|
|
# Additionally, .extend can be used to extend the lib with
|
|
|
|
# custom, composed functions.
|
|
|
|
lib0 = self: let
|
|
|
|
callLibs = file:
|
|
|
|
import file {
|
|
|
|
inherit inputs;
|
|
|
|
lib = self;
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
extendedLib = {
|
|
|
|
builders = callLibs ./builders.nix;
|
2024-08-30 20:11:05 +02:00
|
|
|
};
|
2024-08-30 22:43:16 +03:00
|
|
|
|
|
|
|
# This makes mkSysytem available *in addition* to `lib.extendedLib.builders.mkSystem`.
|
|
|
|
# The syntax is a matter of preference, but it is good to make sure all custom attribute
|
|
|
|
# sets (e.g., builders) are defined and taken from a separate attrset (extendedLib) to make
|
|
|
|
# absolutely sure we *never* conflict with nixpkgs. Likewise, the function names inherited
|
|
|
|
# here should also be different from ones available under `lib` by default, i.e., you cannot
|
|
|
|
# re-define functions.
|
|
|
|
inherit (self.extendedLib.builders) mkSystem;
|
2024-08-30 20:11:05 +02:00
|
|
|
};
|
2024-08-30 22:43:16 +03:00
|
|
|
|
|
|
|
# This can be used with `.extend` to extend the extended library.
|
|
|
|
extendedLib = lib.makeExtensible lib0;
|
2024-08-28 18:17:55 +02:00
|
|
|
in {
|
2024-08-30 22:43:16 +03:00
|
|
|
# Set the `lib` argument in `perSystem`, for example:
|
|
|
|
# ```
|
|
|
|
# perSystem = {pkgs, lib, ...}: { ...}
|
|
|
|
# ````
|
|
|
|
perSystem._module.args.lib = extendedLib;
|
|
|
|
|
|
|
|
# Prepare `lib` for external usage. This means it can be consumed
|
|
|
|
# from inputs.<name of this flake as an input>` by other flakes.
|
|
|
|
# `self` can also be used to access the custom lib as long as
|
|
|
|
# `flake.lib` is set.
|
2024-08-28 18:17:55 +02:00
|
|
|
flake = {
|
2024-08-30 20:41:07 +02:00
|
|
|
lib = extendedLib;
|
|
|
|
_module.args.lib = extendedLib;
|
2024-08-28 18:17:55 +02:00
|
|
|
};
|
|
|
|
}
|