nix-bundle/appdir.nix

80 lines
2.2 KiB
Nix
Raw Normal View History

2017-05-01 02:50:30 +03:00
{ stdenv, fetchurl, perl, pathsFromGraph, fetchFromGitHub, musl }:
2017-02-07 01:17:20 +03:00
let
2017-05-01 02:50:30 +03:00
AppRun = stdenv.mkDerivation {
name = "AppRun";
phases = [ "buildPhase" "installPhase" "fixupPhase" ];
buildPhase = ''
CC="${musl}/bin/musl-gcc -O2 -Wall -Wno-deprecated-declarations -Wno-unused-result -static"
$CC ${./AppRun.c} -o AppRun
'';
installPhase = ''
mkdir -p $out/bin
cp AppRun $out/bin/AppRun
'';
2017-02-07 01:17:20 +03:00
};
in
{ target, name }: stdenv.mkDerivation {
name = "${name}.AppDir";
exportReferencesGraph = map (x: [("closure-" + baseNameOf x) x]) [ target ];
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
cp -r $storePaths nix/store
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
ln -s .$f usr/share/metainfo
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
ln -s .$desktop
2017-02-07 01:17:20 +03:00
fi
# icons
if [ -d ${target}/share/icons ]; then
2017-02-07 03:21:01 +03:00
icon=$(find ${target}/share/icons -name "${name}.png" -or -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
icon=$(find ${target}/share/icons -name "${name}.svg" -or -name "*.svg" | head -n1)
if ! [ -z "$icon" ]; then
ln -s .$icon
ln -s .$icon .DirIcon
fi
2017-02-07 01:17:20 +03:00
fi
fi
2017-05-01 02:50:30 +03:00
cp ${AppRun}/bin/AppRun AppRun
2017-02-07 01:17:20 +03:00
'';
}