add translator nixos modules

This commit is contained in:
DavHau 2022-08-05 15:06:49 +02:00
parent de7da02336
commit c6b0582a9e
3 changed files with 136 additions and 0 deletions

View 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
View 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;
};
}

View 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;
};
}