Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: init appimage #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
51 changes: 51 additions & 0 deletions appimage.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{nixpkgsFor,lib,nixpkgs,nix-bundle,program,system ? "x86_64-linux"}:
drv: with nixpkgsFor.${system}; let
closure = closureInfo {rootPaths = [drv];};
prog = program drv;
system = drv.system;
nixpkgs' = nixpkgs.legacyPackages.${system};
muslPkgs = import nixpkgs {
localSystem.config = "x86_64-unknown-linux-musl";
};
pkgs = nixpkgs.legacyPackages.${system};
appdir = pkgs.callPackage (nix-bundle + "/appdir.nix") { inherit muslPkgs; };

env = appdir {
name = "hello";
target =
buildEnv {
name = "hello";
paths = [drv (
runCommand "appdir" {buildInputs = [imagemagick];} ''

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
runCommand "appdir" {buildInputs = [imagemagick];} ''
runCommand "appdir" {nativeBuildInputs = [imagemagick];} ''

mkdir -p $out/share/applications
mkdir -p $out/share/icons/hicolor/256x256/apps
convert -size 256x256 xc:#990000 ${nixpkgs.lib.attrByPath ["meta" "icon"] "$out/share/icons/hicolor/256x256/apps/icon.png" drv}
cat <<EOF > $out/share/applications/out.desktop
[Desktop Entry]
Type=Application
Version=1.0
Name=${drv.pname or drv.name}
Comment=${nixpkgs.lib.attrByPath ["meta" "description"] "Bundled by toAppImage" drv}
Path=${drv}/bin
Exec=${prog}
Icon=icon
Terminal=true
Categories=${nixpkgs.lib.attrByPath ["meta" "categories"] "Utility" drv};
EOF
''
)];
};
};
in
runCommand drv.name {
buildInputs = [ patchelfUnstable appimagekit ];
dontFixup = true;
} ''
cp -rL ${env}/*.AppDir out.AppDir
chmod +w -R ./out.AppDir
cp out.AppDir/usr/share/applications/out.desktop out.AppDir
cp out.AppDir/usr/share/icons/hicolor/256x256/apps/icon.png out.AppDir/.DirIcon
cp out.AppDir/usr/share/icons/hicolor/256x256/apps/icon.png out.AppDir/.
ARCH=x86_64 appimagetool out.AppDir
cp *.AppImage $out
''
49 changes: 27 additions & 22 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });

# Backwards compatibility helper for pre Nix2.6 bundler API
program = p: with builtins; with p; "${outPath}/bin/${
program = p: with builtins; with p; "${
if p?meta && p.meta?mainProgram then
meta.mainProgram
else (parseDrvName (unsafeDiscardStringContext p.name)).name
}";
in {

# Backwards compatibility helper for pre Nix2.6 bundler API
defaultBundler = {__functor = s: {...}@arg:
(if arg?program && arg?system then
Expand All @@ -40,37 +39,43 @@

bundlers = let n =
(forAllSystems (system: {

# Backwards compatibility helper for pre Nix2.6 bundler API
toArx = drv: (nix-bundle.bundlers.nix-bundle ({
program = if drv?program then drv.program else (program drv);
program = if drv?program then drv.program else (drv.outPath + program drv);
inherit system;
})) // (if drv?program then {} else {name=
(builtins.parseDrvName drv.name).name;});

toRPM = drv: nix-utils.bundlers.rpm {inherit system; program=program drv;};
toRPM = drv: nix-utils.bundlers.rpm {inherit system; program=drv.outPath + program drv;};

toDEB = drv: nix-utils.bundlers.deb {inherit system; program=program drv;};
toDEB = drv: nix-utils.bundlers.deb {inherit system; program=drv.outPath + program drv;};

toDockerImage = {...}@drv:
(nixpkgs.legacyPackages.${system}.dockerTools.buildLayeredImage {
name = drv.name;
tag = "latest";
contents = [ drv ];
});
toDockerImage = {...}@drv:
(nixpkgs.legacyPackages.${system}.dockerTools.buildLayeredImage {
name = drv.name;
tag = "latest";
contents = [ drv ];
});

toBuildDerivation = drv:
(import ./report/default.nix {
inherit drv;
pkgs = nixpkgsFor.${system};}).buildtimeDerivations;
toBuildDerivation = drv:
(import ./report/default.nix {
inherit drv;
pkgs = nixpkgsFor.${system};}).buildtimeDerivations;

toReport = drv:
(import ./report/default.nix {
inherit drv;
pkgs = nixpkgsFor.${system};}).runtimeReport;
toReport = drv:
(import ./report/default.nix {
inherit drv;
pkgs = nixpkgsFor.${system};}).runtimeReport;

identity = drv: drv;
}
));
identity = drv: drv;
}
)) // {
x86_64-linux.toAppImage = (import ./appimage.nix {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppimageKit does support packaging for i686-linux and aarch64-linux. Is there a reason to only allow x86_64-linux AppImage bundling?

inherit nixpkgs nixpkgsFor nix-bundle program;
lib = self.lib;
});
};
in with builtins;
# Backwards compatibility helper for pre Nix2.6 bundler API
listToAttrs (map
Expand Down