fix: add wrapPureTranslator to functions.translators

This commit is contained in:
Yusuf Bera Ertan 2022-10-06 21:26:15 +03:00
parent df731a0722
commit 08ae837a1a
No known key found for this signature in database
GPG Key ID: 1D8F8FAF2294D6EA
5 changed files with 86 additions and 13 deletions

View File

@ -51,7 +51,17 @@ in let
};
framework = import ./modules/framework.nix {
inherit apps lib dlib pkgs utils externals externalSources;
inherit
apps
lib
dlib
pkgs
utils
externals
externalSources
dream2nixWithExternals
;
dream2nixConfigFile = configFile;
dream2nixConfig = config;
};

View File

@ -92,10 +92,12 @@
framework = import ./modules/framework.nix {
inherit lib dlib externalSources;
dream2nixConfig = config;
dream2nixConfigFile = l.toFile "dream2nix-config.json" (l.toJSON config);
apps = throw "apps is not available before nixpkgs is imported";
pkgs = throw "pkgs is not available before nixpkgs is imported";
utils = throw "utils is not available before nixpkgs is imported";
externals = throw "externals is not available before nixpkgs is imported";
dream2nixWithExternals = throw "not available before nixpkgs is imported";
};
initD2N = initDream2nix config;

View File

@ -1,12 +1,7 @@
{
dream2nixConfig,
pkgs,
dlib,
externals,
externalSources,
lib,
utils,
apps,
dream2nixConfig,
...
} @ args: let
topLevel = import ./top-level.nix args;
evaledModules = lib.evalModules {

View File

@ -11,10 +11,67 @@
else def.default or null
)
extraArgsDef;
# adds a translateBin to a pure translator
wrapPureTranslator = {
subsystem,
name,
}: let
inherit
(config)
utils
pkgs
dream2nixWithExternals
configFile
;
bin =
utils.writePureShellScript
(with pkgs; [
coreutils
jq
nix
python3
])
''
jsonInputFile=$(realpath $1)
outputFile=$(realpath -m $(jq '.outputFile' -c -r $jsonInputFile))
pushd $TMPDIR
nix eval \
--option experimental-features "nix-command flakes"\
--show-trace --impure --raw --expr "
let
dream2nix = import ${dream2nixWithExternals} {
config = ${configFile};
};
translatorArgs =
(builtins.fromJSON
(builtins.unsafeDiscardStringContext (builtins.readFile '''$1''')));
dreamLock' =
dream2nix.framework.translatorsBySubsystem.${subsystem}.${name}.translate
translatorArgs;
# simpleTranslate2 puts dream-lock in result
dreamLock = dreamLock'.result or dreamLock';
in
dream2nix.utils.dreamLock.toJSON
# don't use nix to detect cycles, this will be more efficient in python
(dreamLock // {
_generic = builtins.removeAttrs dreamLock._generic [ \"cyclicDependencies\" ];
})
" | python3 ${../apps/cli/format-dream-lock.py} > out
tmpOut=$(realpath out)
popd
mkdir -p $(dirname $outputFile)
cp $tmpOut $outputFile
'';
in
bin.overrideAttrs (old: {
name = "translator-${subsystem}-pure-${name}";
});
in {
functions.translators = {
inherit
makeTranslatorDefaultArgs
wrapPureTranslator
;
};
}

View File

@ -7,7 +7,9 @@
pkgs,
utils,
dream2nixConfig,
}: let
dream2nixConfigFile,
dream2nixWithExternals,
} @ args: let
t = lib.types;
in {
imports = [
@ -47,9 +49,16 @@ in {
dream2nixConfig = lib.mkOption {
type = t.raw;
};
dream2nixWithExternals = lib.mkOption {
type = t.path;
};
dream2nixConfigFile = lib.mkOption {
type = t.path;
};
};
config = {
inherit apps dlib externals externalSources pkgs utils dream2nixConfig;
lib = lib // builtins;
};
config =
args
// {
lib = args.lib // builtins;
};
}