WIP translators: init gradle2nix

This commit is contained in:
Ilan Joselevich 2022-04-28 22:16:43 +03:00
parent 8df4f0beee
commit 30a0ace955
3 changed files with 100 additions and 0 deletions

View File

@ -84,6 +84,22 @@
"type": "github"
}
},
"gradle2nix": {
"flake": false,
"locked": {
"lastModified": 1651167340,
"narHash": "sha256-U+YBGk/c2jjp6uExGiyrO8+vGpLqeRu6BlhvNDzbfJo=",
"owner": "kranzes",
"repo": "gradle2nix",
"rev": "5acbd615af9f26bbf11e5dd2b620c4d3cf06e01a",
"type": "github"
},
"original": {
"owner": "kranzes",
"repo": "gradle2nix",
"type": "github"
}
},
"mach-nix": {
"flake": false,
"locked": {
@ -176,6 +192,7 @@
"crane": "crane",
"flake-utils-pre-commit": "flake-utils-pre-commit",
"gomod2nix": "gomod2nix",
"gradle2nix": "gradle2nix",
"mach-nix": "mach-nix",
"nixpkgs": "nixpkgs",
"node2nix": "node2nix",

View File

@ -44,6 +44,12 @@
url = "github:ipetkov/crane";
flake = false;
};
# required for builder/translator java/gradle2nix
gradle2nix = {
url = "github:kranzes/gradle2nix";
flake = false;
};
};
outputs = {

View File

@ -0,0 +1,77 @@
{
dlib,
lib,
}: {
# A derivation which outputs a single executable at `$out`.
# The executable will be called by dream2nix for translation
# The input format is specified in /specifications/translator-call-example.json.
# The first arg `$1` will be a json file containing the input parameters
# like defined in /src/specifications/translator-call-example.json and the
# additional arguments required according to extraArgs
#
# The program is expected to create a file at the location specified
# by the input parameter `outFile`.
# The output file must contain the dream lock data encoded as json.
# See /src/specifications/dream-lock-example.json
translateBin = {
# dream2nix utils
utils,
# nixpkgs dependenies
bash,
jq,
writeScriptBin,
callPackage,
...
}:
utils.writePureShellScript
[
bash
coreutils
jq
(callPackage externalSources.gradle2nix {})
]
''
# accroding to the spec, the translator reads the input from a json file
jsonInput=$1
# read the json input
outputFile=$(${jq}/bin/jq '.outputFile' -c -r $jsonInput)
source=$(${jq}/bin/jq '.source' -c -r $jsonInput)
relPath=$(${jq}/bin/jq '.project.relPath' -c -r $jsonInput)
tmpDir=$(mktemp -d)
gradle2nix --project $source --out-dir $tmpDir
somehow format the json file created by gradle2nix $tmpDir/gradle-env.json > $outputFile
# TODO:
# read input files/dirs and produce a json file at $outputFile
# containing the dream lock similar to /src/specifications/dream-lock-example.json
'';
# If the translator requires additional arguments, specify them here.
# When users run the CLI, they will be asked to specify these arguments.
# There are only two types of arguments:
# - string argument (type = "argument")
# - boolean flag (type = "flag")
# String arguments contain a default value and examples. Flags do not.
extraArgs = {
# Example: boolean option
# Flags always default to 'false' if not specified by the user
noDev = {
description = "Exclude dev dependencies";
type = "flag";
};
# Example: string option
theAnswer = {
default = "42";
description = "The Answer to the Ultimate Question of Life";
examples = [
"0"
"1234"
];
type = "argument";
};
};
}