diff --git a/src/rebar3_nix_init_prv.erl b/src/rebar3_nix_init_prv.erl index 9c0da30..db0863a 100644 --- a/src/rebar3_nix_init_prv.erl +++ b/src/rebar3_nix_init_prv.erl @@ -22,7 +22,7 @@ buildRebar3 { "{ pkgs ? import { } }: with pkgs.beamPackages; rebar3Relx { - name = \"~s\"; + pname = \"~s\"; version = \"0.1.0\"; src = ./.; releaseType = \"~s\"; diff --git a/src/rebar3_nix_lock_prv.erl b/src/rebar3_nix_lock_prv.erl index 3171500..9fa99eb 100644 --- a/src/rebar3_nix_lock_prv.erl +++ b/src/rebar3_nix_lock_prv.erl @@ -20,6 +20,15 @@ in self beamDeps = [ ~s]; };"). +-define(DEP_SUBDIR, " + ~s = builder rec { + name = \"~s\"; + version = \"~s\"; + src = ~s; + beamDeps = [ ~s]; + sourceRoot = \"${src.name}/~s\"; + };"). + -define(FETCH_HEX, "fetchHex { pkg = \"~s\"; @@ -97,13 +106,18 @@ format_error(Reason) -> to_nix(AppInfo, AllDepsNames) -> Name = rebar_app_info:name(AppInfo), - {Vsn, Src} = src(Name, rebar_app_info:source(AppInfo)), + {Vsn, Src, Subdir} = src(Name, rebar_app_info:source(AppInfo)), Deps = [[BinName, " "] || BinName <- app_deps(AppInfo), lists:member(BinName, AllDepsNames)], - io_lib:format(?DEP, [Name, Name, Vsn, Src, Deps]). + case Subdir of + root -> + io_lib:format(?DEP, [Name, Name, Vsn, Src, Deps]); + {subdir, Dir} -> + io_lib:format(?DEP_SUBDIR, [Name, Name, Vsn, Src, Deps, Dir]) + end. src(_, {pkg, PkgName, Vsn, _OldHash, Hash, _Repo}) -> - {Vsn, io_lib:format(?FETCH_HEX, [PkgName, Vsn, to_sri(Hash)])}; + {Vsn, io_lib:format(?FETCH_HEX, [PkgName, Vsn, to_sri(Hash)]), root}; src(_, {git, Url, {ref, Ref}}) -> case string:prefix(string:lowercase(Url), "https://github.com/") of nomatch -> @@ -111,15 +125,18 @@ src(_, {git, Url, {ref, Ref}}) -> {ok, Json} = rebar3_nix_utils:cmd(Prefetch), {ok, #{<<"sha256">> := Hash}, _} = rebar3_nix_jsone_decode_vendored:decode(unicode:characters_to_binary(Json)), - {"git", io_lib:format(?FETCH_GIT, [Url, Ref, Hash])}; + {"git", io_lib:format(?FETCH_GIT, [Url, Ref, Hash]), root}; Path -> [Owner, Repo0] = string:split(Path, "/", trailing), Repo = re:replace(Repo0, "\\.git$", "", [{return, list}]), Prefetch = ["nix-prefetch-url --unpack https://github.com/", Owner, "/", Repo, "/tarball/", Ref], {ok, Hash} = rebar3_nix_utils:cmd(Prefetch), - {"git", io_lib:format(?FETCH_FROM_GITHUB, [Owner, Repo, Ref, Hash])} + {"git", io_lib:format(?FETCH_FROM_GITHUB, [Owner, Repo, Ref, Hash]), root} end; +src(Name, {git_subdir, Url, {ref, Ref}, Subdir}) -> + {Vsn, Src, root} = src(Name, {git, Url, {ref, Ref}}), + {Vsn, Src, {subdir, Subdir}}; src(Name, Other) -> rebar_api:abort("rebar3_nix: unsupported dependency type ~p for ~s~n", [Other, Name]), undefined. diff --git a/tests/Makefile b/tests/Makefile index b567bf3..4ff6a7a 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,4 +1,4 @@ -NIX_PATH := nixpkgs=https://github.com/NixOS/nixpkgs/archive/56d11e1467123fb1cd6212418aa2703520415524.tar.gz +NIX_PATH := nixpkgs=https://github.com/NixOS/nixpkgs/archive/72841a4a8761d1aed92ef6169a636872c986c76d.tar.gz all: clean nix-shell --run 'make test' @@ -9,7 +9,9 @@ PROJECTS := test_app test_lib test_release test_escript test_profiles DEPS := \ {cowboy, "2.8.0"}, \ {hackney, {git, "https://github.com/benoitc/hackney.git", {ref, "01bb4249f595e0aa692db28ef23e70f57ae2d4ed"}}}, \ - {zj, {git, "https://gitlab.com/zxq9/zj.git", {ref, "27b7252f82c726d78f7ea297644b6b8ad90df479"}}} + {zj, {git, "https://gitlab.com/zxq9/zj.git", {ref, "27b7252f82c726d78f7ea297644b6b8ad90df479"}}}, \ + {opentelemetry_api, {git_subdir, "https://github.com/open-telemetry/opentelemetry-erlang.git", \ + {ref, "6f1d63673ccd628d057f2cc3f4909ac63279cc10"}, "apps/opentelemetry_api"}} APP_DEPS := cowboy @@ -20,7 +22,7 @@ test: $(PROJECTS) test_profiles: test_lib cp -R test_lib test_profiles - printf "\n{profiles, [{test, [{deps, [meck]}]}]}.\n" >> test_profiles/rebar.config + printf "\n{profiles, [{test, [{deps, [{meck, \"1.0.0\"}]}]}]}.\n" >> test_profiles/rebar.config cd test_profiles && rebar3 as test nix lock nix-build test_profiles nix-shell ./test_profiles --run \