2024-07-29 00:35:14 +02:00
|
|
|
{ lib, config, self, inputs, ... }:
|
|
|
|
|
|
|
|
let
|
2024-07-29 01:11:32 +02:00
|
|
|
inherit (config.lib)
|
2024-08-04 01:52:04 +02:00
|
|
|
createThings;
|
2024-07-29 00:35:14 +02:00
|
|
|
in
|
|
|
|
let
|
2024-08-04 01:52:04 +02:00
|
|
|
createPackages = baseDir:
|
|
|
|
createThings {
|
|
|
|
inherit baseDir;
|
|
|
|
thingType = "package";
|
|
|
|
raw = false;
|
|
|
|
extras.systems = {
|
|
|
|
default = lib.const true;
|
|
|
|
};
|
|
|
|
};
|
2024-07-29 00:35:14 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = let
|
|
|
|
inherit (lib) types;
|
|
|
|
in {
|
2024-09-01 03:29:32 +02:00
|
|
|
auto.packages = lib.mkOption {
|
2024-07-29 00:35:14 +02:00
|
|
|
description = ''
|
|
|
|
Automagically generate packages from walking directories with Nix files
|
|
|
|
'';
|
|
|
|
type = types.submodule (submodule: {
|
|
|
|
options = {
|
|
|
|
enable = lib.mkEnableOption "Automatic packages extraction";
|
|
|
|
dir = lib.mkOption {
|
|
|
|
description = ''
|
|
|
|
Base directory of the contained packages
|
|
|
|
'';
|
|
|
|
type = types.path;
|
|
|
|
default = "${self}/pkgs";
|
|
|
|
defaultText = ''''${self}/pkgs'';
|
|
|
|
};
|
|
|
|
result = lib.mkOption {
|
|
|
|
description = ''
|
|
|
|
The resulting automatic packages
|
|
|
|
'';
|
|
|
|
type = types.attrsOf (types.submodule { options = {
|
|
|
|
package = lib.mkOption { type = types.unspecified; };
|
|
|
|
systems = lib.mkOption { type = types.functionTo types.bool; };
|
|
|
|
};});
|
|
|
|
readOnly = true;
|
|
|
|
internal = true;
|
|
|
|
default =
|
|
|
|
lib.optionalAttrs
|
2024-09-01 03:29:32 +02:00
|
|
|
config.auto.packages.enable
|
|
|
|
(createPackages config.auto.packages.dir);
|
2024-07-29 00:35:14 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
default = {};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
perSystem = { lib, pkgs, system, ... }: let
|
|
|
|
packages =
|
|
|
|
lib.pipe
|
2024-09-01 03:29:32 +02:00
|
|
|
config.auto.packages.result
|
2024-07-29 00:35:14 +02:00
|
|
|
[
|
|
|
|
(lib.filterAttrs
|
|
|
|
(name: { package, systems }:
|
|
|
|
pkgs.callPackage systems {
|
|
|
|
inherit (pkgs) lib hostPlatform targetPlatform;
|
|
|
|
}))
|
2024-08-04 02:12:58 +02:00
|
|
|
(lib.mapAttrs
|
|
|
|
(name: { package, systems }:
|
|
|
|
let
|
|
|
|
# TODO: put in `autoThings` `handle`?
|
|
|
|
isDream2Nix = lib.pipe package
|
|
|
|
[
|
|
|
|
builtins.functionArgs
|
|
|
|
builtins.attrNames
|
|
|
|
(builtins.elem "dream2nix")
|
|
|
|
];
|
|
|
|
in
|
|
|
|
if isDream2Nix
|
|
|
|
then inputs.dream2nix.lib.evalModules {
|
|
|
|
packageSets.nixpkgs = pkgs;
|
|
|
|
modules = [
|
|
|
|
package
|
|
|
|
{
|
|
|
|
paths.projectRoot = "${self.outPath}";
|
|
|
|
paths.projectRootFile = "flake.nix";
|
|
|
|
paths.package = "${self.outPath}";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
specialArgs = {
|
|
|
|
# NOTE: for overlayed `maintainers`
|
|
|
|
inherit (pkgs) lib;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else pkgs.callPackage package { }))
|
2024-07-29 00:35:14 +02:00
|
|
|
];
|
|
|
|
in {
|
|
|
|
inherit packages;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|