on master help sign in
Add nix2appimage.sh script.
43f0f04Matthew Bauer
appdir.nixnew file+55
@@ -0,0 +1,55 @@
1+{ stdenv, fetchurl, perl, pathsFromGraph }:
2+
3+let
4+ AppRun = fetchurl {
5+ url = "https://github.com/probonopd/AppImageKit/releases/download/6/AppRun_6-x86_64";
6+ sha256 = "1i0hr4ag6jz3h27c80ir2rswq91khw0cq9fqylg23l6pmjgwbf98";
7+ };
8+
9+in
10+
11+ { target, name }: stdenv.mkDerivation {
12+ name = "${name}.AppDir";
13+ exportReferencesGraph = map (x: [("closure-" + baseNameOf x) x]) [ target ];
14+ nativeBuildInputs = [ perl ];
15+ buildCommand = ''
16+ # TODO use symlinks to shrink output size
17+
18+ if [ ! -d ${target}/share/applications ]; then
19+ echo "--------------------------------------------------"
20+ echo "| /share/applications does not exist. |"
21+ echo "| AppImage only works with 'applications'. |"
22+ echo "| Try using nix-bundle.sh for command-line apps. |"
23+ echo "--------------------------------------------------"
24+ exit 1
25+ fi
26+
27+ storePaths=$(${perl}/bin/perl ${pathsFromGraph} ./closure-*)
28+ mkdir -p $out/nix/store
29+ cp -r $storePaths $out/nix/store
30+
31+ cd $out
32+
33+ ln -s .${target} $out/usr
34+
35+ # .desktop
36+ if [ -d ${target}/share/applications ]; then
37+ desktop=$(find ${target}/share/applications -name "*.desktop" | head -n1)
38+ if ! [ -z "$desktop" ]; then
39+ ln -s .$desktop $out
40+ fi
41+ fi
42+
43+ # icons
44+ if [ -d ${target}/share/icons ]; then
45+ icon=$(find ${target}/share/icons -name "${name}.png" | head -n1)
46+ if ! [ -z "$icon" ]; then
47+ ln -s .$icon $out
48+ ln -s .$icon .DirIcon
49+ fi
50+ fi
51+
52+ cp ${AppRun} AppRun
53+ chmod a+x AppRun
54+ '';
55+ }
appimage.nixnew file+10
@@ -0,0 +1,10 @@
1+{ stdenv, appimagetool }:
2+dir:
3+
4+stdenv.mkDerivation {
5+ name = "appimage.AppImage";
6+ buildInputs = [ appimagetool ];
7+ buildCommand = ''
8+ appimagetool ${dir} $out
9+ '';
10+}
appimagetool.nixnew file+29
@@ -0,0 +1,29 @@
1+{ stdenv, fetchurl }:
2+
3+# This is from some binaries.
4+
5+# Ideally, this should be source based,
6+# but I can't get it to build from GitHub
7+
8+stdenv.mkDerivation rec {
9+ name = "appimagekit";
10+
11+ src = fetchurl {
12+ url = "https://github.com/probonopd/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage";
13+ sha256 = "0l3hxp169dpyj3h38q9nsnh1cynam1j5zx8q362p93448rhm7d0y";
14+ };
15+
16+ sourceRoot = "squashfs-root";
17+
18+ unpackPhase = ''
19+ chmod a+x $src
20+ $src --appimage-extract
21+ '';
22+
23+ installPhase = ''
24+ mkdir -p $out
25+ cp -r usr/* $out
26+ '';
27+
28+ dontPatchELF = true;
29+}
default.nix+7
@@ -22,4 +22,11 @@ rec {
22 inherit nix-user-chroot makebootstrap;
22 inherit nix-user-chroot makebootstrap;
23 };
23 };
24
24
25+ appimagetool = callPackage ./appimagetool.nix {};
26+
27+ appimage = callPackage ./appimage.nix {
28+ inherit appimagetool;
29+ };
30+
31+ appdir = callPackage ./appdir.nix {};
25}
32}
nix2appimage.shnew file+26
@@ -0,0 +1,26 @@
1+#!/usr/bin/env sh
2+
3+if [ "$#" -lt 1 ]; then
4+ cat <<EOF
5+
6+Usage: $0 TARGET
7+
8+Create a single-file bundle from the nixpkgs attribute "TARGET".
9+
10+For example:
11+
12+$ $0 emacs
13+$ ./emacs
14+
15+EOF
16+
17+ exit 1
18+fi
19+
20+target="$1"
21+
22+expr="with import <nixpkgs> {}; with import ./. {}; appimage (appdir { name = \"$target\"; target = $target; })"
23+
24+out=$(nix-store --no-gc-warning -r $(nix-instantiate --no-gc-warning -E "$expr"))
25+
26+cp -f $out $target