Skip to content

Instantly share code, notes, and snippets.

@diamondburned
Last active March 11, 2025 00:56
Show Gist options
  • Save diamondburned/b9252476c1ce295e453dc815b888d974 to your computer and use it in GitHub Desktop.
Save diamondburned/b9252476c1ce295e453dc815b888d974 to your computer and use it in GitHub Desktop.
Run gotk4 programs using the system's Nixpkgs because Nix Flakes sucks!!!
#!/usr/bin/env bash
set -eo pipefail
NIX_EXPR=$(cat <<-'EOF'
{
mainProgram,
}:
let
pkgs = import <nixpkgs> { };
in
pkgs.stdenv.mkDerivation {
name = "${mainProgram}-wrapped";
src = ./. + "/${mainProgram}";
dontUnpack = true;
buildInputs = with pkgs; [
gtk4
glib
libadwaita
librsvg
gdk-pixbuf
gobject-introspection
hicolor-icon-theme
gtksourceview4
gtksourceview5
libspelling
gst_all_1.gstreamer
gst_all_1.gst-plugins-good
gst_all_1.gst-plugins-bad
gst_all_1.gst-plugins-ugly
];
nativeBuildInputs = with pkgs; [
wrapGAppsHook
autoPatchelfHook
];
sourceRoot = ".";
buildPhase = ''
mkdir -p \
$out/bin
install -Dm755 "$src" "$out/bin/${mainProgram}"
'';
}
EOF
)
if [[ "$1" == shell ]]; then
nix-shell -E "$NIX_EXPR" --argstr mainProgram "" --run bash
else
mainProgram="${1:-$(basename "$PWD")}"
out=$(nix-build -E "$NIX_EXPR" --argstr mainProgram "${mainProgram}" --no-out-link)
exec "${out}/bin/${mainProgram}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment