mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-19 20:41:54 +03:00
Merge pull request #304 from nix-community/feat/modules-builders
feat: use modules for builders
This commit is contained in:
commit
12ae9b891b
11
examples/_d2n-extended-new-subsystem/builders.nix
Normal file
11
examples/_d2n-extended-new-subsystem/builders.nix
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
builders.dummy = {...}: {
|
||||||
|
name = "dummy";
|
||||||
|
subsystem = "hello";
|
||||||
|
type = "pure";
|
||||||
|
build = {hello, ...}: {...}: {
|
||||||
|
packages.${hello.pname}.${hello.version} =
|
||||||
|
hello;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
@ -11,12 +11,5 @@
|
|||||||
})
|
})
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
builders.dummy = {...}: {
|
|
||||||
type = "pure";
|
|
||||||
build = {hello, ...}: {...}: {
|
|
||||||
packages.${hello.pname}.${hello.version} =
|
|
||||||
hello;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
config.extra = ./extra.nix;
|
config.extra = ./extra.nix;
|
||||||
config.modules = [
|
config.modules = [
|
||||||
./translators.nix
|
./translators.nix
|
||||||
|
./builders.nix
|
||||||
];
|
];
|
||||||
source = ./.;
|
source = ./.;
|
||||||
settings = [
|
settings = [
|
||||||
|
@ -23,10 +23,18 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
'')
|
'')
|
||||||
|
(builtins.toFile "brp-new.nix" ''
|
||||||
|
{
|
||||||
|
builders.brp-new = {
|
||||||
|
imports = ["${inp.dream2nix}/src/subsystems/rust/builders/build-rust-package"];
|
||||||
|
name = "brp-new";
|
||||||
|
subsystem = "rust";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
'')
|
||||||
];
|
];
|
||||||
config.extra = {
|
config.extra = {
|
||||||
subsystems.rust = {
|
subsystems.rust = {
|
||||||
builders.brp-new = "${inp.dream2nix}/src/subsystems/rust/builders/build-rust-package";
|
|
||||||
discoverers.default = "${inp.dream2nix}/src/subsystems/rust/discoverers/default";
|
discoverers.default = "${inp.dream2nix}/src/subsystems/rust/discoverers/default";
|
||||||
};
|
};
|
||||||
fetchers.crates-io = "${inp.dream2nix}/src/fetchers/crates-io";
|
fetchers.crates-io = "${inp.dream2nix}/src/fetchers/crates-io";
|
||||||
|
@ -242,9 +242,9 @@ in let
|
|||||||
findBuilder = dreamLock: let
|
findBuilder = dreamLock: let
|
||||||
subsystem = dreamLock._generic.subsystem;
|
subsystem = dreamLock._generic.subsystem;
|
||||||
in
|
in
|
||||||
if ! subsystems."${subsystem}" ? builders
|
if ! framework.buildersBySubsystem ? ${subsystem}
|
||||||
then throw "Could not find any builder for subsystem '${subsystem}'"
|
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
|
# detect if granular or combined fetching must be used
|
||||||
findFetcher = dreamLock:
|
findFetcher = dreamLock:
|
||||||
@ -394,7 +394,7 @@ in let
|
|||||||
if builder == null
|
if builder == null
|
||||||
then findBuilder dreamLock
|
then findBuilder dreamLock
|
||||||
else if l.isString builder
|
else if l.isString builder
|
||||||
then subsystems.${dreamLock._generic.subsystem}.builders.${builder}
|
then framework.buildersBySubsystem.${dreamLock._generic.subsystem}.${builder}
|
||||||
else builder;
|
else builder;
|
||||||
|
|
||||||
fetcher' =
|
fetcher' =
|
||||||
|
5
src/modules/builders/builder/default.nix
Normal file
5
src/modules/builders/builder/default.nix
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
imports = [
|
||||||
|
./interface.nix
|
||||||
|
];
|
||||||
|
}
|
33
src/modules/builders/builder/interface.nix
Normal file
33
src/modules/builders/builder/interface.nix
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
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.functionTo (t.functionTo t.attrs);
|
||||||
|
default = _: _: {};
|
||||||
|
};
|
||||||
|
type = lib.mkOption {
|
||||||
|
type = t.enum [
|
||||||
|
"pure"
|
||||||
|
"ifd"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
6
src/modules/builders/default.nix
Normal file
6
src/modules/builders/default.nix
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
imports = [
|
||||||
|
./implementation.nix
|
||||||
|
./interface.nix
|
||||||
|
];
|
||||||
|
}
|
40
src/modules/builders/implementation.nix
Normal file
40
src/modules/builders/implementation.nix
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
{
|
||||||
|
config,
|
||||||
|
callPackageDream,
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
defaults = {
|
||||||
|
rust = "build-rust-package";
|
||||||
|
nodejs = "granular-nodejs";
|
||||||
|
python = "simple-python";
|
||||||
|
php = "granular-php";
|
||||||
|
haskell = "simple-haskell";
|
||||||
|
debian = "simple-debian";
|
||||||
|
};
|
||||||
|
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 =
|
||||||
|
lib.mapAttrs
|
||||||
|
(
|
||||||
|
subsystem: builders:
|
||||||
|
builders
|
||||||
|
// lib.optionalAttrs (lib.hasAttr subsystem defaults) {
|
||||||
|
default = builders.${defaults.${subsystem}};
|
||||||
|
}
|
||||||
|
)
|
||||||
|
(funcs.structureBySubsystem config.builderInstances);
|
||||||
|
};
|
||||||
|
}
|
25
src/modules/builders/interface.nix
Normal file
25
src/modules/builders/interface.nix
Normal 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);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
@ -44,7 +44,21 @@ modules:
|
|||||||
(name: description:
|
(name: description:
|
||||||
(import description.path {inherit dlib lib;})
|
(import description.path {inherit dlib lib;})
|
||||||
// {inherit (description) name subsystem;})
|
// {inherit (description) name subsystem;})
|
||||||
(lib.listToAttrs collectedModules);
|
(
|
||||||
|
lib.foldl'
|
||||||
|
(
|
||||||
|
all: el:
|
||||||
|
if lib.hasAttr el.name all
|
||||||
|
then
|
||||||
|
throw ''
|
||||||
|
module named ${el.name} in subsystem ${el.value.subsystem} conflicts
|
||||||
|
with a module with the same name from subsystem ${all.${el.name}.subsystem}
|
||||||
|
''
|
||||||
|
else all // {${el.name} = el.value;}
|
||||||
|
)
|
||||||
|
{}
|
||||||
|
collectedModules
|
||||||
|
);
|
||||||
|
|
||||||
instantiate = importedModules: loader:
|
instantiate = importedModules: loader:
|
||||||
lib.mapAttrs
|
lib.mapAttrs
|
||||||
|
@ -9,6 +9,7 @@ in {
|
|||||||
./functions.subsystem-loading
|
./functions.subsystem-loading
|
||||||
./functions.translators
|
./functions.translators
|
||||||
./translators
|
./translators
|
||||||
|
./builders
|
||||||
];
|
];
|
||||||
options = {
|
options = {
|
||||||
lib = lib.mkOption {
|
lib = lib.mkOption {
|
||||||
|
Loading…
Reference in New Issue
Block a user