on master help sign in
nix-bundle/appdir.nix
81 lines 2.4 kB history raw
1{ stdenv, lib, fetchurl, muslPkgs, perl, pathsFromGraph, fetchFromGitHub, coreutils, bash }:
3let
4 AppRun = targets: muslPkgs.stdenv.mkDerivation {
5 name = "AppRun";
7 phases = [ "buildPhase" "installPhase" "fixupPhase" ];
9 buildPhase = ''
10 CC="$CC -O2 -Wall -Wno-deprecated-declarations -Wno-unused-result -static"
11 $CC ${./AppRun.c} -o AppRun -DENV_PATH='"${lib.makeBinPath targets}"'
12 '';
14 installPhase = ''
15 mkdir -p $out/bin
16 cp AppRun $out/bin/AppRun
17 '';
18 };
20in
22 { target, name, extraTargets ? [ coreutils bash ] }: let targets = ([ target ] ++ extraTargets);
23 in stdenv.mkDerivation {
24 name = "${name}.AppDir";
25 exportReferencesGraph = map (x: [("closure-" + baseNameOf x) x]) targets;
26 nativeBuildInputs = [ perl ];
27 buildCommand = ''
28 # TODO use symlinks to shrink output size
30 if [ ! -d ${target}/share/applications ]; then
31 echo "--------------------------------------------------"
32 echo "| /share/applications does not exist. |"
33 echo "| AppImage only works with 'applications'. |"
34 echo "| Try using nix-bundle.sh for command-line apps. |"
35 echo "--------------------------------------------------"
36 exit 1
37 fi
39 storePaths=$(${perl}/bin/perl ${pathsFromGraph} ./closure-*)
41 mkdir -p $out/${name}.AppDir
42 cd $out/${name}.AppDir
44 mkdir -p nix/store
45 cp -r $storePaths nix/store
47 ln -s .${target} usr
49 if [ -d ${target}/share/appdata ]; then
50 chmod a+w usr/share
51 mkdir -p usr/share/metainfo
52 for f in ${target}/share/appdata/*.xml; do
53 ln -s ../appdata/$(basename $f) usr/share/metainfo/$(basename $f)
54 done
55 fi
57 # .desktop
58 desktop=$(find ${target}/share/applications -name "*.desktop" | head -n1)
59 if ! [ -z "$desktop" ]; then
60 cp .$desktop .
61 fi
64 # icons
65 if [ -d ${target}/share/icons ]; then
66 icon=$(find ${target}/share/icons -name "${name}*.png" | head -n1)
67 if ! [ -z "$icon" ]; then
68 ln -s .$icon
69 ln -s .$icon .DirIcon
70 else
71 icon=$(find ${target}/share/icons -name "${name}*.svg" | head -n1)
72 if ! [ -z "$icon" ]; then
73 ln -s .$icon
74 ln -s .$icon .DirIcon
75 fi
76 fi
77 fi
79 cp ${AppRun targets}/bin/AppRun AppRun
80 '';
81 }