feat: add socket communication support for nix builds

includes socket interface support in colorshell nix builds! thanks to @conroy-cheers in #28 :D
This commit is contained in:
João Dias
2025-11-13 21:42:16 -03:00
committed by GitHub
4 changed files with 40 additions and 18 deletions
+1 -1
View File
@@ -41,7 +41,7 @@
... ...
}: }:
let let
colorshell = pkgs.callPackage ./nix/package.nix { inherit inputs'; }; colorshell = pkgs.callPackage ./nix/colorshell.nix { inherit inputs'; };
in in
{ {
packages = { packages = {
+25 -4
View File
@@ -3,6 +3,7 @@
lib, lib,
stdenv, stdenv,
stdenvNoCC, stdenvNoCC,
moreutils,
pnpm_10, pnpm_10,
buildNpmPackage, buildNpmPackage,
wrapGAppsHook4, wrapGAppsHook4,
@@ -10,6 +11,8 @@
glib, glib,
gjs, gjs,
libadwaita, libadwaita,
dart-sass,
socat,
}: }:
let let
packageJSON = lib.importJSON ../package.json; packageJSON = lib.importJSON ../package.json;
@@ -106,6 +109,7 @@ buildNpmPackage (finalAttrs: {
wrapGAppsHook4 wrapGAppsHook4
gobject-introspection gobject-introspection
inputs'.ags.packages.default inputs'.ags.packages.default
moreutils
]; ];
buildInputs = [ buildInputs = [
@@ -129,25 +133,42 @@ buildNpmPackage (finalAttrs: {
buildPhase = '' buildPhase = ''
runHook preBuild runHook preBuild
mkdir -p $out/bin mkdir build
ags bundle ./src/app.ts $out/bin/${packageJSON.name} \ outPath=./build/${packageJSON.name}
ags bundle ./src/app.ts $outPath \
--gtk 4 \ --gtk 4 \
--root ./src \ --root ./src \
--define "DEVEL=false" \ --define "DEVEL=false" \
--define "COLORSHELL_VERSION='${finalAttrs.version}'" \ --define "COLORSHELL_VERSION='${finalAttrs.version}'" \
--define "GRESOURCES_FILE='${colorshellResources}'" --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 runHook postBuild
''; '';
# the above buildPhase installs for us installPhase = ''
dontInstall = true; runHook preInstall
mkdir -p $out/bin
cp -rp build/${packageJSON.name} $out/bin/
runHook postInstall
'';
preFixup = '' preFixup = ''
gappsWrapperArgs+=( gappsWrapperArgs+=(
--prefix PATH : ${ --prefix PATH : ${
lib.makeBinPath [ lib.makeBinPath [
# runtime executables # runtime executables
dart-sass
glib
socat
] ]
} }
) )
+13
View File
@@ -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
+1 -13
View File
@@ -43,19 +43,7 @@ sh ./scripts/build.sh -o "${outdir:-./build/release}" -b -r "${gresource_file:-\
if [[ $socket_support ]]; then if [[ $socket_support ]]; then
echo "[info] adding socket communication support" echo "[info] adding socket communication support"
script="\ script="\
#!/usr/bin/bash `cat ./scripts/colorshell-socket-interface.sh`
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 "${outdir:-./build/release}/colorshell" | sed -e 's/^#.*//'`" # remove shebang `cat "${outdir:-./build/release}/colorshell" | sed -e 's/^#.*//'`" # remove shebang
echo -en "$script" > "${outdir:-./build/release}/colorshell" echo -en "$script" > "${outdir:-./build/release}/colorshell"