2018-02-26 21:39:40 +03:00
|
|
|
{ stdenv, fetchurl, muslPkgs, perl, pathsFromGraph, fetchFromGitHub, coreutils, bash }:
|
2017-02-07 01:17:20 +03:00
|
|
|
|
|
|
|
let
|
2018-02-26 21:39:40 +03:00
|
|
|
AppRun = targets: muslPkgs.stdenv.mkDerivation {
|
2017-05-01 02:50:30 +03:00
|
|
|
name = "AppRun";
|
|
|
|
|
|
|
|
phases = [ "buildPhase" "installPhase" "fixupPhase" ];
|
|
|
|
|
|
|
|
buildPhase = ''
|
2018-02-26 21:39:40 +03:00
|
|
|
CC="$CC -O2 -Wall -Wno-deprecated-declarations -Wno-unused-result -static"
|
2017-05-08 08:03:19 +03:00
|
|
|
$CC ${./AppRun.c} -o AppRun -DENV_PATH='"${stdenv.lib.makeBinPath targets}"'
|
2017-05-01 02:50:30 +03:00
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
cp AppRun $out/bin/AppRun
|
|
|
|
'';
|
2017-02-07 01:17:20 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
|
2017-05-08 08:03:19 +03:00
|
|
|
{ target, name, extraTargets ? [ coreutils bash ] }: let targets = ([ target ] ++ extraTargets);
|
|
|
|
in stdenv.mkDerivation {
|
2017-02-07 01:17:20 +03:00
|
|
|
name = "${name}.AppDir";
|
2017-05-08 08:03:19 +03:00
|
|
|
exportReferencesGraph = map (x: [("closure-" + baseNameOf x) x]) targets;
|
2017-02-07 01:17:20 +03:00
|
|
|
nativeBuildInputs = [ perl ];
|
|
|
|
buildCommand = ''
|
|
|
|
# TODO use symlinks to shrink output size
|
|
|
|
|
|
|
|
if [ ! -d ${target}/share/applications ]; then
|
|
|
|
echo "--------------------------------------------------"
|
|
|
|
echo "| /share/applications does not exist. |"
|
|
|
|
echo "| AppImage only works with 'applications'. |"
|
|
|
|
echo "| Try using nix-bundle.sh for command-line apps. |"
|
|
|
|
echo "--------------------------------------------------"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
storePaths=$(${perl}/bin/perl ${pathsFromGraph} ./closure-*)
|
|
|
|
|
2017-02-07 03:21:01 +03:00
|
|
|
mkdir -p $out/${name}.AppDir
|
|
|
|
cd $out/${name}.AppDir
|
2017-02-07 01:17:20 +03:00
|
|
|
|
2017-02-07 03:21:01 +03:00
|
|
|
mkdir -p nix/store
|
2019-06-24 06:21:08 +03:00
|
|
|
cp -Lr $storePaths nix/store
|
2017-02-07 03:21:01 +03:00
|
|
|
|
|
|
|
ln -s .${target} usr
|
|
|
|
|
|
|
|
if [ -d ${target}/share/appdata ]; then
|
|
|
|
chmod a+w usr/share
|
|
|
|
mkdir -p usr/share/metainfo
|
|
|
|
for f in ${target}/share/appdata/*.xml; do
|
2017-05-01 02:55:56 +03:00
|
|
|
ln -s ../appdata/$(basename $f) usr/share/metainfo/$(basename $f)
|
2017-02-07 03:21:01 +03:00
|
|
|
done
|
|
|
|
fi
|
2017-02-07 01:17:20 +03:00
|
|
|
|
|
|
|
# .desktop
|
2017-02-07 03:21:01 +03:00
|
|
|
desktop=$(find ${target}/share/applications -name "*.desktop" | head -n1)
|
|
|
|
if ! [ -z "$desktop" ]; then
|
2017-05-08 08:02:33 +03:00
|
|
|
cp .$desktop .
|
2017-02-07 01:17:20 +03:00
|
|
|
fi
|
|
|
|
|
2017-05-08 08:02:33 +03:00
|
|
|
|
2017-02-07 01:17:20 +03:00
|
|
|
# icons
|
|
|
|
if [ -d ${target}/share/icons ]; then
|
2019-06-24 06:21:08 +03:00
|
|
|
icon=$(find ${target}/share/icons -name "${name}*.png" | head -n1)
|
2017-02-07 01:17:20 +03:00
|
|
|
if ! [ -z "$icon" ]; then
|
2017-02-07 03:21:01 +03:00
|
|
|
ln -s .$icon
|
2017-02-07 01:17:20 +03:00
|
|
|
ln -s .$icon .DirIcon
|
2017-02-07 03:21:01 +03:00
|
|
|
else
|
2019-06-24 06:21:08 +03:00
|
|
|
icon=$(find ${target}/share/icons -name "${name}*.svg" | head -n1)
|
2017-02-07 03:21:01 +03:00
|
|
|
if ! [ -z "$icon" ]; then
|
|
|
|
ln -s .$icon
|
|
|
|
ln -s .$icon .DirIcon
|
|
|
|
fi
|
2017-02-07 01:17:20 +03:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2017-05-08 08:03:19 +03:00
|
|
|
cp ${AppRun targets}/bin/AppRun AppRun
|
2017-02-07 01:17:20 +03:00
|
|
|
'';
|
|
|
|
}
|