-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkAppImage.nix
67 lines (57 loc) · 2.07 KB
/
mkAppImage.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
{ lib
, runCommand
, squashfsTools
, writeClosure
, writeTextFile
# mkappimage-specific, passed from flake.nix
, mkappimage-runtime # runtimes are an executable that mount the squashfs part of the appimage and start AppRun
, mkappimage-apprun # appruns contain an AppRun executable that does setup and launches entrypoint
}:
# actual arguments
{ program # absolute path of executable to start
# output name
, pname ? (lib.last (builtins.split "/" program))
, name ? "${pname}.AppImage"
# advanced appimage configuration
, squashfsArgs ? [ ] # additional arguments to pass to mksquashfs
}:
let
commonArgs = [
"-offset $(stat -L -c%s ${lib.escapeShellArg mkappimage-runtime})" # squashfs comes after the runtime
"-all-root" #chown to root, same as -root-owned
"-b 1M" #set block size to 1MB
"-no-xattrs" #Don't store Extended Attributes
"-Xcompression-level 1" #We repack it later anyway, default is 9
] ++ squashfsArgs;
in
runCommand name
{
nativeBuildInputs = [ squashfsTools ];
} ''
if ! test -x ${program}; then
echo "Entrypoint '${program}' is NOT Executable (Or It wasn't found)"
echo "Maybe it is a multi-call Program?"
fi
mksquashfs ${builtins.concatStringsSep " " ([
# first run of mksquashfs copies the nix/store closure and additional files
"$(cat ${writeClosure [ program ]})"
"$out"
# additional files
(lib.concatMapStrings (x: " -p ${lib.escapeShellArg x}") [
# symlink entrypoint to the executable to run
"entrypoint s 555 0 0 ${program}"
])
"-no-strip" # don't strip leading dirs, to preserve the fact that everything's in the nix store
] ++ commonArgs)}
mksquashfs ${builtins.concatStringsSep " " ([
# second run of mksquashfs adds the apprun
# no -no-strip since we *do* want to strip leading dirs now
"${mkappimage-apprun}"
"$out"
"-no-recovery" #Don't generate recovery files, prevents "No such file or directory"
] ++ commonArgs)}
# add the runtime to the start
dd if=${lib.escapeShellArg mkappimage-runtime} of=$out conv=notrunc
# make executable
chmod 755 $out
''