I wanted to create a tiny package for one of my shell scripts for simple distribution on our servers. It can be installed in NixOS configs using (callPackage ./my-script.nix {}).
{ pkgs, ... }: pkgs.writeShellApplication {
name = "my-script";
runtimeInputs = [ pkgs.curl pkgs.coreutils ];
text = builtins.readFile "./my-script.sh";
}
But I also need a .desktop file installed along with the script to run it from a desktop environment.
The .desktop file would be generated with something like:
The question is how these two could be combined into one derivation so that the .desktop file would be installed correctly under share/applications/ and point to the correct path of the executable my-script.
Is it a good way, to use something like this:
{ pkgs, ... }:
pkgs.stdenv.mkDerivation {
name = "my-script";
buildCommand = ''
# include the writeShellApplication call from above
# create $out/bin and $out/share/applications directories
# copy files into the directories
'';
dontBuild = true;
}
Still, the question is, how to fill in the executable path in the .desktop file?
EDIT: oh, it should be just $out/bin/my-script if $out is the final result path.
I’m using pkgs.makeDesktopItem for that. Using https://noogle.dev sometimes helps quickly figuring out if there is already something provided by nixpkgs or the standard libs/builtins.
Here my snippet, checkout GitHub code search path:*.nix pkgs.makeDesktopItem if you need more inspiration or read the source of make-desktopitem/default.nix.
lil question but how do enter the full path to the executable in makeDestopItem ? technically i can just enter the executable name but i’d rather have a full path, ik that in a shell snippet i could just use $out/bin/<executable name> but idk how i can do it here
The string interpolation doesn’t work? Like exec = "${script}/bin/${name} %f";?
Either way, take a look in a nixpkgs search and notice that all instances of makeDesktopItem use the executable name, instead of the full path. Maybe that’s the standard way.