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-01 19:54:06 +03:00
|
|
|
packageCategories = 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 {
|
|
|
|
dream2nix = self;
|
|
|
|
nixpkgs = inputs.nixpkgs;
|
|
|
|
self = self';
|
|
|
|
};
|
|
|
|
in
|
|
|
|
self';
|
|
|
|
|
2023-11-01 19:54:06 +03:00
|
|
|
# importFlakeSmall = flakeFile: let
|
|
|
|
# self' = (import flakeFile).outputs {
|
|
|
|
# dream2nix = dream2nixFlake;
|
|
|
|
# nixpkgs = inputs.nixpkgs;
|
|
|
|
# self = self';
|
|
|
|
# };
|
|
|
|
# in
|
|
|
|
# self';
|
2023-10-01 02:47:33 +03:00
|
|
|
|
2023-11-01 19:54:06 +03:00
|
|
|
# dream2nixFlake = import (../../.) {};
|
2023-10-01 02:47:33 +03:00
|
|
|
|
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: {
|
|
|
|
name = "example-package-${name}";
|
|
|
|
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-01 19:54:06 +03:00
|
|
|
repo.path = ../../examples/repo;
|
2023-09-06 01:11:28 +03:00
|
|
|
repo-flake.description = "Dream2nix repo with flakes";
|
2023-11-01 19:54:06 +03:00
|
|
|
repo-flake.path = ../../examples/repo-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 =
|
2023-09-20 23:03:03 +03:00
|
|
|
lib.optionalAttrs
|
|
|
|
(system == "x86_64-linux")
|
|
|
|
(
|
2023-10-31 14:26:26 +03:00
|
|
|
(lib.mapAttrs (_: flakeFile: getPackage flakeFile) allExamples)
|
2023-09-20 23:03:03 +03:00
|
|
|
// {
|
2023-11-01 19:54:06 +03:00
|
|
|
example-repo = let
|
|
|
|
imported =
|
|
|
|
(import (../../examples/repo) {
|
|
|
|
dream2nixSource = ../..;
|
|
|
|
inherit pkgs;
|
|
|
|
})
|
|
|
|
.hello;
|
|
|
|
in
|
|
|
|
imported;
|
2023-09-20 23:03:03 +03:00
|
|
|
example-repo-flake =
|
2023-11-01 19:54:06 +03:00
|
|
|
(importFlake (../../examples/repo-flake/flake.nix)).packages.${system}.hello;
|
|
|
|
# example-repo-flake-pdm =
|
|
|
|
# (importFlakeSmall (../../examples/repo-flake-pdm/flake.nix)).packages.${system}.my-project;
|
2023-09-20 23:03:03 +03:00
|
|
|
}
|
|
|
|
);
|
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
|
|
|
}
|