feat: use modules for builders

This commit is contained in:
Yusuf Bera Ertan 2022-09-25 20:51:24 +03:00
parent b54f6403f4
commit f348abd9e5
No known key found for this signature in database
GPG Key ID: 1D8F8FAF2294D6EA
7 changed files with 99 additions and 3 deletions

View File

@ -242,9 +242,9 @@ in let
findBuilder = dreamLock: let
subsystem = dreamLock._generic.subsystem;
in
if ! subsystems."${subsystem}" ? builders
if ! framework.buildersBySubsystem.${subsystem} ? default
then throw "Could not find any builder for subsystem '${subsystem}'"
else subsystems."${subsystem}".builders.default;
else framework.buildersBySubsystem.${subsystem}.default;
# detect if granular or combined fetching must be used
findFetcher = dreamLock:
@ -394,7 +394,7 @@ in let
if builder == null
then findBuilder dreamLock
else if l.isString builder
then subsystems.${dreamLock._generic.subsystem}.builders.${builder}
then framework.buildersBySubsystem.${dreamLock._generic.subsystem}.${builder}
else builder;
fetcher' =

View File

@ -0,0 +1,5 @@
{
imports = [
./interface.nix
];
}

View File

@ -0,0 +1,37 @@
{
config,
lib,
...
}: let
t = lib.types;
in {
options = {
disabled = lib.mkOption {
type = t.bool;
default = false;
description = "Whether to disable the builder, if disabled it can't be used.";
};
name = lib.mkOption {
type = t.str;
description = "Name of the builder.";
};
subsystem = lib.mkOption {
type = t.str;
description = "Subsystem of the builder.";
};
build = lib.mkOption {
type = t.function (t.functionTo t.attrs);
default = _: _: {};
};
type = lib.mkOption {
type = t.enum [
"pure"
"ifd"
];
};
version = lib.mkOption {
type = t.int;
default = 2;
};
};
}

View File

@ -0,0 +1,6 @@
{
imports = [
./implementation.nix
./interface.nix
];
}

View File

@ -0,0 +1,22 @@
{
config,
callPackageDream,
...
}: let
loader = b: b // {build = callPackageDream b.build;};
funcs = config.functions.subsystem-loading;
collectedModules = funcs.collect "builders";
in {
config = {
# The user can add more translators by extending this attribute
builders = funcs.import_ collectedModules;
/*
translators wrapped with extra logic to add extra attributes,
like .translateBin for pure translators
*/
builderInstances = funcs.instantiate config.builders loader;
buildersBySubsystem = funcs.structureBySubsystem config.builderInstances;
};
}

View File

@ -0,0 +1,25 @@
{
lib,
specialArgs,
...
}: let
t = lib.types;
in {
options = {
builders = lib.mkOption {
type = t.attrsOf (t.submoduleWith {
modules = [./builder/default.nix];
inherit specialArgs;
});
description = ''
builder module definitions
'';
};
builderInstances = lib.mkOption {
type = t.attrsOf t.anything;
};
buildersBySubsystem = lib.mkOption {
type = t.attrsOf (t.attrsOf t.anything);
};
};
}

View File

@ -9,6 +9,7 @@ in {
./functions.subsystem-loading
./functions.translators
./translators
./builders
];
options = {
lib = lib.mkOption {