Help creating derivation for installing a macOS app Insomnia

I’d love some help creating a derivation for installing Insomnia.app for macOS. The linux derivation may be of some help, in terms of runtime dependencies; not sure.

So, I’ve taken jwiegley’s overlay 30-apps.nix as a reference for how to install macOS apps via nix.

Installing something like Zotero works fine. It installs happily, is linked in ~/.nix-profile/Applications, and starts happily via open -a Zotero.

But in trying to define a derivation for Insomnia it fails to start, due to a linkage error. Downloading the same dmg and installing it into the standard macOS /Applications location starts up just fine.

Any ideas?

The error upon launching Insomnia from nix is as follows:

Process:               Insomnia [56589]
Path:                  /Volumes/VOLUME/*/Insomnia.app/Contents/MacOS/Insomnia
Identifier:            com.insomnia.app
Version:               7.1.1 (7.1.1.3350)
Code Type:             X86-64 (Native)
Parent Process:        ??? [1]
Responsible:           Insomnia [56589]
User ID:               501

Date/Time:             2020-03-12 18:45:42.145 +1100
OS Version:            Mac OS X 10.15.3 (19D76)
Report Version:        12
Bridge OS Version:     4.2 (17P3050)
Anonymous UUID:        AABD1439-665E-61B1-A942-E6ADC22C6409

Sleep/Wake UUID:       E45909D3-158F-4300-8BE4-BF5BB221E7FE

Time Awake Since Boot: 400000 seconds
Time Since Wake:       3600 seconds

System Integrity Protection: enabled

Crashed Thread:        0

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Reason:    DYLD, [0x1] Library missing

Application Specific Information:
dyld: launch, loading dependent libraries

Dyld Error Message:
  Library not loaded: @rpath/Electron Framework.framework/Electron Framework
  Referenced from: /Volumes/VOLUME/*/Insomnia.app/Contents/MacOS/Insomnia
  Reason: no suitable image found.  Did find:
	/nix/store/8yqxccj5a6ax58wxsrrwy4ywjvpyhjhm-Insomnia-7.1.1/Applications/Insomnia.app/Contents/MacOS/../Frameworks/Electron Framework.framework/Electron Framework: file too short
	/nix/store/8yqxccj5a6ax58wxsrrwy4ywjvpyhjhm-Insomnia-7.1.1/Applications/Insomnia.app/Contents/MacOS/../Frameworks/Electron Framework.framework/Electron Framework: stat() failed with errno=1

Binary Images:
       0x10f29a000 -        0x10f29aff3 +com.insomnia.app (7.1.1 - 7.1.1.3350) <4FAD2A7B-B418-358C-949F-1104B0620579> /Volumes/VOLUME/*/Insomnia.app/Contents/MacOS/Insomnia
       0x114be4000 -        0x114c74cb7  dyld (733.8) <EBC07CB6-870A-3A8E-B48A-67F62EA161F3> /usr/lib/dyld

My overlay 30-macos-apps.nix is as follows so far:

self: super: {

installApplication = 
  { name, appname ? name, version, src, description, homepage, 
    postInstall ? "", sourceRoot ? ".", ... }:
  with super; stdenv.mkDerivation {
    name = "${name}-${version}";
    version = "${version}";
    src = src;
    buildInputs = [ undmg unzip ];
    sourceRoot = sourceRoot;
    phases = [ "unpackPhase" "installPhase" ];
    installPhase = ''
      mkdir -p "$out/Applications/${appname}.app"
      cp -pR * "$out/Applications/${appname}.app"
    '' + postInstall;
    meta = with stdenv.lib; {
      description = description;
      homepage = homepage;
      maintainers = with maintainers; [ jwiegley ];
      platforms = platforms.darwin;
    };
  };

Insomnia = self.installApplication rec {
  name = "Insomnia";
  version = "7.1.1";
  sourceRoot = "Insomnia.app";
  src = super.fetchurl {
    name = "insomnia-${version}.dmg";
    url = "https://github.com/getinsomnia/insomnia/releases/download/v${version}/Insomnia-${version}.dmg";
    sha256 = "7718dd2c1a6ec0edafe36116d9123cda80b769abadc2d4fc5c5389922c7dfa6f";
  };
  description = "Cross-platform HTTP and GraphQL Client";
  homepage = https://insomnia.rest;
};

Zotero = self.installApplication rec {
  name = "Zotero";
  version = "5.0.84";
  sourceRoot = "Zotero.app";
  src = super.fetchurl {
    name = "zotero-${version}.dmg";
    url = "https://download.zotero.org/client/release/${version}/Zotero-${version}.dmg";
    sha256 = "0nfgbbwls576hi0bvjb47b5sn65ygxj3vz102s1jsvmk4pkwvap8";
  };
  description = ''
    Zotero is a free, easy-to-use tool to help you collect, organize, cite,
    and share your research sources
  '';
  homepage = https://www.zotero.org;
};

}

References

  • the home-brew cask for insomnia is here.
  • the insomnia package derivation for linux here