From 49f9dc05bab151ab8cd6e1707f5bc93f7ba3a7e6 Mon Sep 17 00:00:00 2001 From: Tom Bereknyei Date: Fri, 18 Mar 2022 02:21:12 -0400 Subject: [PATCH] feat: init appimage --- appimage.nix | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 49 +++++++++++++++++++++++++++---------------------- 2 files changed, 78 insertions(+), 22 deletions(-) create mode 100644 appimage.nix diff --git a/appimage.nix b/appimage.nix new file mode 100644 index 0000000..fd2c1e7 --- /dev/null +++ b/appimage.nix @@ -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];} '' + 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 < $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 + '' diff --git a/flake.nix b/flake.nix index 4366ff9..cd043eb 100644 --- a/flake.nix +++ b/flake.nix @@ -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 @@ -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 { + inherit nixpkgs nixpkgsFor nix-bundle program; + lib = self.lib; + }); + }; in with builtins; # Backwards compatibility helper for pre Nix2.6 bundler API listToAttrs (map