Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ deps_nix-*.tar
# Temporary files, for example, from tests.
/tmp/
/.direnv
result
69 changes: 67 additions & 2 deletions fixtures/example/deps.nix
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,26 @@ let
${old.buildPhase}
'';
};

elixirMake = _unusedArgs: old: {
preConfigure = ''
export ELIXIR_MAKE_CACHE_DIR="$TEMPDIR/elixir_make_cache"
'';
};

lazyHtml = _unusedArgs: old: {
preConfigure = ''
export ELIXIR_MAKE_CACHE_DIR="$TEMPDIR/elixir_make_cache"
'';

postPatch = ''
substituteInPlace mix.exs --replace-fail "Fine.include_dir()" '"${packages.fine}/src/c_include"' --replace-fail '@lexbor_git_sha "244b84956a6dc7eec293781d051354f351274c46"' '@lexbor_git_sha ""'
'';

preBuild = ''
install -Dm644 -t _build/c/third_party/lexbor/$LEXBOR_GIT_SHA/build ${pkgs.lexbor}/lib/liblexbor_static.a
'';
};
};

defaultOverrides = (
Expand Down Expand Up @@ -260,7 +280,7 @@ let
];
};
in
drv;
drv.override (workarounds.elixirMake { } drv);

chatterbox =
let
Expand Down Expand Up @@ -650,6 +670,23 @@ let
in
drv;

fine =
let
version = "0.1.4";
drv = buildMix {
inherit version;
name = "fine";
appConfigPath = ./config;

src = fetchHex {
inherit version;
pkg = "fine";
sha256 = "be3324cc454a42d80951cf6023b9954e9ff27c6daa255483b3e8d608670303f5";
};
};
in
drv;

fsm =
let
version = "0.3.1";
Expand Down Expand Up @@ -868,6 +905,34 @@ let
in
drv;

lazy_html =
let
version = "0.1.8";
drv = buildMix {
inherit version;
name = "lazy_html";
appConfigPath = ./config;

nativeBuildInputs = with pkgs; [
cmake
lexbor
];

src = fetchHex {
inherit version;
pkg = "lazy_html";
sha256 = "0d8167d930b704feb94b41414ca7f5779dff9bca7fcf619fcef18de138f08736";
};

beamDeps = [
cc_precompiler
elixir_make
fine
];
};
in
drv.override (workarounds.lazyHtml { } drv);

mime =
let
version = "2.0.6";
Expand Down Expand Up @@ -1524,7 +1589,7 @@ let
];
};
in
drv;
drv.override (workarounds.elixirMake { } drv);

