on master help sign in
nix-bundle/appimage-bundle.nix
61 lines 1.8 kB history raw
1# use like this:
2# nix-build appimage-bundle.nix --argstr package hello --argstr exec hello
3# nix-build appimage-bundle.nix --arg package 'with import <nixpkgs>{}; writers.writePython3Bin "helloThere.py" {} "print(1)\n"' --argstr exec helloThere.py
6{nixpkgs ? import <nixpkgs>{},
7package,
8exec,
9... }:
10let
11 appimage_src = drv : exec : with nixpkgs;
12 self.stdenv.mkDerivation rec {
13 name = drv.name + "-appdir";
14 env = buildEnv {
15 inherit name;
16 paths = buildInputs;
17 };
18 src = env;
19 inherit exec;
20 buildInputs = [ drv ];
21 buildCommand = ''
22 mkdir -p $out/share/icons/hicolor/256x256/apps
23 mkdir -p $out/share/applications
25 shopt -s extglob
26 ln -s ${env}/!(share) $out/
27 ln -s ${env}/share/* $out/share/
29 touch $out/share/icons/hicolor/256x256/apps/${drv.name}.png
30 touch $out/share/icons/${drv.name}.png
32 cat <<EOF > $out/share/applications/${drv.name}.desktop
33 [Desktop Entry]
34 Type=Application
35 Version=1.0
36 Name=${drv.name}
37 Path=${env}
38 Icon=${drv.name}
39 Exec=$exec
40 Terminal=true
41 EOF
42 '';
43 system = builtins.currentSystem;
44 };
46in
47 let results =
48 if (nixpkgs.lib.isDerivation package && !(nixpkgs.lib.isString package))
49 then {
50 name = package.name;
51 target = appimage_src package "${exec}";
52 extraTargets = [];
53 }
54 else {
55 name = nixpkgs."${package}".name;
56 target = appimage_src (nixpkgs."${package}") "${exec}";
57 extraTargets = [];
58 };
59 in
60 with (import (./appimage-top.nix){nixpkgs' = nixpkgs.path;});
61 (appimage (appdir results )).overrideAttrs (old: {name = results.name;})