HyprlandでWaylandとXwayland間でClipboardの同期ができず,策がないかと困り果てていたところ,以下のPython Scriptが機能することが分かった.
https://github.com/arabianq/wl-x11-clipsync
ただこれは特にパッケージングされている等はないので,自分でNix PackageにしてNURに上げることにした.
Nix式は以下.
{
lib,
stdenv,
fetchFromGitHub,
unstableGitUpdater,
xclip,
wl-clipboard,
clipnotify,
python3,
makeWrapper,
which
}:
stdenv.mkDerivation rec {
name = "wl-x11-clipsync";
version = "0-unstable-2025-01-31";
src = fetchFromGitHub {
owner = "arabianq";
repo = "wl-x11-clipsync";
rev = "fc3ac4d1d57ffdc3222e818c8a58d20c91f3fcf3";
hash = "sha256-Cez4ywJtOjHM1GVRuPvyOgwjftzHK3UyGCBw2VQkIrA=";
};
nativeBuildInputs = [ makeWrapper ];
buildInputs = [ python3 ];
installPhase = ''
mkdir -p $out/share/wl-x11-clipsync
cp ./clipsync.py $out/share/wl-x11-clipsync/clipsync
chmod +x $out/share/wl-x11-clipsync/clipsync
patchShebangs --host $out/share/wl-x11-clipsync/clipsync
makeWrapper $out/share/wl-x11-clipsync/clipsync $out/bin/clipsync \
--prefix PATH : "${lib.makeBinPath [ xclip wl-clipboard clipnotify which ]}"
'';
meta = with lib; {
description = "Python script synchronizes the clipboard between Wayland";
homepage = "https://github.com/arabianq/wl-x11-clipsync";
license = licenses.unlicense;
platforms = platforms.linux;
mainProgram = "clipsync";
};
}
ただScriptがあるだけなので,とりあえずinstallPhase
があればよい.
このスクリプトは他のPythonパッケージへの依存がなかったので特に追加していないが,依存がある場合はbuildInputs
のpython3
にそれを含める必要がある.
こういった感じ (from https://stackoverflow.com/questions/43837691/how-to-package-a-single-python-script-with-nix)
(pkgs.python3.withPackages (pythonPackages: with pythonPackages; [
consul
six
requests2
]))
Python Script本体はNixではど定番のpatchShebang
でshebangの書き換えを行い,とりあえずshare
以下に配置した.
ポン置きで動作すればよいのだが,外部コマンドにいくつか依存しているため,bin
以下にはwrapperを配置する.
makeWrapper
のオプション --prefix PATH : "${lib.makeBinPath [ xclip wl-clipboard clipnotify which ]}"
で実行時のパスを追加し,スクリプトから正しく呼び出されるようにする.
自動で立ち上がってほしいので,これをsystemd user serviceから呼ぶようにした.
こちらはdotfiles
のnixosConfiguration
.
# Sync clipboard between wayland and X11
systemd.user.services.wl-x11-clipsync = {
description = "Clipboard Sync Service";
wantedBy = [ "default.target" ];
serviceConfig = {
ExecStart = "${pkgs.wl-x11-clipsync}/bin/clipsync";
Restart = "on-failure";
};
};