-
-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathappdir.nix
More file actions
111 lines (95 loc) · 2.38 KB
/
appdir.nix
File metadata and controls
111 lines (95 loc) · 2.38 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
{
stdenv,
lib,
fetchurl,
muslPkgs,
perl,
closureInfo,
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);
closure = closureInfo { rootPaths = targets; };
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=$(cat ${closure}/store-paths)
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
'';
}