elmPackages: Refactor lib and builds of packages

This commit is contained in:
Marek Fajkus 2020-04-15 21:29:52 +02:00
parent 48dd117b24
commit b9e9effb44
No known key found for this signature in database
GPG Key ID: 95585219BA6FE2CC
6 changed files with 2448 additions and 2745 deletions

View File

@ -71,56 +71,60 @@ let
}; };
}; };
/* /* Node/NPM based dependecies can be upgraded using script `packages/generate-node-packages.sh`.
Node/NPM based dependecies can be upgraded using script
`packages/generate-node-packages.sh`. * Packages which rely on `bin-wrap` will fail by default
Packages which rely on `bin-wrap` will fail by default and can be patched using `patchBinwrap` function defined in `packages/lib.nix`.
and can be patched using `patchBinwrap` function defined in `packages/patch-binwrap.nix`.
* Packages which depend on npm installation of elm can be patched using
`patchNpmElm` function also defined in `packages/lib.nix`.
*/ */
elmNodePackages = elmLib = import ./packages/lib.nix {
inherit lib writeScriptBin stdenv;
inherit (hsPkgs.elmPkgs) elm;
};
elmNodePackages = with elmLib;
let let
nodePkgs = import ./packages/node-composition.nix { nodePkgs = import ./packages/node-composition.nix {
inherit nodejs pkgs; inherit nodejs pkgs;
inherit (stdenv.hostPlatform) system; inherit (stdenv.hostPlatform) system;
}; };
in with hsPkgs.elmPkgs; { in with hsPkgs.elmPkgs; {
elm-test = patchBinwrap [elmi-to-json] nodePkgs.elm-test;
elm-verify-examples = patchBinwrap [elmi-to-json] nodePkgs.elm-verify-examples; elm-test = patchBinwrap [elmi-to-json]
nodePkgs.elm-test;
elm-verify-examples = patchBinwrap [elmi-to-json]
nodePkgs.elm-verify-examples;
elm-coverage = elm-coverage =
let patched = patchBinwrap [elmi-to-json] nodePkgs.elm-coverage; let patched = patchNpmElm (patchBinwrap [elmi-to-json] nodePkgs.elm-coverage);
in patched.override { in patched.override (old: {
preRebuild = '' # Symlink Elm instrument binary
preRebuild = (old.preRebuild or "") + ''
# Noop custom installation script
sed 's/\"install\".*/\"install\":\"echo no-op\"/g' --in-place package.json sed 's/\"install\".*/\"install\":\"echo no-op\"/g' --in-place package.json
# This should not be needed (thanks to binwrap* being nooped) but for some reason it still needs to be done # This should not be needed (thanks to binwrap* being nooped) but for some reason it still needs to be done
# in case of just this package # in case of just this package
# TODO: investigate
sed 's/\"install\".*/\"install\":\"echo no-op\",/g' --in-place node_modules/elmi-to-json/package.json sed 's/\"install\".*/\"install\":\"echo no-op\",/g' --in-place node_modules/elmi-to-json/package.json
rm node_modules/elm/install.js
echo "console.log('no-op');" > node_modules/elm/install.js
''; '';
postInstall = (old.postInstall or "") + ''
# Link Elm instrument binary
postInstall = patched.postInstall + ''
mkdir -p unpacked_bin mkdir -p unpacked_bin
ln -sf ${elm-instrument}/bin/elm-instrument unpacked_bin/elm-instrument ln -sf ${elm-instrument}/bin/elm-instrument unpacked_bin/elm-instrument
''; '';
}; });
create-elm-app = patchBinwrap [elmi-to-json] (nodePkgs.create-elm-app.override { create-elm-app = patchNpmElm (patchBinwrap [elmi-to-json]
preRebuild = '' nodePkgs.create-elm-app);
rm node_modules/elm/install.js
echo "console.log('no-op');" > node_modules/elm/install.js
'';
});
elm-language-server = nodePkgs."@elm-tooling/elm-language-server"; elm-language-server = nodePkgs."@elm-tooling/elm-language-server";
inherit (nodePkgs) elm-doc-preview elm-live elm-upgrade elm-xref elm-analyse; inherit (nodePkgs) elm-doc-preview elm-live elm-upgrade elm-xref elm-analyse;
}; };
patchBinwrap = import ./packages/patch-binwrap.nix { inherit lib writeScriptBin stdenv; };
in hsPkgs.elmPkgs // elmNodePackages // { in hsPkgs.elmPkgs // elmNodePackages // {
lib = { inherit patchBinwrap; }; lib = elmLib;
} }

