Skip to content

Commit

Permalink
feat: add nix support(#80) (#82)
Browse files Browse the repository at this point in the history
* feat: add nix support(#80)

* chore: nix flake update

* update actions
  • Loading branch information
ICE-GB committed Mar 15, 2024
1 parent abf95af commit 8ff991a
Show file tree
Hide file tree
Showing 9 changed files with 306 additions and 1 deletion.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
24 changes: 24 additions & 0 deletions .github/workflows/cachix.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/target
.gdbinit
.idea/
.vs/
.vs/
.vscode/
.direnv/
result
82 changes: 82 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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 changes: 40 additions & 0 deletions nix/README.md
Original file line number Diff line number Diff line change
@@ -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 changes: 46 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -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 changes: 50 additions & 0 deletions nix/hm-module.nix
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(builtins.getFlake ("git+file://" + toString ./.)).devShells.${builtins.currentSystem}.default

0 comments on commit 8ff991a

Please sign in to comment.