mirror of
https://github.com/nix-community/nix-on-droid-app.git
synced 2025-11-08 11:36:11 +01:00
nix flake init
Signed-off-by: phanirithvij <phanirithvij2000@gmail.com>
This commit is contained in:
parent
14dc0df6c4
commit
e87b6091bf
10 changed files with 5057 additions and 0 deletions
145
nix/deps-scripts.nix
Normal file
145
nix/deps-scripts.nix
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
{
|
||||
bash,
|
||||
coreutils,
|
||||
curl,
|
||||
jq,
|
||||
htmlq,
|
||||
gawk,
|
||||
gitMinimal,
|
||||
gnused,
|
||||
gnugrep,
|
||||
gradle,
|
||||
fetchurl,
|
||||
parallel,
|
||||
moreutils,
|
||||
writeShellApplication,
|
||||
go-maven-resolver,
|
||||
callPackage,
|
||||
}:
|
||||
let
|
||||
url2json = callPackage ./url2json.nix { };
|
||||
resolve-gradle-deps = writeShellApplication {
|
||||
name = "resolve-gradle-deps";
|
||||
runtimeInputs = [
|
||||
gradle
|
||||
gitMinimal
|
||||
];
|
||||
inheritPath = false;
|
||||
text = ''
|
||||
pushd "$(git rev-parse --show-toplevel)" >/dev/null || exit 1
|
||||
gradle -I nix/init.gradle \
|
||||
--no-daemon --dependency-verification=off \
|
||||
--no-configuration-cache --no-configure-on-demand \
|
||||
:ForceDependencyResolutionPlugin_resolveAllDependencies >/dev/null 2>&1 || exit 1
|
||||
popd >/dev/null || exit 1
|
||||
'';
|
||||
meta.description = "Generates the full dependency report from current project";
|
||||
};
|
||||
gen-deps-lock = writeShellApplication {
|
||||
name = "gen-deps-lock";
|
||||
bashOptions = [ ]; # TODO decide what these should be
|
||||
runtimeInputs = [
|
||||
gawk
|
||||
gitMinimal
|
||||
gnused
|
||||
gnugrep
|
||||
# order matters, parallel first, then moreutils
|
||||
parallel
|
||||
moreutils # sponge
|
||||
go-maven-resolver
|
||||
|
||||
url2json
|
||||
bash
|
||||
jq
|
||||
htmlq
|
||||
curl
|
||||
coreutils
|
||||
];
|
||||
text = ''
|
||||
pushd "$(git rev-parse --show-toplevel)" >/dev/null || exit 1
|
||||
|
||||
out=''${2:-nix/gradle.lock}
|
||||
|
||||
# trim/format input file properly
|
||||
deps_list="$(grep . "$1" | awk '{$1=$1};1')"
|
||||
|
||||
echo "[" >"$out"
|
||||
|
||||
# note: moreutils parallel doesn't work here
|
||||
echo -en "$deps_list" | go-maven-resolver | \
|
||||
parallel --will-cite --keep-order --jobs 4 url2json >>"$out"
|
||||
|
||||
# convert to gradle2nix lock format
|
||||
grep . "$out" | sed '$s/,$/\n]/' | jq -r 'map(. as $root | {
|
||||
(.path | split("/") | (.[0:-2] | join(".")) + ":" + .[-2] + ":" + .[-1]): (.files | to_entries | map({
|
||||
(.key): {
|
||||
url: ($root.repo + "/" + $root.path + "/" + .key),
|
||||
hash: .value.sha256
|
||||
}
|
||||
}) | add)
|
||||
}) | add' | jq -S . | sponge "$out"
|
||||
|
||||
popd >/dev/null || exit 1
|
||||
'';
|
||||
inheritPath = true; # url2json needs nix
|
||||
meta.description = "script to help create the gradle.lock file";
|
||||
};
|
||||
regen-lock = writeShellApplication {
|
||||
name = "regen-lock";
|
||||
runtimeInputs = [
|
||||
gen-deps-lock
|
||||
gitMinimal
|
||||
coreutils # cat
|
||||
];
|
||||
text = ''
|
||||
set -x
|
||||
pushd "$(git rev-parse --show-toplevel)" >/dev/null || exit 1
|
||||
|
||||
gen-deps-lock <(
|
||||
# missing deps from build report
|
||||
# https://github.com/status-im/status-mobile/blob/674261c7e2808b918e85428073768827ecfc836d/nix/deps/gradle/deps_hack.sh#L29C1-L29C148
|
||||
# https://github.com/googlesamples/android-custom-lint-rules/blob/be672cd747ecf13844918e1afccadb935f856a72/docs/api-guide/example.md.html#L112-L129
|
||||
|
||||
# lint-gradle version should be gradle version + 23.0.0, as of now 7.4.2 + 23.0.0
|
||||
# httpclient version can be determined by removing it and running build-apk
|
||||
echo -en '
|
||||
com.android.tools.lint:lint-gradle:30.4.2
|
||||
org.apache.httpcomponents:httpclient:4.5.6
|
||||
'
|
||||
cat build/reports/dependency-graph-snapshots/dependency-list.txt
|
||||
)
|
||||
popd >/dev/null || exit 1
|
||||
'';
|
||||
inheritPath = true; # gen-deps-lock needs path
|
||||
meta.description = "Generates the gradle.lock file";
|
||||
};
|
||||
build-apk = writeShellApplication {
|
||||
name = "build-apk";
|
||||
runtimeInputs = [
|
||||
resolve-gradle-deps
|
||||
regen-lock
|
||||
];
|
||||
text = # bash
|
||||
''
|
||||
# generate full dependency report
|
||||
resolve-gradle-deps
|
||||
|
||||
# generate gradle.lock
|
||||
regen-lock
|
||||
|
||||
# build apk
|
||||
nix build -L
|
||||
'';
|
||||
inheritPath = true; # need nix, regen-lock needs path
|
||||
meta.description = "Re-create gradle.lock and build the apk";
|
||||
};
|
||||
in
|
||||
{
|
||||
inherit
|
||||
build-apk
|
||||
resolve-gradle-deps
|
||||
regen-lock
|
||||
gen-deps-lock
|
||||
url2json
|
||||
;
|
||||
}
|
||||
26
nix/go-maven-resolver.nix
Normal file
26
nix/go-maven-resolver.nix
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
lib,
|
||||
buildGoModule,
|
||||
fetchFromGitHub,
|
||||
}:
|
||||
|
||||
buildGoModule (finalAttrs: {
|
||||
pname = "go-maven-resolver";
|
||||
version = "1.1.2-unstable-2025-06-16";
|
||||
|
||||
vendorHash = "sha256-dlqI+onfeo4tTwmHeq8heVKRzLU1gFEQ+4iv+8egN90=";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "status-im";
|
||||
repo = "go-maven-resolver";
|
||||
rev = "473b36df1d12996fc5fbcb8b7cc4f60c9aa4f8e0";
|
||||
hash = "sha256-wYGjOcNnhMU2hwKGNLEAT4CcienKw5CvWieH1wV7bA8=";
|
||||
};
|
||||
|
||||
meta = {
|
||||
description = "go maven resolver";
|
||||
homepage = "https://github.com/status-im/go-maven-resolver";
|
||||
license = lib.licenses.mit;
|
||||
mainProgram = "go-maven-resolver";
|
||||
};
|
||||
})
|
||||
4622
nix/gradle.lock
Normal file
4622
nix/gradle.lock
Normal file
File diff suppressed because it is too large
Load diff
9
nix/init.gradle
Normal file
9
nix/init.gradle
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
initscript {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.gradle:github-dependency-graph-gradle-plugin:+"
|
||||
}
|
||||
}
|
||||
apply plugin: org.gradle.dependencygraph.simple.SimpleDependencyGraphPlugin
|
||||
12
nix/url2json-fix-printing.patch
Normal file
12
nix/url2json-fix-printing.patch
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
--- a/url2json.sh
|
||||
+++ b/url2json.sh
|
||||
@@ -115,7 +115,8 @@ PKG_URL_NO_EXT="${POM_URL%.pom}"
|
||||
# Name of package without extension.
|
||||
PKG_NAME="$(basename "${PKG_URL_NO_EXT}")"
|
||||
|
||||
-echo -en "${CLR} - Nix entry for: ${1##*/}\r" >&2
|
||||
+printf -v spaces '%*s' 60 ''
|
||||
+echo -en "${CLR} - Nix entry for: ${1##*/}$spaces\r" >&2
|
||||
|
||||
REPO_URL=$(match_repo_url "${PKG_URL_NO_EXT}")
|
||||
|
||||
18
nix/url2json.nix
Normal file
18
nix/url2json.nix
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# This script url2json.sh is the heart behind gradle dependency lock generation
|
||||
{ stdenv, fetchurl }:
|
||||
stdenv.mkDerivation {
|
||||
name = "url2json";
|
||||
phases = [ "buildPhase" ];
|
||||
src = fetchurl {
|
||||
url = "https://github.com/status-im/status-mobile/raw/2df7a7cf6d46c8d1add73b8965ce8b04e6f7d014/nix/deps/gradle/url2json.sh";
|
||||
hash = "sha256-McEyQPvofpMYv7mvX/7m/eRNYxJOUkm98foSYmYOyE4=";
|
||||
executable = true;
|
||||
};
|
||||
buildPhase = ''
|
||||
mkdir -p $out/bin; cd $out/bin
|
||||
cp $src url2json.sh
|
||||
chmod +w url2json.sh; patch -p1 < ${./url2json-fix-printing.patch}; chmod -w url2json.sh
|
||||
mv url2json.sh url2json
|
||||
'';
|
||||
meta.mainProgram = "url2json";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue