Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AppRun.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static void add_path(const char* name, const char* rootdir) {
}

#define SAVE_ENV_VAR(x) char *x = getenv(#x)
#define LOAD_ENV_VAR(x) setenv(#x, x, 1)
#define LOAD_ENV_VAR(x) do { if (x != NULL) setenv(#x, x, 1); } while(0)

int main(int argc, char *argv[]) {
char *appdir = dirname(realpath("/proc/self/exe", NULL));
Expand Down
6 changes: 3 additions & 3 deletions appdir.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{ stdenv, fetchurl, perl, pathsFromGraph, fetchFromGitHub, musl, coreutils, bash }:
{ stdenv, fetchurl, muslPkgs, perl, pathsFromGraph, fetchFromGitHub, coreutils, bash }:

let
AppRun = targets: stdenv.mkDerivation {
AppRun = targets: muslPkgs.stdenv.mkDerivation {
name = "AppRun";

phases = [ "buildPhase" "installPhase" "fixupPhase" ];

buildPhase = ''
CC="${musl}/bin/musl-gcc -O2 -Wall -Wno-deprecated-declarations -Wno-unused-result -static"
CC="$CC -O2 -Wall -Wno-deprecated-declarations -Wno-unused-result -static"
$CC ${./AppRun.c} -o AppRun -DENV_PATH='"${stdenv.lib.makeBinPath targets}"'
'';

Expand Down
16 changes: 10 additions & 6 deletions appimage-top.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{nixpkgs ? import <nixpkgs> {}}:
{ nixpkgs' ? <nixpkgs> }:

with nixpkgs;
let
pkgs = import nixpkgs' { };
muslPkgs = import nixpkgs' {
localSystem.config = "x86_64-unknown-linux-musl";
};

rec {
appimagetool = callPackage ./appimagetool.nix {};
in rec {
appimagetool = pkgs.callPackage ./appimagetool.nix {};

appimage = callPackage ./appimage.nix {
appimage = pkgs.callPackage ./appimage.nix {
inherit appimagetool;
};

appdir = callPackage ./appdir.nix {};
appdir = pkgs.callPackage ./appdir.nix { inherit muslPkgs; };
}
22 changes: 12 additions & 10 deletions appimagetool.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
# Ideally, this should be source based,
# but I can't get it to build from GitHub

stdenv.mkDerivation rec {
let
inherit (stdenv.cc.bintools) dynamicLinker;
in stdenv.mkDerivation rec {
name = "appimagekit";

src = fetchurl {
url = "https://github.com/probonopd/AppImageKit/releases/download/7/appimagetool-x86_64.AppImage";
sha256 = "1irvbf0xnya16cyzpvr43jviq5ly3wl7b9753rji7d1hhxwb7b9r";
url = "https://github.com/AppImage/AppImageKit/releases/download/10/appimagetool-x86_64.AppImage";
sha256 = "03zbiblj8a1yk1xsb5snxi4ckwn3diyldg1jh5hdjjhsmpw652ig";
};

buildInputs = [
Expand All @@ -22,7 +24,7 @@ stdenv.mkDerivation rec {
unpackPhase = ''
cp $src appimagetool-x86_64.AppImage
chmod u+wx appimagetool-x86_64.AppImage
patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
patchelf --set-interpreter ${dynamicLinker} \
--set-rpath ${fuse}/lib:${zlib}/lib \
appimagetool-x86_64.AppImage
./appimagetool-x86_64.AppImage --appimage-extract
Expand All @@ -32,12 +34,12 @@ stdenv.mkDerivation rec {
mkdir -p $out
cp -r usr/* $out

patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
--set-rpath ${stdenv.glibc.out}/lib:${fuse}/lib:${zlib}/lib:${glib}/lib \
$out/bin/appimagetool
patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
--set-rpath ${zlib}/lib \
$out/bin/mksquashfs
for x in $out/bin/*; do
patchelf \
--set-interpreter ${dynamicLinker} \
--set-rpath ${stdenv.lib.makeLibraryPath [ zlib stdenv.glibc.out fuse glib ]} \
$x
done
'';

dontStrip = true;
Expand Down
14 changes: 14 additions & 0 deletions test-appimage.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{ appimagefile, nixpkgs' ? <nixpkgs> }:

# nix build -f test-appimage.nix --arg appimagefile ./VLC*AppImage

with import nixpkgs' {};

runCommand "patchelf" {} ''
cp ${appimagefile} $out
chmod +w $out
patchelf \
--set-interpreter ${stdenv.cc.bintools.dynamicLinker} \
--set-rpath ${stdenv.glibc.out}/lib:${fuse}/lib:${zlib}/lib:${glib}/lib \
$out
''