From e7ec263cf96b770cd8cfd3923669d9b27f6b3dcb Mon Sep 17 00:00:00 2001 From: QuarterHeaven Date: Tue, 4 Jun 2024 10:55:18 +0800 Subject: [PATCH 01/10] add nix flake support --- .gitignore | 1 + default.nix | 11 +++++++++++ flake.lock | 27 +++++++++++++++++++++++++++ flake.nix | 16 ++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitignore b/.gitignore index ba1e2c6..716d322 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # compiled files and executables /target/ +/result/ # distributable packages /dist/ diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..691c34f --- /dev/null +++ b/default.nix @@ -0,0 +1,11 @@ +{ pkgs ? import { } }: +pkgs.rustPlatform.buildRustPackage rec { + buildInputs = with pkgs; [ + xorg.libxcb + ]; + + pname = "clipboard-sync"; + version = "0.2.0"; + cargoLock.lockFile = ./Cargo.lock; + src = ./.; +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..07b4b9a --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1717196966, + "narHash": "sha256-yZKhxVIKd2lsbOqYd5iDoUIwsRZFqE87smE2Vzf6Ck0=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "57610d2f8f0937f39dbd72251e9614b1561942d8", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..b9ce9b6 --- /dev/null +++ b/flake.nix @@ -0,0 +1,16 @@ +{ + description = "Synchronizes the clipboard across multiple X11 and wayland instances running on the same machine"; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + }; + outputs = { self, nixpkgs }: + let + supportedSystems = [ "x86_64-linux" ]; + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + pkgsFor = nixpkgs.legacyPackages; + in { + packages = forAllSystems (system: { + default = pkgsFor.${system}.callPackage ./. { }; + }); + }; +} From 655c6641455aa48f2e1824dfbd5d1a71af91612b Mon Sep 17 00:00:00 2001 From: QuarterHeaven Date: Tue, 4 Jun 2024 11:14:21 +0800 Subject: [PATCH 02/10] add service config in nix flake --- flake.nix | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index b9ce9b6..908272b 100644 --- a/flake.nix +++ b/flake.nix @@ -8,9 +8,24 @@ supportedSystems = [ "x86_64-linux" ]; forAllSystems = nixpkgs.lib.genAttrs supportedSystems; pkgsFor = nixpkgs.legacyPackages; - in { - packages = forAllSystems (system: { - default = pkgsFor.${system}.callPackage ./. { }; - }); - }; + in { + packages = forAllSystems (system: { + default = pkgsFor.${system}.callPackage ./. { }; + }); + + nixosModules.default = + # For illustration, probably want to break this definition out to a separate file + { config, pkgs, lib, ... }: { + options = { + services.myApp.enable = lib.mkEnableOption "clipboard-sync"; + }; + + config = lib.mkIf config.services.clipboard-sync.enable { + systemd.services.clipboard-sync = { + # Insert systemd config here + serviceConfig.ExecStart = "${self.packages.${pkgs.system}.default}/bin/main"; + }; + }; + }; + }; } From 3f6691ef68c6f8de1a0f4e44bb5683ac917961f0 Mon Sep 17 00:00:00 2001 From: QuarterHeaven Date: Tue, 4 Jun 2024 11:17:44 +0800 Subject: [PATCH 03/10] fixed flake service. --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 908272b..021eb29 100644 --- a/flake.nix +++ b/flake.nix @@ -17,7 +17,7 @@ # For illustration, probably want to break this definition out to a separate file { config, pkgs, lib, ... }: { options = { - services.myApp.enable = lib.mkEnableOption "clipboard-sync"; + services.clipboard-sync.enable = lib.mkEnableOption "clipboard-sync"; }; config = lib.mkIf config.services.clipboard-sync.enable { From 3c04fc465b5d47cc1a8ddeeea142cc38d18e0841 Mon Sep 17 00:00:00 2001 From: QuarterHeaven Date: Tue, 4 Jun 2024 11:28:54 +0800 Subject: [PATCH 04/10] updated README. --- README.md | 12 +++++++++++- flake.nix | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ac1aac1..d201848 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Example use cases: - **Improve Wayland compatibility**: You have already enabled support for wayland in your system, but your computer does not synchronize the clipboard between X11 and wayland windows. clipboard-sync can solve this problem. [more details](https://github.com/dnut/clipboard-sync/issues/9#issuecomment-1502368133) - **VNC**: You run a VNC server and would like all host and client logins from the same user to share the same clipboard. -- **Multiple displays**: You run two or more desktop environments or window managers in separate ttys, switching between desktops using ctrl-alt-F*. +- **Multiple displays**: You run two or more desktop environments or window managers in separate ttys, switching between desktops using ctrl-alt-F*. - **Nested Wayland**: You run a wayland compositor within a window. examples: - you primarily use kde, but run sway in a window to consolidate all your messenger apps into a single tiled/tabbed window. - you use gnome and develop extensions for gnome, so you run a nested gnome environment for testing. @@ -77,6 +77,16 @@ In addition to installing from the official repository, you can also build and i make deb && sudo apt install ./dist/deb/clipboard-sync_*.deb ``` +### NixOS +Firstly add this repo to your flake inputs: +```nix +clipboard-sync.url = "github:QuarterHeaven/clipboard-sync"; +``` + +Then put `clipboard-sync.nixosModules.default` into flake modules. + +Finally, add `services.clipboard-sync.enable = true;` into the `configuration.nix`. + # Usage The typical set-and-forget approach is to enable to service: ```bash diff --git a/flake.nix b/flake.nix index 021eb29..8f68302 100644 --- a/flake.nix +++ b/flake.nix @@ -23,7 +23,7 @@ config = lib.mkIf config.services.clipboard-sync.enable { systemd.services.clipboard-sync = { # Insert systemd config here - serviceConfig.ExecStart = "${self.packages.${pkgs.system}.default}/bin/main"; + serviceConfig.ExecStart = "${self.packages.${pkgs.system}.default}/bin/clipboard-sync"; }; }; }; From 385f7ebb330c51c2ed0f6ebcf3dc3c7445203b82 Mon Sep 17 00:00:00 2001 From: QuarterHeaven Date: Tue, 4 Jun 2024 12:09:50 +0800 Subject: [PATCH 05/10] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d201848..023a202 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ make deb && sudo apt install ./dist/deb/clipboard-sync_*.deb ### NixOS Firstly add this repo to your flake inputs: ```nix -clipboard-sync.url = "github:QuarterHeaven/clipboard-sync"; +clipboard-sync.url = "github:dnut/clipboard-sync"; ``` Then put `clipboard-sync.nixosModules.default` into flake modules. From 27ee0a06c7c610f93309ceddf67fdf6523c91917 Mon Sep 17 00:00:00 2001 From: QuarterHeaven Date: Tue, 4 Jun 2024 15:10:14 +0800 Subject: [PATCH 06/10] update systemd service in flake --- flake.nix | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 8f68302..e2988fb 100644 --- a/flake.nix +++ b/flake.nix @@ -22,8 +22,14 @@ config = lib.mkIf config.services.clipboard-sync.enable { systemd.services.clipboard-sync = { - # Insert systemd config here - serviceConfig.ExecStart = "${self.packages.${pkgs.system}.default}/bin/clipboard-sync"; + description = "Synchronize clipboards across all displays"; + documentation = "https://github.com/dnut/clipboard-sync/"; + wantedBy = [ "graphical-session.target" ]; + after = [ "graphical-session.target" ]; + partOf = [ "graphical-session.target" ]; + requisite = [ "graphical-session.target" ]; + serviceConfig.ExecStart = "/usr/bin/env ${self.packages.${pkgs.system}.default}/bin/clipboard-sync --hide-timestamp --log-level debug"; + serviceConfig.Restart = "on-failure"; }; }; }; From d7b6ea55cce39a4680466a0cb603c857cad1299d Mon Sep 17 00:00:00 2001 From: QuarterHeaven Date: Tue, 4 Jun 2024 15:12:17 +0800 Subject: [PATCH 07/10] update services in flake.nix --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index e2988fb..e616492 100644 --- a/flake.nix +++ b/flake.nix @@ -23,7 +23,7 @@ config = lib.mkIf config.services.clipboard-sync.enable { systemd.services.clipboard-sync = { description = "Synchronize clipboards across all displays"; - documentation = "https://github.com/dnut/clipboard-sync/"; + documentation = [ "https://github.com/dnut/clipboard-sync/" ]; wantedBy = [ "graphical-session.target" ]; after = [ "graphical-session.target" ]; partOf = [ "graphical-session.target" ]; From 93d061fc3f9acc59ad8897ab027eb7be292dabe5 Mon Sep 17 00:00:00 2001 From: QuarterHeaven Date: Tue, 4 Jun 2024 15:23:34 +0800 Subject: [PATCH 08/10] update services in flake.nix --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index e616492..31a9816 100644 --- a/flake.nix +++ b/flake.nix @@ -21,7 +21,7 @@ }; config = lib.mkIf config.services.clipboard-sync.enable { - systemd.services.clipboard-sync = { + systemd.user.services.clipboard-sync = { description = "Synchronize clipboards across all displays"; documentation = [ "https://github.com/dnut/clipboard-sync/" ]; wantedBy = [ "graphical-session.target" ]; From 0e33cb753ce974a2176c86e5d59cbb400d7b5ded Mon Sep 17 00:00:00 2001 From: Drew Nutter Date: Mon, 23 Sep 2024 15:10:45 +0800 Subject: [PATCH 09/10] style(nix): format with nixfmt-rfc-style --- default.nix | 8 ++++---- flake.nix | 59 +++++++++++++++++++++++++++++++---------------------- 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/default.nix b/default.nix index 691c34f..d8b15fd 100644 --- a/default.nix +++ b/default.nix @@ -1,8 +1,8 @@ -{ pkgs ? import { } }: +{ + pkgs ? import { }, +}: pkgs.rustPlatform.buildRustPackage rec { - buildInputs = with pkgs; [ - xorg.libxcb - ]; + buildInputs = with pkgs; [ xorg.libxcb ]; pname = "clipboard-sync"; version = "0.2.0"; diff --git a/flake.nix b/flake.nix index 31a9816..dee3710 100644 --- a/flake.nix +++ b/flake.nix @@ -3,35 +3,46 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; }; - outputs = { self, nixpkgs }: + outputs = + { self, nixpkgs }: let supportedSystems = [ "x86_64-linux" ]; forAllSystems = nixpkgs.lib.genAttrs supportedSystems; pkgsFor = nixpkgs.legacyPackages; - in { - packages = forAllSystems (system: { - default = pkgsFor.${system}.callPackage ./. { }; - }); + in + { + formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixfmt-rfc-style; + packages = forAllSystems (system: { + default = pkgsFor.${system}.callPackage ./. { }; + }); - nixosModules.default = - # For illustration, probably want to break this definition out to a separate file - { config, pkgs, lib, ... }: { - options = { - services.clipboard-sync.enable = lib.mkEnableOption "clipboard-sync"; - }; + nixosModules.default = + # For illustration, probably want to break this definition out to a separate file + { + config, + pkgs, + lib, + ... + }: + { + options = { + services.clipboard-sync.enable = lib.mkEnableOption "clipboard-sync"; + }; - config = lib.mkIf config.services.clipboard-sync.enable { - systemd.user.services.clipboard-sync = { - description = "Synchronize clipboards across all displays"; - documentation = [ "https://github.com/dnut/clipboard-sync/" ]; - wantedBy = [ "graphical-session.target" ]; - after = [ "graphical-session.target" ]; - partOf = [ "graphical-session.target" ]; - requisite = [ "graphical-session.target" ]; - serviceConfig.ExecStart = "/usr/bin/env ${self.packages.${pkgs.system}.default}/bin/clipboard-sync --hide-timestamp --log-level debug"; - serviceConfig.Restart = "on-failure"; - }; + config = lib.mkIf config.services.clipboard-sync.enable { + systemd.user.services.clipboard-sync = { + description = "Synchronize clipboards across all displays"; + documentation = [ "https://github.com/dnut/clipboard-sync/" ]; + wantedBy = [ "graphical-session.target" ]; + after = [ "graphical-session.target" ]; + partOf = [ "graphical-session.target" ]; + requisite = [ "graphical-session.target" ]; + serviceConfig.ExecStart = "/usr/bin/env ${ + self.packages.${pkgs.system}.default + }/bin/clipboard-sync --hide-timestamp --log-level debug"; + serviceConfig.Restart = "on-failure"; }; - }; - }; + }; + }; + }; } From c1e100c0f2db14689a790c9d22c2e13586cd3982 Mon Sep 17 00:00:00 2001 From: Drew Nutter Date: Mon, 23 Sep 2024 15:16:56 +0800 Subject: [PATCH 10/10] fix/docs(gitignore,readme): result is a symlink and must be treated as a file --- .gitignore | 2 +- README.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 716d322..dbe4a76 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # compiled files and executables /target/ -/result/ +/result # distributable packages /dist/ diff --git a/README.md b/README.md index 023a202..b139c03 100644 --- a/README.md +++ b/README.md @@ -78,14 +78,14 @@ make deb && sudo apt install ./dist/deb/clipboard-sync_*.deb ``` ### NixOS -Firstly add this repo to your flake inputs: +Add this repo to your flake inputs: ```nix clipboard-sync.url = "github:dnut/clipboard-sync"; ``` -Then put `clipboard-sync.nixosModules.default` into flake modules. +Put `clipboard-sync.nixosModules.default` into flake modules. -Finally, add `services.clipboard-sync.enable = true;` into the `configuration.nix`. +To enable the systemd service, add `services.clipboard-sync.enable = true;` into the `configuration.nix`. # Usage The typical set-and-forget approach is to enable to service: