@@ -0,0 +1,55 @@
1+{ stdenv, fetchurl, perl, pathsFromGraph }:
2+
3+let
4+ AppRun = fetchurl {
5+ url = "https://github.com/probonopd/AppImageKit/releases/download/6/AppRun_6-x86_64";
6+ sha256 = "1i0hr4ag6jz3h27c80ir2rswq91khw0cq9fqylg23l6pmjgwbf98";
7+ };
8+
9+in
10+
11+ { target, name }: stdenv.mkDerivation {
12+ name = "${name}.AppDir";
13+ exportReferencesGraph = map (x: [("closure-" + baseNameOf x) x]) [ target ];
14+ nativeBuildInputs = [ perl ];
15+ buildCommand = ''
16+ # TODO use symlinks to shrink output size
17+
18+ if [ ! -d ${target}/share/applications ]; then
19+ echo "--------------------------------------------------"
20+ echo "| /share/applications does not exist. |"
21+ echo "| AppImage only works with 'applications'. |"
22+ echo "| Try using nix-bundle.sh for command-line apps. |"
23+ echo "--------------------------------------------------"
24+ exit 1
25+ fi
26+
27+ storePaths=$(${perl}/bin/perl ${pathsFromGraph} ./closure-*)
28+ mkdir -p $out/nix/store
29+ cp -r $storePaths $out/nix/store
30+
31+ cd $out
32+
33+ ln -s .${target} $out/usr
34+
35+ # .desktop
36+ if [ -d ${target}/share/applications ]; then
37+ desktop=$(find ${target}/share/applications -name "*.desktop" | head -n1)
38+ if ! [ -z "$desktop" ]; then
39+ ln -s .$desktop $out
40+ fi
41+ fi
42+
43+ # icons
44+ if [ -d ${target}/share/icons ]; then
45+ icon=$(find ${target}/share/icons -name "${name}.png" | head -n1)
46+ if ! [ -z "$icon" ]; then
47+ ln -s .$icon $out
48+ ln -s .$icon .DirIcon
49+ fi
50+ fi
51+
52+ cp ${AppRun} AppRun
53+ chmod a+x AppRun
54+ '';
55+ }