2017-08-01 03:29:53 +01:00
|
|
|
args @ {stdenv, clwrapper, baseName, packageName ? baseName
|
|
|
|
, parasites ? []
|
|
|
|
, buildSystems ? ([packageName] ++ parasites)
|
2017-06-21 21:15:07 +01:00
|
|
|
, version ? "latest"
|
2017-03-31 21:46:32 +01:00
|
|
|
, src, description, deps, buildInputs ? [], meta ? {}, overrides?(x: {})
|
2017-08-01 03:29:53 +01:00
|
|
|
, propagatedBuildInputs ? []
|
|
|
|
, asdFilesToKeep ? [(builtins.concatStringsSep "" [packageName ".asd"])]}:
|
2017-04-10 00:10:39 +01:00
|
|
|
let
|
2013-10-13 07:57:30 +01:00
|
|
|
deployConfigScript = ''
|
2017-04-06 17:43:42 +01:00
|
|
|
outhash="$out"
|
|
|
|
outhash="''${outhash##*/}"
|
|
|
|
outhash="''${outhash%%-*}"
|
2013-10-13 07:57:30 +01:00
|
|
|
config_script="$out"/lib/common-lisp-settings/${args.baseName}-shell-config.sh
|
2017-04-06 17:43:42 +01:00
|
|
|
path_config_script="$out"/lib/common-lisp-settings/${args.baseName}-path-config.sh
|
|
|
|
store_translation="$(dirname "$out"):$(dirname "$out")"
|
2013-10-13 07:57:30 +01:00
|
|
|
mkdir -p "$(dirname "$config_script")"
|
|
|
|
touch "$config_script"
|
2017-04-06 17:43:42 +01:00
|
|
|
touch "$path_config_script"
|
2013-10-13 07:57:30 +01:00
|
|
|
chmod a+x "$config_script"
|
2017-04-06 17:43:42 +01:00
|
|
|
chmod a+x "$path_config_script"
|
|
|
|
echo "if test -z \"\''${_''${outhash}_NIX_LISP_CONFIG}\"; then export _''${outhash}_NIX_LISP_CONFIG=1; " >> "$config_script"
|
2017-03-31 21:46:32 +01:00
|
|
|
echo "export NIX_CFLAGS_COMPILE='$NIX_CFLAGS_COMPILE'\"\''${NIX_CFLAGS_COMPILE:+ \$NIX_CFLAGS_COMPILE}\"" >> "$config_script"
|
2017-04-06 17:43:42 +01:00
|
|
|
echo "export NIX_LDFLAGS='$NIX_LDFLAGS'\"\''${NIX_LDFLAGS:+ \$NIX_LDFLAGS}\"" >> "$config_script"
|
2013-10-13 07:57:30 +01:00
|
|
|
echo "export NIX_LISP_COMMAND='$NIX_LISP_COMMAND'" >> "$config_script"
|
|
|
|
echo "export NIX_LISP_ASDF='$NIX_LISP_ASDF'" >> "$config_script"
|
2017-08-17 16:04:41 +01:00
|
|
|
set | grep NIX_CC_WRAPPER_ | sed -e 's@^NIX_CC_WRAPPER@export &@' >> "$config_script"
|
2017-04-06 17:43:42 +01:00
|
|
|
echo "export PATH=\"\''${PATH:+\$PATH:}$PATH\"" >> "$config_script"
|
|
|
|
echo "echo \"\$ASDF_OUTPUT_TRANSLATIONS\" | grep -E '(^|:)$store_translation(:|\$)' >/dev/null || export ASDF_OUTPUT_TRANSLATIONS=\"\''${ASDF_OUTPUT_TRANSLATIONS:+\$ASDF_OUTPUT_TRANSLATIONS:}\"'$store_translation'" >> "$config_script"
|
|
|
|
echo "source '$path_config_script'" >> "$config_script"
|
|
|
|
echo "fi" >> "$config_script"
|
|
|
|
echo "if test -z \"\''${_''${outhash}_NIX_LISP_PATH_CONFIG}\"; then export _''${outhash}_NIX_LISP_PATH_CONFIG=1; " >> "$path_config_script"
|
2017-11-22 06:55:06 +00:00
|
|
|
echo "export NIX_LISP_ASDF_PATHS=\"$( ( echo "\$NIX_LISP_ASDF_PATHS"; echo "$NIX_LISP_ASDF_PATHS"; echo "$out/lib/common-lisp/${args.baseName}" ) | grep . | sort | uniq)\"" >> "$path_config_script"
|
2013-10-29 07:29:46 +00:00
|
|
|
test -n "$LD_LIBRARY_PATH" &&
|
2017-04-06 17:43:42 +01:00
|
|
|
echo "export LD_LIBRARY_PATH=\"\$LD_LIBRARY_PATH\''${LD_LIBRARY_PATH:+:}\"'$LD_LIBRARY_PATH'" >> "$path_config_script"
|
2013-10-29 07:29:46 +00:00
|
|
|
test -n "$NIX_LISP_LD_LIBRARY_PATH" &&
|
2018-02-25 10:53:51 +00:00
|
|
|
echo "export NIX_LISP_LD_LIBRARY_PATH=\"\$NIX_LISP_LD_LIBRARY_PATH\''${NIX_LISP_LD_LIBRARY_PATH:+:}\"'$(echo "$NIX_LISP_LD_LIBRARY_PATH" | tr -d '\n' | tr : '\n' | sort | uniq | tr '\n' ':' | sed -e 's/:$//')'" >> "$path_config_script"
|
2017-04-06 17:43:42 +01:00
|
|
|
echo "fi" >> "$path_config_script"
|
2013-10-13 07:57:30 +01:00
|
|
|
'';
|
|
|
|
deployLaunchScript = ''
|
|
|
|
launch_script="$out"/bin/${args.baseName}-lisp-launcher.sh
|
|
|
|
mkdir -p "$(dirname "$launch_script")"
|
|
|
|
touch "$launch_script"
|
|
|
|
chmod a+x "$launch_script"
|
2019-01-15 22:41:31 +00:00
|
|
|
echo "#! ${stdenv.shell}" >> "$launch_script"
|
2013-10-13 07:57:30 +01:00
|
|
|
echo "source '$config_script'" >> "$launch_script"
|
2018-02-25 10:53:51 +00:00
|
|
|
echo "test -n \"\$NIX_LISP_LD_LIBRARY_PATH\" export LD_LIBRARY_PATH=\"\$NIX_LISP_LD_LIBRARY_PATH\''${LD_LIBRARY_PATH:+:}\$LD_LIBRARY_PATH\"" >> "$launch_script"
|
2017-04-10 00:10:39 +01:00
|
|
|
echo '"${clwrapper}/bin/common-lisp.sh" "$@"' >> "$launch_script"
|
2013-10-13 07:57:30 +01:00
|
|
|
'';
|
2017-08-01 03:29:53 +01:00
|
|
|
moveAsdFiles = ''
|
|
|
|
find $out/lib/common-lisp/ -name '*.asd' | while read ASD_FILE; do
|
|
|
|
KEEP_THIS_ASD=0
|
|
|
|
for ALLOWED_ASD in $asdFilesToKeep; do
|
|
|
|
ALLOWED_ASD="/$ALLOWED_ASD"
|
|
|
|
ALLOWED_ASD_LENGTH=${"$"}{#ALLOWED_ASD}
|
|
|
|
ASD_FILE_LENGTH=${"$"}{#ASD_FILE}
|
|
|
|
ASD_FILE_SUFFIX_INDEX=$(expr "$ASD_FILE_LENGTH" - "$ALLOWED_ASD_LENGTH")
|
|
|
|
ASD_FILE_SUFFIX_INDEX=$(expr "$ASD_FILE_SUFFIX_INDEX" + 1)
|
|
|
|
echo $ALLOWED_ASD $ASD_FILE $ASD_FILE_SUFFIX_INDEX $(expr substr "$ASD_FILE" "$ASD_FILE_SUFFIX_INDEX" "$ASD_FILE_LENGTH")
|
|
|
|
if [ "$(expr substr "$ASD_FILE" "$ASD_FILE_SUFFIX_INDEX" "$ASD_FILE_LENGTH")" == "$ALLOWED_ASD" ]; then
|
|
|
|
KEEP_THIS_ASD=1
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ "$KEEP_THIS_ASD" == 0 ]; then
|
|
|
|
mv "$ASD_FILE"{,.sibling}
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
'';
|
2013-10-13 07:57:30 +01:00
|
|
|
basePackage = {
|
|
|
|
name = "lisp-${baseName}-${version}";
|
|
|
|
inherit src;
|
|
|
|
|
2017-08-01 03:29:53 +01:00
|
|
|
dontBuild = true;
|
|
|
|
|
2013-10-13 07:57:30 +01:00
|
|
|
inherit deployConfigScript deployLaunchScript;
|
2017-08-01 03:29:53 +01:00
|
|
|
inherit asdFilesToKeep moveAsdFiles;
|
2013-10-13 07:57:30 +01:00
|
|
|
installPhase = ''
|
2014-11-16 16:08:00 +00:00
|
|
|
eval "$preInstall"
|
|
|
|
|
2013-10-13 07:57:30 +01:00
|
|
|
mkdir -p "$out"/share/doc/${args.baseName};
|
|
|
|
mkdir -p "$out"/lib/common-lisp/${args.baseName};
|
|
|
|
cp -r . "$out"/lib/common-lisp/${args.baseName};
|
|
|
|
cp -rf doc/* LICENCE LICENSE COPYING README README.html README.md readme.html "$out"/share/doc/${args.baseName} || true
|
|
|
|
|
|
|
|
${deployConfigScript}
|
|
|
|
${deployLaunchScript}
|
2017-08-01 03:29:53 +01:00
|
|
|
${moveAsdFiles}
|
2014-11-16 16:08:00 +00:00
|
|
|
|
2017-08-01 03:29:53 +01:00
|
|
|
env -i \
|
|
|
|
NIX_LISP="$NIX_LISP" \
|
|
|
|
NIX_LISP_PRELAUNCH_HOOK='nix_lisp_run_single_form "(progn
|
|
|
|
${stdenv.lib.concatMapStrings (system: ''
|
|
|
|
(asdf:compile-system :${system})
|
|
|
|
(asdf:load-system :${system})
|
|
|
|
(asdf:operate (quote asdf::compile-bundle-op) :${system})
|
|
|
|
(ignore-errors (asdf:operate (quote asdf::deploy-asd-op) :${system}))
|
|
|
|
'') buildSystems}
|
|
|
|
)"' \
|
|
|
|
"$out/bin/${args.baseName}-lisp-launcher.sh"
|
2017-03-31 21:46:32 +01:00
|
|
|
|
2014-11-16 16:08:00 +00:00
|
|
|
eval "$postInstall"
|
2013-10-13 07:57:30 +01:00
|
|
|
'';
|
2017-04-10 00:10:39 +01:00
|
|
|
propagatedBuildInputs = (args.deps or []) ++ [clwrapper clwrapper.lisp clwrapper.asdf]
|
2014-11-13 08:17:17 +00:00
|
|
|
++ (args.propagatedBuildInputs or []);
|
2013-10-13 07:57:30 +01:00
|
|
|
buildInputs = buildInputs;
|
|
|
|
dontStrip=true;
|
2017-03-30 11:15:08 +01:00
|
|
|
|
2017-04-06 17:43:42 +01:00
|
|
|
ASDF_OUTPUT_TRANSLATIONS="${builtins.storeDir}/:${builtins.storeDir}";
|
|
|
|
|
2013-10-13 07:57:30 +01:00
|
|
|
meta = {
|
|
|
|
inherit description version;
|
|
|
|
} // meta;
|
|
|
|
};
|
|
|
|
package = basePackage // (overrides basePackage);
|
|
|
|
in
|
|
|
|
stdenv.mkDerivation package
|