2023-03-13 07:20:09 +03:00
|
|
|
# evaluate packages from `/**/modules/drvs` and export them via `flake.packages`
|
2023-03-12 18:27:22 +03:00
|
|
|
{
|
|
|
|
self,
|
|
|
|
inputs,
|
2023-09-06 01:11:28 +03:00
|
|
|
lib,
|
2023-03-12 18:27:22 +03:00
|
|
|
...
|
2023-09-06 01:11:28 +03:00
|
|
|
}: let
|
|
|
|
inherit
|
|
|
|
(lib)
|
|
|
|
flip
|
|
|
|
foldl
|
|
|
|
mapAttrs'
|
|
|
|
mapAttrsToList
|
|
|
|
;
|
|
|
|
inherit
|
|
|
|
(builtins)
|
|
|
|
mapAttrs
|
|
|
|
readDir
|
|
|
|
;
|
|
|
|
|
2023-11-05 06:22:03 +03:00
|
|
|
dream2nixFlake = import ../../. {};
|
|
|
|
|
2024-01-02 12:19:58 +03:00
|
|
|
packageCategories =
|
|
|
|
lib.filterAttrs
|
|
|
|
(name: type: type == "directory")
|
|
|
|
(readDir ../../examples/packages);
|
2023-09-06 01:11:28 +03:00
|
|
|
|
|
|
|
readExamples = dirName: let
|
2023-11-01 19:54:06 +03:00
|
|
|
examplesPath = ../../examples/packages + "/${dirName}";
|
2023-09-06 01:11:28 +03:00
|
|
|
examples = readDir examplesPath;
|
|
|
|
in
|
|
|
|
flip mapAttrs examples
|
|
|
|
(name: _: {
|
2023-10-31 14:26:26 +03:00
|
|
|
dir = examplesPath + "/${name}";
|
|
|
|
flake = examplesPath + "/${name}/flake.nix";
|
2023-09-06 01:11:28 +03:00
|
|
|
});
|
|
|
|
|
2023-09-20 22:48:16 +03:00
|
|
|
importFlake = flakeFile: let
|
|
|
|
self' = (import flakeFile).outputs {
|
2023-11-05 06:22:03 +03:00
|
|
|
dream2nix = dream2nixFlake;
|
2023-09-20 22:48:16 +03:00
|
|
|
nixpkgs = inputs.nixpkgs;
|
|
|
|
self = self';
|
|
|
|
};
|
|
|
|
in
|
|
|
|
self';
|
|
|
|
|
2023-09-06 01:11:28 +03:00
|
|
|
# Type: [ {${name} = {module, packagePath} ]
|
2023-10-31 14:26:26 +03:00
|
|
|
allExamplesList = mapAttrsToList (dirName: _: readExamples dirName) packageCategories;
|
2023-09-06 01:11:28 +03:00
|
|
|
|
2023-10-31 14:26:26 +03:00
|
|
|
exampleFlakes = foldl (a: b: a // b) {} allExamplesList;
|
2023-09-06 01:11:28 +03:00
|
|
|
|
|
|
|
# create a template for each example package
|
2023-10-31 14:26:26 +03:00
|
|
|
packageTempaltes = flip mapAttrs exampleFlakes (name: def: {
|
2023-09-06 01:11:28 +03:00
|
|
|
description = "Example package ${name}";
|
2023-10-31 14:26:26 +03:00
|
|
|
path = def.dir;
|
|
|
|
});
|
|
|
|
|
|
|
|
allExamples = flip mapAttrs' exampleFlakes (name: example: {
|
2024-03-07 17:16:44 +03:00
|
|
|
name = "example-${name}";
|
2023-10-31 14:26:26 +03:00
|
|
|
value = example.flake;
|
2023-09-06 01:11:28 +03:00
|
|
|
});
|
|
|
|
in {
|
|
|
|
flake.templates =
|
|
|
|
packageTempaltes
|
|
|
|
// {
|
|
|
|
# add repo templates
|
|
|
|
repo.description = "Dream2nix repo without flakes";
|
2023-11-07 15:07:00 +03:00
|
|
|
repo.path = ../../examples/repo-with-packages;
|
2023-09-06 01:11:28 +03:00
|
|
|
repo-flake.description = "Dream2nix repo with flakes";
|
2023-11-07 15:07:00 +03:00
|
|
|
repo-flake.path = ../../examples/repo-with-packages-flake;
|
2023-09-06 01:11:28 +03:00
|
|
|
};
|
|
|
|
|
2023-04-18 14:41:43 +03:00
|
|
|
perSystem = {
|
|
|
|
system,
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
...
|
2023-07-03 12:28:05 +03:00
|
|
|
}: let
|
2023-07-29 10:45:31 +03:00
|
|
|
# evaluates the package behind a given module
|
2023-10-31 14:26:26 +03:00
|
|
|
getPackage = flakeFile: let
|
|
|
|
flake = importFlake flakeFile;
|
2023-07-03 12:28:05 +03:00
|
|
|
in
|
2023-10-31 14:26:26 +03:00
|
|
|
flake.packages.${system}.default;
|
2023-10-17 21:03:21 +03:00
|
|
|
|
2023-07-29 16:08:40 +03:00
|
|
|
# map all modules in /examples to a package output in the flake.
|
2023-07-29 12:58:20 +03:00
|
|
|
checks =
|
2024-07-13 17:38:46 +03:00
|
|
|
lib.optionalAttrs
|
|
|
|
(system == "x86_64-linux" || system == "aarch64-darwin")
|
|
|
|
(
|
|
|
|
(lib.mapAttrs (_: flakeFile: getPackage flakeFile) allExamples)
|
|
|
|
// {
|
|
|
|
repo-with-packages = let
|
|
|
|
imported =
|
|
|
|
(import ../../examples/repo-with-packages {
|
|
|
|
dream2nixSource = ../..;
|
|
|
|
inherit pkgs;
|
|
|
|
})
|
|
|
|
.hello;
|
|
|
|
in
|
|
|
|
imported;
|
|
|
|
repo-with-packages-flake =
|
|
|
|
(importFlake ../../examples/repo-with-packages-flake/flake.nix).packages.${system}.hello;
|
|
|
|
}
|
|
|
|
);
|
2023-10-17 21:03:21 +03:00
|
|
|
|
|
|
|
# work around a bug in nix-fast-build / nix-eval jobs
|
|
|
|
# TODO: remove this
|
|
|
|
checksWithSystem = lib.mapAttrs (_: drv: drv // {inherit system;}) checks;
|
|
|
|
in {
|
|
|
|
checks = checksWithSystem;
|
2023-07-03 12:28:05 +03:00
|
|
|
};
|
2023-02-11 16:38:53 +03:00
|
|
|
}
|