From 4b33d2f6554dca4c8bea7ca4329588e7dc84026a Mon Sep 17 00:00:00 2001 From: DavHau Date: Fri, 12 Aug 2022 20:30:45 +0200 Subject: [PATCH] feat: modules: refactor to flat structure --- src/lib/translators.nix | 11 ---------- .../default.nix | 0 .../implementation.nix | 2 +- .../interface.nix | 0 src/modules/functions.translators/default.nix | 6 ++++++ .../functions.translators/implementation.nix | 20 +++++++++++++++++++ .../functions.translators/interface.nix | 8 ++++++++ src/modules/functions/default.nix | 5 ----- src/modules/top-level.nix | 3 ++- src/modules/translators/interface.nix | 2 +- src/subsystems/translators.nix | 2 +- src/utils/default.nix | 3 ++- 12 files changed, 41 insertions(+), 21 deletions(-) rename src/modules/{functions/subsystem-loading => functions.subsystem-loading}/default.nix (100%) rename src/modules/{functions/subsystem-loading => functions.subsystem-loading}/implementation.nix (97%) rename src/modules/{functions/subsystem-loading => functions.subsystem-loading}/interface.nix (100%) create mode 100644 src/modules/functions.translators/default.nix create mode 100644 src/modules/functions.translators/implementation.nix create mode 100644 src/modules/functions.translators/interface.nix delete mode 100644 src/modules/functions/default.nix diff --git a/src/lib/translators.nix b/src/lib/translators.nix index 9e32094e..40ffbdea 100644 --- a/src/lib/translators.nix +++ b/src/lib/translators.nix @@ -24,15 +24,4 @@ in { inherit translators mapTranslators; callTranslator = modules.callModule; - - # pupulates a translators special args with defaults - getextraArgsDefaults = extraArgsDef: - l.mapAttrs - ( - name: def: - if def.type == "flag" - then false - else def.default or null - ) - extraArgsDef; } diff --git a/src/modules/functions/subsystem-loading/default.nix b/src/modules/functions.subsystem-loading/default.nix similarity index 100% rename from src/modules/functions/subsystem-loading/default.nix rename to src/modules/functions.subsystem-loading/default.nix diff --git a/src/modules/functions/subsystem-loading/implementation.nix b/src/modules/functions.subsystem-loading/implementation.nix similarity index 97% rename from src/modules/functions/subsystem-loading/implementation.nix rename to src/modules/functions.subsystem-loading/implementation.nix index 34b018fd..a4534bbd 100644 --- a/src/modules/functions/subsystem-loading/implementation.nix +++ b/src/modules/functions.subsystem-loading/implementation.nix @@ -14,7 +14,7 @@ modules: }: let lib = config.lib; t = lib.types; - subsystemsDir = lib.toString ../../../subsystems; + subsystemsDir = lib.toString ../../subsystems; subsystems = dlib.dirNames subsystemsDir; /* diff --git a/src/modules/functions/subsystem-loading/interface.nix b/src/modules/functions.subsystem-loading/interface.nix similarity index 100% rename from src/modules/functions/subsystem-loading/interface.nix rename to src/modules/functions.subsystem-loading/interface.nix diff --git a/src/modules/functions.translators/default.nix b/src/modules/functions.translators/default.nix new file mode 100644 index 00000000..e0a7730f --- /dev/null +++ b/src/modules/functions.translators/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./implementation.nix + ./interface.nix + ]; +} diff --git a/src/modules/functions.translators/implementation.nix b/src/modules/functions.translators/implementation.nix new file mode 100644 index 00000000..466cddf6 --- /dev/null +++ b/src/modules/functions.translators/implementation.nix @@ -0,0 +1,20 @@ +{config, ...}: let + lib = config.lib; + + # pupulates a translators special args with defaults + makeTranslatorDefaultArgs = extraArgsDef: + lib.mapAttrs + ( + name: def: + if def.type == "flag" + then false + else def.default or null + ) + extraArgsDef; +in { + functions.translators = { + inherit + makeTranslatorDefaultArgs + ; + }; +} diff --git a/src/modules/functions.translators/interface.nix b/src/modules/functions.translators/interface.nix new file mode 100644 index 00000000..fabee307 --- /dev/null +++ b/src/modules/functions.translators/interface.nix @@ -0,0 +1,8 @@ +{config, ...}: let + lib = config.lib; + t = lib.types; +in { + options.functions.translators = { + makeTranslatorDefaultArgs = lib.mkOption {type = t.functionTo t.anything;}; + }; +} diff --git a/src/modules/functions/default.nix b/src/modules/functions/default.nix deleted file mode 100644 index f3d9fe9e..00000000 --- a/src/modules/functions/default.nix +++ /dev/null @@ -1,5 +0,0 @@ -{ - imports = [ - ./subsystem-loading - ]; -} diff --git a/src/modules/top-level.nix b/src/modules/top-level.nix index 6cbc324c..eae9abdd 100644 --- a/src/modules/top-level.nix +++ b/src/modules/top-level.nix @@ -6,7 +6,8 @@ t = lib.types; in { imports = [ - ./functions + ./functions.subsystem-loading + ./functions.translators ./translators ]; options = { diff --git a/src/modules/translators/interface.nix b/src/modules/translators/interface.nix index 1ab3fce7..726b721a 100644 --- a/src/modules/translators/interface.nix +++ b/src/modules/translators/interface.nix @@ -12,7 +12,7 @@ in { Translator module definitions ''; }; - translators = lib.mkOption { + translatorInstances = lib.mkOption { type = t.attrsOf t.anything; }; translatorsBySubsystem = lib.mkOption { diff --git a/src/subsystems/translators.nix b/src/subsystems/translators.nix index e3841354..df37e737 100644 --- a/src/subsystems/translators.nix +++ b/src/subsystems/translators.nix @@ -86,7 +86,7 @@ args: translateOriginal ( - (dlib.translators.getextraArgsDefaults + (framework.functions.translators.makeTranslatorDefaultArgs (translatorModule.extraArgs or {})) // args // (args.project.subsystemInfo or {}) diff --git a/src/utils/default.nix b/src/utils/default.nix index ac000a64..c88099d7 100644 --- a/src/utils/default.nix +++ b/src/utils/default.nix @@ -22,6 +22,7 @@ subsystems, config, configFile, + framework, ... }: let b = builtins; @@ -197,7 +198,7 @@ in project = l.removeAttrs args.project ["dreamLock"]; outputFile = project.dreamLockPath; } - // (dlib.translators.getextraArgsDefaults translator.extraArgs or {}) + // (framework.functions.translators.makeTranslatorDefaultArgs translator.extraArgs or {}) // args.project.subsystemInfo or {} )); script =