Add icon file to application?

Hi,

I have nix file that builds and installs an application, but there is no png icon in the github repo, so how can I add a icon myself?
The repo only contains a gif icon, but I think a png icon is required for it to show up in Gnome.

So I need to add a png file from somewhere else, wget/curl or base64 doesn’t work in the postInstall step.
I could fork the repo and add my own png icon but that seems stupid.

Any idea how to inject my own png file?

Thanks!!

Here is the nix file:

{ pkgs, ... }:

pkgs.stdenv.mkDerivation rec {
  pname = "sheepshaver";
  version = "96e512bd6376e78a2869f16dcc8a9028bce5ee72";

  src = pkgs.fetchFromGitHub {
    owner = "cebix";
    repo = "macemu";
    rev = version;
    sha256 = "sha256-ZWE51cRAKj8YFkiBHtd1/M5bWElbdNC30gmYk/cmxEo=";
  };
  unpackPhase = ''
    cp -R $src/ writable/
    chmod -R u+w writable/
    make -C writable/SheepShaver links
  '';
  sourceRoot = "writable/SheepShaver/src/Unix";

  nativeBuildInputs = with pkgs; [
    autoconf automake file perl pkg-config
  ];

  buildInputs = with pkgs; [
    gtk2 SDL xorg.libX11 xorg.libSM libslirp
  ];

  configureFlags = [
    "--enable-sdl-audio"
  ];
  CPPFLAGS = "-DSTDC_HEADERS";

  preConfigure = ''
    NO_CONFIGURE=1 ./autogen.sh
  '';

   desktopEntry = pkgs.makeDesktopItem {
     name = "SheepShaver";
     desktopName = "SheepShaver";
     exec = "SheepShaver";
     icon = "SheepShaver";
     terminal = false;
    };

  postInstall =  ''
    mkdir -p $out/share/applications $out/share/icons
    # this doesn't work
    cp $src/SheepShaver/doc/Linux/icon.gif $out/share/icons/SheepShaver.gif
    cp ${desktopEntry}/share/applications/SheepShaver.desktop $out/share/applications/SheepShaver.desktop
  '';
}

You could probably use a let binding and fetchurl to get the icon and copy or link it in your postInstall-phase.

1 Like

Oh, thanks!

I added this at the top:

{ pkgs, ... }:

let
 getIcon = builtins.fetchurl {
   url = "file:///etc/nixos/nixflakes/assets/SheepShaver.png";
   sha256 = "sha256:9f343a50c61ba17f70c75d07c023da324a254090c280efe685e068f730c6a645";
};
in

But how do I fetch in in the postInstall phase?

This fails with cp: missing destination file operand

  postInstall =  ''
    mkdir -p $out/share/applications $out/share/icons
    cp $getIcon $out/share/icons/SheepShaver.png
    cp ${desktopEntry}/share/applications/SheepShaver.desktop $out/share/applications/SheepShaver.desktop
  '';

You probably need to create the folder for the icon first.

Edit: I see you do that already. Would use ls now to check contents of both the output path and the $getIcon.

1 Like

Thanks for your help!
It works now, I just had to change $getIcon to ${getIcon}

1 Like

Perfect. But you mainly solved it yourself :joy:

1 Like