websock =
let
Expand Down
1 change: 1 addition & 0 deletions fixtures/example/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ defmodule Example.MixProject do
depth: 1},
{:image, "~> 0.37"},
{:jason, "~> 1.4.1"},
{:lazy_html, "~> 0.1"},
{:opentelemetry_exporter, "~> 1.7"},
{:plug, "~> 1.13", override: true},
{:png, "~> 0.2.1"},
Expand Down
2 changes: 2 additions & 0 deletions fixtures/example/mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"ex_secp256k1": {:hex, :ex_secp256k1, "0.7.3", "489b6fd57fab5a7259ace927d8cb5171aad835e9c7279c2a859a0483cb069415", [:mix], [{:rustler, ">= 0.0.0", [hex: :rustler, repo: "hexpm", optional: true]}, {:rustler_precompiled, "~> 0.7", [hex: :rustler_precompiled, repo: "hexpm", optional: false]}], "hexpm", "ea63159442f4d8143166cd1507da03edc43216d6e7c6bac4b416bdce04f0daa8"},
"explorer": {:hex, :explorer, "0.10.1", "ff6e2a7d7a480c86708c3300cc67a3fd6982c7d28b51f4db2f411aa476c9ecdb", [:mix], [{:adbc, "~> 0.1", [hex: :adbc, repo: "hexpm", optional: true]}, {:aws_signature, "~> 0.3", [hex: :aws_signature, repo: "hexpm", optional: false]}, {:castore, "~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:decimal, "~> 2.1", [hex: :decimal, repo: "hexpm", optional: false]}, {:flame, "~> 0.3", [hex: :flame, repo: "hexpm", optional: true]}, {:fss, "~> 0.1", [hex: :fss, repo: "hexpm", optional: false]}, {:nx, "~> 0.4", [hex: :nx, repo: "hexpm", optional: true]}, {:rustler, "~> 0.34.0", [hex: :rustler, repo: "hexpm", optional: true]}, {:rustler_precompiled, "~> 0.7", [hex: :rustler_precompiled, repo: "hexpm", optional: false]}, {:table, "~> 0.1.2", [hex: :table, repo: "hexpm", optional: false]}, {:table_rex, "~> 3.1.1 or ~> 4.0.0", [hex: :table_rex, repo: "hexpm", optional: false]}], "hexpm", "4e3efc45d4981a568405a181ebf206ba208622a5e94048c9d713b27a053c3197"},
"finch": {:hex, :finch, "0.19.0", "c644641491ea854fc5c1bbaef36bfc764e3f08e7185e1f084e35e0672241b76d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.6.2 or ~> 1.7", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.1", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "fc5324ce209125d1e2fa0fcd2634601c52a787aff1cd33ee833664a5af4ea2b6"},
"fine": {:hex, :fine, "0.1.4", "b19a89c1476c7c57afb5f9314aed5960b5bc95d5277de4cb5ee8e1d1616ce379", [:mix], [], "hexpm", "be3324cc454a42d80951cf6023b9954e9ff27c6daa255483b3e8d608670303f5"},
"fsm": {:hex, :fsm, "0.3.1", "087aa9b02779a84320dc7a2d8464452b5308e29877921b2bde81cdba32a12390", [:mix], [], "hexpm", "fbf0d53f89e9082b326b0b5828b94b4c549ff9d1452bbfd00b4d1ac082208e96"},
"fss": {:hex, :fss, "0.1.1", "9db2344dbbb5d555ce442ac7c2f82dd975b605b50d169314a20f08ed21e08642", [:mix], [], "hexpm", "78ad5955c7919c3764065b21144913df7515d52e228c09427a004afe9c1a16b0"},
"fun_with_flags": {:hex, :fun_with_flags, "1.12.0", "8036ad262ae4321d160e36c4db13c8cadf1890121d74c4f5852ab0de0ac3ad2b", [:mix], [{:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: true]}, {:redix, "~> 1.0", [hex: :redix, repo: "hexpm", optional: true]}], "hexpm", "9ed303bee60687f7a07dde2c036d3e8905771001ebd77790543ba5655a5f9066"},
Expand All @@ -36,6 +37,7 @@
"image": {:hex, :image, "0.58.0", "304a479703e9bdea23276f708099f61020cc815f5e792a2c9788a0e811a82a1f", [:mix], [{:bumblebee, "~> 0.6", [hex: :bumblebee, repo: "hexpm", optional: true]}, {:evision, "~> 0.1.33 or ~> 0.2", [hex: :evision, repo: "hexpm", optional: true]}, {:exla, "~> 0.9", [hex: :exla, repo: "hexpm", optional: true]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: true]}, {:kino, "~> 0.13", [hex: :kino, repo: "hexpm", optional: true]}, {:nx, "~> 0.9", [hex: :nx, repo: "hexpm", optional: true]}, {:nx_image, "~> 0.1", [hex: :nx_image, repo: "hexpm", optional: true]}, {:phoenix_html, "~> 2.1 or ~> 3.2 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:plug, "~> 1.13", [hex: :plug, repo: "hexpm", optional: true]}, {:rustler, "> 0.0.0", [hex: :rustler, repo: "hexpm", optional: true]}, {:scholar, "~> 0.3", [hex: :scholar, repo: "hexpm", optional: true]}, {:sweet_xml, "~> 0.7", [hex: :sweet_xml, repo: "hexpm", optional: false]}, {:vix, "~> 0.23", [hex: :vix, repo: "hexpm", optional: false]}], "hexpm", "b5d472360caa7e8a113aeaa06559c705b593361c9d1391e1992b66ed2d7b6889"},
"jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"},
"kafka_protocol": {:hex, :kafka_protocol, "4.1.5", "d15e64994a8ca99716ab47db4132614359ac1bfa56d6c5b4341fdc1aa4041518", [:rebar3], [{:crc32cer, "0.1.8", [hex: :crc32cer, repo: "hexpm", optional: false]}], "hexpm", "c956c9357fef493b7072a35d0c3e2be02aa5186c804a412d29e62423bb15e5d9"},
"lazy_html": {:hex, :lazy_html, "0.1.8", "677a8642e644eef8de98f3040e2520d42d0f0f8bd6c5cd49db36504e34dffe91", [:make, :mix], [{:cc_precompiler, "~> 0.1", [hex: :cc_precompiler, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.9.0", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:fine, "~> 0.1.0", [hex: :fine, repo: "hexpm", optional: false]}], "hexpm", "0d8167d930b704feb94b41414ca7f5779dff9bca7fcf619fcef18de138f08736"},
"mime": {:hex, :mime, "2.0.6", "8f18486773d9b15f95f4f4f1e39b710045fa1de891fada4516559967276e4dc2", [:mix], [], "hexpm", "c9945363a6b26d747389aac3643f8e0e09d30499a138ad64fe8fd1d13d9b153e"},
"mint": {:hex, :mint, "1.6.2", "af6d97a4051eee4f05b5500671d47c3a67dac7386045d87a904126fd4bbcea2e", [:mix], [{:castore, "~> 0.1.0 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:hpax, "~> 0.1.1 or ~> 0.2.0 or ~> 1.0", [hex: :hpax, repo: "hexpm", optional: false]}], "hexpm", "5ee441dffc1892f1ae59127f74afe8fd82fda6587794278d924e4d90ea3d63f9"},
"nimble_options": {:hex, :nimble_options, "1.1.1", "e3a492d54d85fc3fd7c5baf411d9d2852922f66e69476317787a7b2bb000a61b", [:mix], [], "hexpm", "821b2470ca9442c4b6984882fe9bb0389371b8ddec4d45a9504f00a66f650b44"},
Expand Down
24 changes: 24 additions & 0 deletions lib/deps_nix.ex
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,30 @@ defmodule DepsNix do
${old.buildPhase}
'';
};

elixirMake = _unusedArgs: old: {
preConfigure = ''
export ELIXIR_MAKE_CACHE_DIR="$TEMPDIR/elixir_make_cache"
'';
};

lazyHtml = _unusedArgs: old: {
preConfigure = ''
export ELIXIR_MAKE_CACHE_DIR="$TEMPDIR/elixir_make_cache"
'';

postPatch = ''
substituteInPlace mix.exs \
--replace-fail "Fine.include_dir()" '"${packages.fine}/src/c_include"' \
--replace-fail '@lexbor_git_sha "244b84956a6dc7eec293781d051354f351274c46"' '@lexbor_git_sha ""'
'';

preBuild = ''
install -Dm644 \
-t _build/c/third_party/lexbor/$LEXBOR_GIT_SHA/build \
${pkgs.lexbor}/lib/liblexbor_static.a
'';
};
};

defaultOverrides = (
Expand Down
40 changes: 35 additions & 5 deletions lib/deps_nix/derivation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,27 @@ defmodule DepsNix.Derivation do
"""
end

def to_string(%DepsNix.Derivation{name: :lazy_html} = drv) do
"""
lazy_html =
let
version = "#{drv.version}";
drv = #{drv.builder} {
inherit version;
name = "#{drv.name}";#{format_app_config_path(drv)}

nativeBuildInputs = with pkgs; [
cmake
lexbor
];

src = #{src(drv.src)}#{beam_deps(drv.beam_deps)}
};
in
drv#{override(drv)};
"""
end

def to_string(%DepsNix.Derivation{name: :heroicons} = drv) do
"""
#{drv.name} = #{drv.src |> Kernel.to_string()}
Expand Down Expand Up @@ -208,7 +229,7 @@ defmodule DepsNix.Derivation do
+++ b/lib/unicode.ex
@@ -46,7 +46,7 @@ defmodule Unicode do
:hebrew | :buginese | :tifinagh

@doc false
- @data_dir Path.join(__DIR__, "../data") |> Path.expand()
+ @data_dir "/tmp/unicode-data"
Expand Down Expand Up @@ -266,11 +287,20 @@ defmodule DepsNix.Derivation do
|> Util.indent(from: 2)
end

defp override(%{name: :lazy_html} = _drv) do
".override (workarounds.lazyHtml { } drv)"
end

defp override(drv) do
if :rustler_precompiled in drv.beam_deps do
".override (workarounds.rustlerPrecompiled { } drv)"
else
""
cond do
:rustler_precompiled in drv.beam_deps ->
".override (workarounds.rustlerPrecompiled { } drv)"

:elixir_make in drv.beam_deps ->
".override (workarounds.elixirMake { } drv)"

true ->
""
end
end

Expand Down
52 changes: 49 additions & 3 deletions test/deps_nix/special_treatment_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ defmodule DepsNix.SpecialTreatmentTest do
sha256: "9acde72b27bdfeadeb51f790f7a6cc0d06cf555718c05cf57e43c5cf93d8471b"
},
beam_deps: [
:castore,
:cc_precompiler,
:elixir_make
],
Expand Down Expand Up @@ -157,13 +156,60 @@ defmodule DepsNix.SpecialTreatmentTest do
};

beamDeps = [
castore
cc_precompiler
elixir_make
];
};
in
drv;
drv.override (workarounds.elixirMake { } drv);
"""
end

test "lazy_html applies a workaround so it can build against lexbor with elixir_make" do
assert %Derivation{
builder: "buildMix",
name: :lazy_html,
version: "0.1.8",
src: %FetchHex{
pkg: :my_project,
version: "0.1.8",
sha256: "0d8167d930b704feb94b41414ca7f5779dff9bca7fcf619fcef18de138f08736"
},
beam_deps: [
:cc_precompiler,
:elixir_make,
:fine
],
app_config_path: "./config"
}
|> to_string() == """
lazy_html =
let
version = "0.1.8";
drv = buildMix {
inherit version;
name = "lazy_html";
appConfigPath = ./config;

nativeBuildInputs = with pkgs; [
cmake
lexbor
];

src = fetchHex {
inherit version;
pkg = "my_project";
sha256 = "0d8167d930b704feb94b41414ca7f5779dff9bca7fcf619fcef18de138f08736";
};

beamDeps = [
cc_precompiler
elixir_make
fine
];
};
in
drv.override (workarounds.lazyHtml { } drv);
"""
end

Expand Down
Loading