NixOS derivation

This was written by @dzervas , and shared on our Discord. I have removed the download link while things are not public!

{ lib,
  stdenv,
  fetchurl,
  dpkg,
  wrapGAppsHook4,
  dbus,
  zlib,
  fontconfig,
  webkitgtk_4_1,
  gtk3,
  pango,
  cairo,
  gdk-pixbuf,
  libsoup_3,
  glib,
  glib-networking,
  gcc,
  pkg-config,
}:

stdenv.mkDerivation rec {
  pname = "atuin-desktop";
  version = "0.0.70";

  src = fetchurl {
    url = "FILL ME IN";
    sha256 = "and me too :)";
  };

  nativeBuildInputs = [
    dpkg
    wrapGAppsHook4
    pkg-config
  ];

  buildInputs = [
    # System libraries
    dbus
    zlib
    fontconfig

    # GTK and related libraries
    webkitgtk_4_1
    gtk3
    pango
    cairo
    gdk-pixbuf

    # Network and utility libraries
    libsoup_3

    # GLib libraries
    glib
    glib-networking

    # Runtime dependencies
    gcc.cc.lib  # For libgcc_s.so.1
  ];

  unpackPhase = ''
    dpkg-deb -x $src .
  '';

  installPhase = ''
    mkdir -p $out
    cp -r usr/* $out/ || true

    # Ensure desktop files exist and are properly configured
    if [ -d $out/share/applications ]; then
      for desktop in $out/share/applications/*.desktop; do
        if [ -f "$desktop" ]; then
          substituteInPlace "$desktop" \
            --replace "Exec=/usr/bin/" "Exec=$out/bin/"
        fi
      done
    fi
  '';

  preFixup = ''
    gappsWrapperArgs+=(
      # Ensure the binary can find all required libraries
      --prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath buildInputs}
    )
  '';

  postFixup = ''
    echo "=== Debugging binary ==="
    if [ -f "$out/bin/atuin-desktop" ]; then
      echo "Binary exists"
      file "$out/bin/atuin-desktop"
      ldd "$out/bin/atuin-desktop" || echo "ldd failed"
      readelf -l "$out/bin/atuin-desktop" | grep interpreter || echo "No interpreter found"
    else
      echo "Binary not found, listing contents:"
      find "$out" -name "*atuin*" -type f
    fi
    echo "=== End debugging ==="
    find $out/bin -type f -executable | while read -r bin; do
      echo "Patching binary: $bin"

      # Check if it's an ELF binary
      if file "$bin" | grep -q "ELF"; then
        echo "  Setting interpreter..."
        patchelf --set-interpreter ${stdenv.cc.bintools.dynamicLinker} "$bin" || echo "  Failed to set interpreter"

        echo "  Setting rpath..."
        patchelf --set-rpath ${lib.makeLibraryPath buildInputs} "$bin" || echo "  Failed to set rpath"

        echo "  Shrinking rpath..."
        patchelf --shrink-rpath "$bin" || echo "  Failed to shrink rpath"
      fi
    done
  '';

  meta = with lib; {
    description = "Atuin Desktop";
    homepage = "https://atuin.sh";
    license = licenses.unfree;
    maintainers = [];
    platforms = ["x86_64-linux"];
  };
}

Known issues

  1. Context menu does not open correctly
  2. Missing icons (again?)
5 Likes

THANK YOU! I just asked Ellie on Mastodon about this and, while I am not shocked someone already did this, I was almost expecting to do it myself. EITHER WAY, so happy.

2 Likes

Updated to patch the elf instead of residing to nix-ld for the dynamic libs

1 Like

Awesome! Thanks for maintaining this one!

glib-networking is not included in the buildInputs, adding this back in fixed the icons for me.

3 Likes

right! fixed it, thanks!

1 Like

Going to ask a stupid question, again.

@dzervas the download link i have in the email I got for the closed beta doesn’t seem to work. Where are you getting updated links?

Additionally, I assume you are using nix-hash to generate the hash value for the package?

@ellie can help with the link

regarding the hash: nix-prefetch-url if I’m not mistaken

@randoneering, I just DMd you a link to the deb download :slight_smile:

Perfect-thank you to the both of you. I will attempt to build tonight