-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
appdir.nix
81 lines (65 loc) · 2.35 KB
/
appdir.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
{ stdenv, lib, fetchurl, muslPkgs, perl, pathsFromGraph, fetchFromGitHub, coreutils, bash }:
let
AppRun = targets: muslPkgs.stdenv.mkDerivation {
name = "AppRun";
phases = [ "buildPhase" "installPhase" "fixupPhase" ];
buildPhase = ''
CC="$CC -O2 -Wall -Wno-deprecated-declarations -Wno-unused-result -static"
$CC ${./AppRun.c} -o AppRun -DENV_PATH='"${lib.makeBinPath targets}"'
'';
installPhase = ''
mkdir -p $out/bin
cp AppRun $out/bin/AppRun
'';
};
in
{ target, name, extraTargets ? [ coreutils bash ] }: let targets = ([ target ] ++ extraTargets);
in stdenv.mkDerivation {
name = "${name}.AppDir";
exportReferencesGraph = map (x: [("closure-" + baseNameOf x) x]) targets;
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-*)
mkdir -p $out/${name}.AppDir
cd $out/${name}.AppDir
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 ../appdata/$(basename $f) usr/share/metainfo/$(basename $f)
done
fi
# .desktop
desktop=$(find ${target}/share/applications -name "*.desktop" | head -n1)
if ! [ -z "$desktop" ]; then
cp .$desktop .
fi
# icons
if [ -d ${target}/share/icons ]; then
icon=$(find ${target}/share/icons -name "${name}*.png" | head -n1)
if ! [ -z "$icon" ]; then
ln -s .$icon
ln -s .$icon .DirIcon
else
icon=$(find ${target}/share/icons -name "${name}*.svg" | head -n1)
if ! [ -z "$icon" ]; then
ln -s .$icon
ln -s .$icon .DirIcon
fi
fi
fi
cp ${AppRun targets}/bin/AppRun AppRun
'';
}