feat: add nix support(#80) (#82)

* feat: add nix support(#80)

* chore: nix flake update

* update actions
This commit is contained in:
虢豳
2024-03-16 05:02:18 +08:00
committed by GitHub
parent abf95afb9f
commit 8ff991aefe
9 changed files with 306 additions and 1 deletions

1
.envrc Normal file
View File

@@ -0,0 +1 @@
use flake

24
.github/workflows/cachix.yml vendored Normal file
View File

@@ -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

5
.gitignore vendored
View File

@@ -1,4 +1,7 @@
/target
.gdbinit
.idea/
.vs/
.vs/
.vscode/
.direnv/
result

82
flake.lock generated Normal file
View File

@@ -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
}

58
flake.nix Normal file
View File

@@ -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";
};
});
};
}

40
nix/README.md Normal file
View File

@@ -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
};
}
```

46
nix/default.nix Normal file
View File

@@ -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;
};
}

50
nix/hm-module.nix Normal file
View File

@@ -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
];
};
}

1
shell.nix Normal file
View File

@@ -0,0 +1 @@
(builtins.getFlake ("git+file://" + toString ./.)).devShells.${builtins.currentSystem}.default