mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-11-24 09:32:34 +03:00
fix: add wrapPureTranslator to functions.translators
This commit is contained in:
parent
df731a0722
commit
08ae837a1a
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
|
@ -1,12 +1,7 @@
|
||||
{
|
||||
dream2nixConfig,
|
||||
pkgs,
|
||||
dlib,
|
||||
externals,
|
||||
externalSources,
|
||||
lib,
|
||||
utils,
|
||||
apps,
|
||||
dream2nixConfig,
|
||||
...
|
||||
} @ args: let
|
||||
topLevel = import ./top-level.nix args;
|
||||
evaledModules = lib.evalModules {
|
||||
|
@ -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
|
||||
;
|
||||
};
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user