From e05dab3ed6adc501be0a5068236aab259c4a63ca Mon Sep 17 00:00:00 2001 From: Conroy Cheers Date: Tue, 11 Nov 2025 00:15:03 +1100 Subject: [PATCH] feat: prepend socket interface to nix build output --- flake.nix | 2 +- nix/{package.nix => colorshell.nix} | 27 ++++++++++++++++++++++---- scripts/colorshell-socket-interface.sh | 13 +++++++++++++ scripts/release.sh | 14 +------------ 4 files changed, 38 insertions(+), 18 deletions(-) rename nix/{package.nix => colorshell.nix} (86%) create mode 100644 scripts/colorshell-socket-interface.sh diff --git a/flake.nix b/flake.nix index 7b8b954..d168097 100644 --- a/flake.nix +++ b/flake.nix @@ -41,7 +41,7 @@ ... }: let - colorshell = pkgs.callPackage ./nix/package.nix { inherit inputs'; }; + colorshell = pkgs.callPackage ./nix/colorshell.nix { inherit inputs'; }; in { packages = { diff --git a/nix/package.nix b/nix/colorshell.nix similarity index 86% rename from nix/package.nix rename to nix/colorshell.nix index 34568f4..5851bd6 100644 --- a/nix/package.nix +++ b/nix/colorshell.nix @@ -3,6 +3,7 @@ lib, stdenv, stdenvNoCC, + moreutils, pnpm_10, buildNpmPackage, wrapGAppsHook4, @@ -10,6 +11,7 @@ glib, gjs, libadwaita, + socat, }: let packageJSON = lib.importJSON ../package.json; @@ -106,6 +108,7 @@ buildNpmPackage (finalAttrs: { wrapGAppsHook4 gobject-introspection inputs'.ags.packages.default + moreutils ]; buildInputs = [ @@ -129,25 +132,41 @@ buildNpmPackage (finalAttrs: { buildPhase = '' runHook preBuild - mkdir -p $out/bin - ags bundle ./src/app.ts $out/bin/${packageJSON.name} \ + mkdir build + outPath=./build/${packageJSON.name} + ags bundle ./src/app.ts $outPath \ --gtk 4 \ --root ./src \ --define "DEVEL=false" \ --define "COLORSHELL_VERSION='${finalAttrs.version}'" \ --define "GRESOURCES_FILE='${colorshellResources}'" + # add socket-communication support on executable + { + head -n1 $outPath + sed '1{/^#!.*$/d}' ${../scripts/colorshell-socket-interface.sh} + cat "$outPath" | sed '/^#!.*$/d' + } | sponge $outPath + runHook postBuild ''; - # the above buildPhase installs for us - dontInstall = true; + installPhase = '' + runHook preInstall + + mkdir -p $out/bin + cp -rp build/${packageJSON.name} $out/bin/ + + runHook postInstall + ''; preFixup = '' gappsWrapperArgs+=( --prefix PATH : ${ lib.makeBinPath [ # runtime executables + socat + glib ] } ) diff --git a/scripts/colorshell-socket-interface.sh b/scripts/colorshell-socket-interface.sh new file mode 100644 index 0000000..883d1b7 --- /dev/null +++ b/scripts/colorshell-socket-interface.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +if gdbus introspect --session \ + --dest io.github.retrozinndev.colorshell \ + --object-path /io/github/retrozinndev/colorshell > /dev/null 2>&1; then + + if command -v socat > /dev/null 2>&1; then + echo "$@" | socat - "${XDG_RUNTIME_DIR:-/run/user/$(id -u)}/colorshell.sock" + exit 0 + else + echo "[warn] \`socat\` not installed, falling back to remote instance communication" + fi +fi diff --git a/scripts/release.sh b/scripts/release.sh index 506026a..43ba944 100644 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -43,19 +43,7 @@ sh ./scripts/build.sh -o "${outdir:-./build/release}" -b -r "${gresource_file:-\ if [[ $socket_support ]]; then echo "[info] adding socket communication support" script="\ -#!/usr/bin/bash - -if gdbus introspect --session \\ - --dest io.github.retrozinndev.colorshell \\ - --object-path /io/github/retrozinndev/colorshell > /dev/null 2>&1; then - - if command -v socat > /dev/null 2>&1; then - echo \"\$@\" | socat - \"\${XDG_RUNTIME_DIR:-/run/user/\$(id -u)}/colorshell.sock\" - exit 0 - else - echo \"[warn] \`socat\` not installed, falling back to remote instance communication\" - fi -fi +`cat ./scripts/colorshell-socket-interface.sh` `cat "${outdir:-./build/release}/colorshell" | sed -e 's/^#.*//'`" # remove shebang echo -en "$script" > "${outdir:-./build/release}/colorshell"