nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 177 lines 5.4 kB view raw
1{ 2 lib, 3 stdenv, 4 fetchFromGitHub, 5 fetchgit, 6 fetchHex, 7 erlang, 8 makeWrapper, 9 writeScript, 10 common-updater-scripts, 11 coreutils, 12 git, 13 gnused, 14 nix, 15 rebar3-nix, 16}: 17 18let 19 version = "3.26.0"; 20 owner = "erlang"; 21 deps = import ./rebar-deps.nix { inherit fetchFromGitHub fetchgit fetchHex; }; 22 rebar3 = stdenv.mkDerivation rec { 23 pname = "rebar3"; 24 inherit version erlang; 25 26 # How to obtain `sha256`: 27 # nix-prefetch-url --unpack https://github.com/erlang/rebar3/archive/${version}.tar.gz 28 src = fetchFromGitHub { 29 inherit owner; 30 repo = pname; 31 rev = version; 32 sha256 = "PDWJFSe8xEUwHcN10PUz6c5EWZLIrKTVqM0xExk9nJs="; 33 }; 34 35 buildInputs = [ erlang ]; 36 37 postPatch = '' 38 mkdir -p _checkouts _build/default/lib/ 39 40 ${toString ( 41 lib.mapAttrsToList (k: v: '' 42 cp -R --no-preserve=mode ${v} _checkouts/${k} 43 '') deps 44 )} 45 46 # Bootstrap script expects the dependencies in _build/default/lib 47 # TODO: Make it accept checkouts? 48 for i in _checkouts/* ; do 49 ln -s $(pwd)/$i $(pwd)/_build/default/lib/ 50 done 51 ''; 52 53 buildPhase = '' 54 HOME=. escript bootstrap 55 ''; 56 57 checkPhase = '' 58 HOME=. escript ./rebar3 ct 59 ''; 60 61 doCheck = true; 62 63 installPhase = '' 64 mkdir -p $out/bin 65 cp rebar3 $out/bin/rebar3 66 ''; 67 68 meta = { 69 homepage = "https://github.com/rebar/rebar3"; 70 description = "Erlang build tool that makes it easy to compile and test Erlang applications, port drivers and releases"; 71 mainProgram = "rebar3"; 72 73 longDescription = '' 74 rebar is a self-contained Erlang script, so it's easy to distribute or 75 even embed directly in a project. Where possible, rebar uses standard 76 Erlang/OTP conventions for project structures, thus minimizing the amount 77 of build configuration work. rebar also provides dependency management, 78 enabling application writers to easily re-use common libraries from a 79 variety of locations (hex.pm, git, hg, and so on). 80 ''; 81 82 platforms = lib.platforms.unix; 83 teams = [ lib.teams.beam ]; 84 license = lib.licenses.asl20; 85 }; 86 87 passthru.updateScript = writeScript "update.sh" '' 88 #!${stdenv.shell} 89 set -ox errexit 90 PATH=${ 91 lib.makeBinPath [ 92 common-updater-scripts 93 coreutils 94 git 95 gnused 96 nix 97 (rebar3WithPlugins { globalPlugins = [ rebar3-nix ]; }) 98 ] 99 } 100 latest=$(list-git-tags | sed -n '/[\d\.]\+/p' | sort -V | tail -1) 101 if [ "$latest" != "${version}" ]; then 102 nixpkgs="$(git rev-parse --show-toplevel)" 103 nix_path="$nixpkgs/pkgs/development/tools/build-managers/rebar3" 104 update-source-version rebar3 "$latest" --version-key=version --print-changes --file="$nix_path/default.nix" 105 tmpdir=$(mktemp -d) 106 cp -R $(nix-build $nixpkgs --no-out-link -A rebar3.src)/* "$tmpdir" 107 (cd "$tmpdir" && rebar3 as test nix lock -o "$nix_path/rebar-deps.nix") 108 nix run -f $nixpkgs/ci fmt.pkg "$nix_path/rebar-deps.nix" 109 else 110 echo "rebar3 is already up-to-date" 111 fi 112 ''; 113 }; 114 115 # Alias rebar3 so we can use it as default parameter below 116 _rebar3 = rebar3; 117 118 rebar3WithPlugins = 119 { 120 plugins ? [ ], 121 globalPlugins ? [ ], 122 rebar3 ? _rebar3, 123 }: 124 let 125 pluginLibDirs = map (p: "${p}/lib/erlang/lib") (lib.unique (plugins ++ globalPlugins)); 126 globalPluginNames = lib.unique (map (p: p.packageName) globalPlugins); 127 rebar3Patched = ( 128 rebar3.overrideAttrs (old: { 129 130 # skip-plugins.patch is necessary because otherwise rebar3 will always 131 # try to fetch plugins if they are not already present in _build. 132 # 133 # global-deps.patch makes it possible to use REBAR_GLOBAL_PLUGINS to 134 # instruct rebar3 to always load a certain plugin. It is necessary since 135 # REBAR_GLOBAL_CONFIG_DIR doesn't seem to work for this. 136 patches = [ 137 ./skip-plugins.patch 138 ./global-plugins.patch 139 ]; 140 141 # our patches cause the tests to fail 142 doCheck = false; 143 }) 144 ); 145 in 146 stdenv.mkDerivation { 147 pname = "rebar3-with-plugins"; 148 inherit (rebar3) version; 149 nativeBuildInputs = [ 150 erlang 151 makeWrapper 152 ]; 153 unpackPhase = "true"; 154 155 # Here we extract the rebar3 escript (like `rebar3_prv_local_install.erl`) and 156 # add plugins to the code path. 157 158 installPhase = '' 159 erl -noshell -eval ' 160 {ok, Escript} = escript:extract("${rebar3Patched}/bin/rebar3", []), 161 {archive, Archive} = lists:keyfind(archive, 1, Escript), 162 {ok, _} = zip:extract(Archive, [{cwd, "'$out/lib'"}]), 163 init:stop(0) 164 ' 165 cp ${./rebar_ignore_deps.erl} rebar_ignore_deps.erl 166 erlc -o $out/lib/rebar/ebin rebar_ignore_deps.erl 167 mkdir -p $out/bin 168 makeWrapper ${erlang}/bin/erl $out/bin/rebar3 \ 169 --set REBAR_GLOBAL_PLUGINS "${toString globalPluginNames} rebar_ignore_deps" \ 170 --suffix-each ERL_LIBS ":" "$out/lib ${toString pluginLibDirs}" \ 171 --add-flags "+sbtu +A1 -noshell -boot start_clean -s rebar3 main -extra" 172 ''; 173 }; 174in 175{ 176 inherit rebar3 rebar3WithPlugins; 177}