Add nix2appimage.sh script.

This commit is contained in:
Matthew Bauer 2017-02-06 16:17:20 -06:00
parent b2496b5f03
commit 43f0f0401f
5 changed files with 127 additions and 0 deletions

55
appdir.nix Normal file
View File

@ -0,0 +1,55 @@
{ stdenv, fetchurl, perl, pathsFromGraph }:
let
AppRun = fetchurl {
url = "https://github.com/probonopd/AppImageKit/releases/download/6/AppRun_6-x86_64";
sha256 = "1i0hr4ag6jz3h27c80ir2rswq91khw0cq9fqylg23l6pmjgwbf98";
};
in
{ target, name }: stdenv.mkDerivation {
name = "${name}.AppDir";
exportReferencesGraph = map (x: [("closure-" + baseNameOf x) x]) [ target ];
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/nix/store
cp -r $storePaths $out/nix/store
cd $out
ln -s .${target} $out/usr
# .desktop
if [ -d ${target}/share/applications ]; then
desktop=$(find ${target}/share/applications -name "*.desktop" | head -n1)
if ! [ -z "$desktop" ]; then
ln -s .$desktop $out
fi
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 $out
ln -s .$icon .DirIcon
fi
fi
cp ${AppRun} AppRun
chmod a+x AppRun
'';
}

10
appimage.nix Normal file
View File

@ -0,0 +1,10 @@
{ stdenv, appimagetool }:
dir:
stdenv.mkDerivation {
name = "appimage.AppImage";
buildInputs = [ appimagetool ];
buildCommand = ''
appimagetool ${dir} $out
'';
}

29
appimagetool.nix Normal file
View File

@ -0,0 +1,29 @@
{ stdenv, fetchurl }:
# This is from some binaries.
# Ideally, this should be source based,
# but I can't get it to build from GitHub
stdenv.mkDerivation rec {
name = "appimagekit";
src = fetchurl {
url = "https://github.com/probonopd/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage";
sha256 = "0l3hxp169dpyj3h38q9nsnh1cynam1j5zx8q362p93448rhm7d0y";
};
sourceRoot = "squashfs-root";
unpackPhase = ''
chmod a+x $src
$src --appimage-extract
'';
installPhase = ''
mkdir -p $out
cp -r usr/* $out
'';
dontPatchELF = true;
}

View File

@ -22,4 +22,11 @@ rec {
inherit nix-user-chroot makebootstrap;
};
appimagetool = callPackage ./appimagetool.nix {};
appimage = callPackage ./appimage.nix {
inherit appimagetool;
};
appdir = callPackage ./appdir.nix {};
}

26
nix2appimage.sh Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env sh
if [ "$#" -lt 1 ]; then
cat <<EOF
Usage: $0 TARGET
Create a single-file bundle from the nixpkgs attribute "TARGET".
For example:
$ $0 emacs
$ ./emacs
EOF
exit 1
fi
target="$1"
expr="with import <nixpkgs> {}; with import ./. {}; appimage (appdir { name = \"$target\"; target = $target; })"
out=$(nix-store --no-gc-warning -r $(nix-instantiate --no-gc-warning -E "$expr"))
cp -f $out $target