mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-12 14:14:36 +03:00
add translator nixos modules
This commit is contained in:
parent
de7da02336
commit
c6b0582a9e
61
src/modules/interfaces/translator.nix
Normal file
61
src/modules/interfaces/translator.nix
Normal file
@ -0,0 +1,61 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
t = lib.types;
|
||||
in {
|
||||
options = {
|
||||
disabled = lib.mkOption {
|
||||
type = t.bool;
|
||||
default = false;
|
||||
};
|
||||
version = lib.mkOption {
|
||||
type = t.int;
|
||||
default = 2;
|
||||
};
|
||||
discoverProject = lib.mkOption {
|
||||
type = t.nullOr (t.functionTo (t.anything));
|
||||
default = null;
|
||||
};
|
||||
generateUnitTestsForProjects = lib.mkOption {
|
||||
type = t.listOf t.anything;
|
||||
default = [];
|
||||
};
|
||||
type = lib.mkOption {
|
||||
type = t.enum [
|
||||
"ifd"
|
||||
"impure"
|
||||
"pure"
|
||||
];
|
||||
};
|
||||
translate = lib.mkOption {
|
||||
type = t.nullOr (t.functionTo (t.functionTo (t.attrs)));
|
||||
default = null;
|
||||
};
|
||||
translateBin = lib.mkOption {
|
||||
type = t.nullOr (t.functionTo t.package);
|
||||
default = null;
|
||||
};
|
||||
extraArgs = lib.mkOption {
|
||||
type = t.attrsOf (t.submodule {
|
||||
options = {
|
||||
description = lib.mkOption {
|
||||
type = t.str;
|
||||
};
|
||||
default = lib.mkOption {
|
||||
type = t.nullOr t.anything;
|
||||
default = null;
|
||||
};
|
||||
examples = lib.mkOption {
|
||||
type = t.listOf t.str;
|
||||
default = [];
|
||||
};
|
||||
type = lib.mkOption {
|
||||
type = t.enum ["argument" "flag"];
|
||||
};
|
||||
};
|
||||
});
|
||||
};
|
||||
};
|
||||
}
|
28
src/modules/top-level.nix
Normal file
28
src/modules/top-level.nix
Normal file
@ -0,0 +1,28 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
t = lib.types;
|
||||
in {
|
||||
imports = [
|
||||
./translators.nix
|
||||
];
|
||||
options = {
|
||||
lib = lib.mkOption {
|
||||
type = t.anything;
|
||||
};
|
||||
translatorModules = lib.mkOption {
|
||||
type = t.attrsOf (t.submodule ./interfaces/translator.nix);
|
||||
description = ''
|
||||
Translator module definitions
|
||||
'';
|
||||
};
|
||||
translators = lib.mkOption {
|
||||
type = t.anything;
|
||||
};
|
||||
};
|
||||
config = {
|
||||
lib = lib // builtins;
|
||||
};
|
||||
}
|
47
src/modules/translators.nix
Normal file
47
src/modules/translators.nix
Normal file
@ -0,0 +1,47 @@
|
||||
{
|
||||
config,
|
||||
dlib,
|
||||
callPackageDream,
|
||||
...
|
||||
}: let
|
||||
lib = config.lib;
|
||||
t = lib.types;
|
||||
subsystemsDir = lib.toString ../subsystems;
|
||||
subsystems = dlib.dirNames subsystemsDir;
|
||||
|
||||
translatorModulesCollected =
|
||||
lib.concatMap
|
||||
(subsystem: let
|
||||
translatorsDir = "${subsystemsDir}/${subsystem}/translators";
|
||||
exists = lib.pathExists translatorsDir;
|
||||
translatorNames = dlib.dirNames translatorsDir;
|
||||
in
|
||||
if ! exists
|
||||
then []
|
||||
else
|
||||
lib.map
|
||||
(translatorName:
|
||||
lib.nameValuePair
|
||||
translatorName
|
||||
(subsystemsDir + "/${subsystem}/translators/${translatorName}"))
|
||||
translatorNames)
|
||||
subsystems;
|
||||
|
||||
# wrapa a translator
|
||||
# add impure translation script to pure translators
|
||||
# add default args to translator
|
||||
makeTranslator =
|
||||
(callPackageDream ../subsystems/translators.nix {}).makeTranslator;
|
||||
in {
|
||||
config = {
|
||||
translatorModules =
|
||||
lib.mapAttrs
|
||||
(translatorName: path: import path {inherit dlib lib;})
|
||||
(lib.listToAttrs translatorModulesCollected);
|
||||
|
||||
translators =
|
||||
lib.mapAttrs
|
||||
(translatorName: translatorRaw: makeTranslator translatorRaw)
|
||||
config.translatorModules;
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user