diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..8392d15 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake \ No newline at end of file diff --git a/.github/workflows/cachix.yml b/.github/workflows/cachix.yml new file mode 100644 index 0000000..d52c88b --- /dev/null +++ b/.github/workflows/cachix.yml @@ -0,0 +1,24 @@ +name: Binary Cache + +on: [push, pull_request, workflow_dispatch] +jobs: + nix: + name: "Build" + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive + + - uses: DeterminateSystems/nix-installer-action@main + with: + logger: pretty + - uses: DeterminateSystems/magic-nix-cache-action@main + - uses: cachix/cachix-action@v14 + with: + name: lan-mouse + authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' + + - name: Build lan-mouse + run: nix build --print-build-logs diff --git a/.gitignore b/.gitignore index d673c4f..28540a2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ /target .gdbinit .idea/ -.vs/ \ No newline at end of file +.vs/ +.vscode/ +.direnv/ +result \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..7bb8056 --- /dev/null +++ b/flake.lock @@ -0,0 +1,82 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1706913249, + "narHash": "sha256-x3M7iV++CsvRXI1fpyFPduGELUckZEhSv0XWnUopAG8=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "e92b6015881907e698782c77641aa49298330223", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1707099356, + "narHash": "sha256-ph483MDKLi9I/gndYOieVP41es633DOOmPjEI50x5KU=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "61dfa5a8129f7edbe9150253c68f673f87b16fb1", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..e9ce9ce --- /dev/null +++ b/flake.nix @@ -0,0 +1,58 @@ +{ + description = "Nix Flake for lan-mouse"; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + outputs = { + self, + nixpkgs, + rust-overlay, + ... + }: let + inherit (nixpkgs) lib; + genSystems = lib.genAttrs [ + "x86_64-linux" + ]; + pkgsFor = system: + import nixpkgs { + inherit system; + + overlays = [ + rust-overlay.overlays.default + ]; + }; + mkRustToolchain = pkgs: + pkgs.rust-bin.stable.latest.default.override { + extensions = ["rust-src"]; + }; + pkgs = genSystems (system: import nixpkgs {inherit system;}); + in { + packages = genSystems (system: rec { + default = pkgs.${system}.callPackage ./nix {}; + lan-mouse = default; + }); + homeManagerModules.default = import ./nix/hm-module.nix self; + devShells = genSystems (system: let + pkgs = pkgsFor system; + rust = mkRustToolchain pkgs; + in { + default = pkgs.mkShell { + packages = with pkgs; [ + rust + rust-analyzer-unwrapped + pkg-config + xorg.libX11 + gtk4 + libadwaita + xorg.libXtst + ]; + + RUST_SRC_PATH = "${rust}/lib/rustlib/src/rust/library"; + }; + }); + }; +} diff --git a/nix/README.md b/nix/README.md new file mode 100644 index 0000000..3ceebae --- /dev/null +++ b/nix/README.md @@ -0,0 +1,40 @@ +# Nix Flake Usage + +## run + +```bash +nix run github:feschber/lan-mouse + +# with params +nix run github:feschber/lan-mouse -- --help + +``` + +## home-manager module + +add input + +```nix +inputs = { + lan-mouse.url = "github:feschber/lan-mouse"; +} +``` + +enable lan-mouse + +``` nix +{ + inputs, + ... +}: { + # add the home manager module + imports = [inputs.lan-mouse.homeManagerModules.default]; + + programs.lan-mouse = { + enable = true; + # systemd = false; + # package = inputs.lan-mouse.packages.${pkgs.stdenv.hostPlatform.system}.default + }; +} + +``` diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 0000000..8372755 --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,46 @@ +{ + rustPlatform, + lib, + pkgs, +}: +rustPlatform.buildRustPackage { + pname = "lan-mouse"; + version = "0.6.0"; + + nativeBuildInputs = with pkgs; [ + pkg-config + cmake + buildPackages.gtk4 + ]; + + buildInputs = with pkgs; [ + xorg.libX11 + gtk4 + libadwaita + xorg.libXtst + ]; + + src = builtins.path { + name = "lan-mouse"; + path = lib.cleanSource ../.; + }; + + cargoLock.lockFile = ../Cargo.lock; + + cargoLock.outputHashes = { + "reis-0.1.0" = "sha256-sRZqm6QdmgqfkTjEENV8erQd+0RL5z1+qjdmY18W3bA="; + }; + + # Set Environment Variables + RUST_BACKTRACE = "full"; + + meta = with lib; { + description = "Lan Mouse is a mouse and keyboard sharing software"; + longDescription = '' + Lan Mouse is a mouse and keyboard sharing software similar to universal-control on Apple devices. It allows for using multiple pcs with a single set of mouse and keyboard. This is also known as a Software KVM switch. + The primary target is Wayland on Linux but Windows and MacOS and Linux on Xorg have partial support as well (see below for more details). + ''; + mainProgram = "lan-mouse"; + platforms = platforms.all; + }; +} diff --git a/nix/hm-module.nix b/nix/hm-module.nix new file mode 100644 index 0000000..49b6cf2 --- /dev/null +++ b/nix/hm-module.nix @@ -0,0 +1,50 @@ +self: { + config, + pkgs, + lib, + ... +}: +with lib; let + cfg = config.programs.lan-mouse; + defaultPackage = self.packages.${pkgs.stdenv.hostPlatform.system}.default; +in { + options.programs.lan-mouse = with types; { + enable = mkEnableOption "Whether or not to enable lan-mouse."; + package = mkOption { + type = with types; nullOr package; + default = defaultPackage; + defaultText = literalExpression "inputs.lan-mouse.packages.${pkgs.stdenv.hostPlatform.system}.default"; + description = '' + The lan-mouse package to use. + + By default, this option will use the `packages.default` as exposed by this flake. + ''; + }; + systemd = mkOption { + type = types.bool; + default = pkgs.stdenv.isLinux; + description = "Whether to enable to systemd service for lan-mouse."; + }; + }; + + config = mkIf cfg.enable { + systemd.user.services.lan-mouse = lib.mkIf cfg.systemd { + Unit = { + Description = "Systemd service for Lan Mouse"; + Requires = ["graphical-session.target"]; + }; + Service = { + Type = "simple"; + ExecStart = "${cfg.package}/bin/lan-mouse --daemon"; + }; + Install.WantedBy = [ + (lib.mkIf config.wayland.windowManager.hyprland.systemd.enable "hyprland-session.target") + (lib.mkIf config.wayland.windowManager.sway.systemd.enable "sway-session.target") + ]; + }; + + home.packages = [ + cfg.package + ]; + }; +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..8745f50 --- /dev/null +++ b/shell.nix @@ -0,0 +1 @@ +(builtins.getFlake ("git+file://" + toString ./.)).devShells.${builtins.currentSystem}.default