View File

@ -6,7 +6,7 @@ set -eu -o pipefail
rm -f node-env.nix rm -f node-env.nix
$(nix-build $ROOT -A nodePackages.node2nix --no-out-link)/bin/node2nix \ $(nix-build $ROOT -A nodePackages.node2nix --no-out-link)/bin/node2nix \
--nodejs-10 \ --nodejs-12 \
-i node-packages.json \ -i node-packages.json \
-o node-packages.nix \ -o node-packages.nix \
-c node-composition.nix \ -c node-composition.nix \

View File

@ -0,0 +1,43 @@
{ writeScriptBin, stdenv, lib, elm }:
let
patchBinwrap =
let
# Patching binwrap by NoOp script
binwrap = writeScriptBin "binwrap" ''
#! ${stdenv.shell}
echo "binwrap called: Returning 0"
return 0
'';
binwrap-install = writeScriptBin "binwrap-install" ''
#! ${stdenv.shell}
echo "binwrap-install called: Doing nothing"
'';
in targets: pkg:
pkg.override (old: {
nativeBuildInputs = (old.nativeBuildInputs or []) ++ [ binwrap binwrap-install ];
# Manually install targets
# by symlinking binaries into `node_modules`
postInstall = let
binFile = module: lib.strings.removeSuffix ("-" + module.version) module.name;
in (old.postInstall or "") + ''
${lib.concatStrings (map (module: ''
echo "linking ${binFile module}"
ln -sf ${module}/bin/${binFile module} \
node_modules/${binFile module}/bin/${binFile module}
'') targets)}
'';
});
patchNpmElm = pkg:
pkg.override (old: {
preRebuild = (old.preRebuild or "") + ''
rm node_modules/elm/install.js
echo "console.log('Nixpkgs\' version of Elm will be used');" > node_modules/elm/install.js
'';
postInstall = (old.postInstall or "") + ''
ln -sf ${elm}/bin/elm node_modules/elm/bin/elm
'';
});
in
{ inherit patchBinwrap patchNpmElm; }

View File

@ -2,7 +2,7 @@
{pkgs ? import <nixpkgs> { {pkgs ? import <nixpkgs> {
inherit system; inherit system;
}, system ? builtins.currentSystem, nodejs ? pkgs."nodejs-10_x"}: }, system ? builtins.currentSystem, nodejs ? pkgs."nodejs-12_x"}:
let let
nodeEnv = import ../../../node-packages/node-env.nix { nodeEnv = import ../../../node-packages/node-env.nix {

File diff suppressed because it is too large Load Diff

View File

@ -1,30 +0,0 @@
{ writeScriptBin, stdenv, lib }:
let
# Patching binwrap by NoOp script
binwrap = writeScriptBin "binwrap" ''
#! ${stdenv.shell}
echo "binwrap called: Returning 0"
return 0
'';
binwrap-install = writeScriptBin "binwrap-install" ''
#! ${stdenv.shell}
echo "binwrap-install called: Doing nothing"
'';
in
targets:
pkg:
pkg.override {
nativeBuildInputs = pkg.nativeBuildInputs ++ [ binwrap binwrap-install ];
# Manually install targets
# by symlinking binaries into `node_modules`
postInstall = let
binFile = module: lib.strings.removeSuffix ("-" + module.version) module.name;
in ''
${lib.concatStrings (map (module: ''
echo "linking ${binFile module}"
ln -sf ${module}/bin/${binFile module} \
node_modules/${binFile module}/bin/${binFile module}
'') targets)}
'';
}