diff --git a/flake.nix b/flake.nix index 7176ec7..2f57e12 100644 --- a/flake.nix +++ b/flake.nix @@ -39,6 +39,7 @@ nixosModules = { reposilite = import ./modules/reposilite.nix; + asus-numpad = import ./modules/asus-numpad.nix self; }; }; }; diff --git a/modules/asus-numpad.nix b/modules/asus-numpad.nix new file mode 100644 index 0000000..e52ded2 --- /dev/null +++ b/modules/asus-numpad.nix @@ -0,0 +1,53 @@ +self: { + lib, + config, + pkgs, + ... +}: let + cfg = config.services.asus-numpad; + inherit (pkgs.stdenv.hostPlatform) system; + + toml = pkgs.formats.toml {}; +in { + options.services.asus-numpad = { + enable = lib.mkEnableOption "asus-numpad"; + package = lib.mkPackageOption self.packages.${system} "asus-numpad" {}; + + settings = lib.mkOption { + description = "Options for the configuration file located at /etc/xdg/asus_numpad.toml. See https://github.com/iamkroot/asus-numpad#configuration"; + example = {layout = "M433IA";}; + type = lib.types.submodule { + freeformType = toml.type; + + options.layout = lib.mkOption { + description = "Numpad key layout."; + type = lib.types.enum ["UX433FA" "M433IA" "UX581" "GX701" "GX531" "G533"]; + }; + }; + }; + }; + + config = lib.mkIf cfg.enable { + hardware = { + i2c.enable = true; + uinput.enable = true; + }; + + environment.etc."xdg/asus_numpad.toml".source = toml.generate "asus_numpad.toml" cfg.settings; + + systemd.services.asus-numpad = { + enable = true; + wantedBy = ["multi-user.target"]; + script = '' + ${lib.getExe cfg.package} + ''; + + serviceConfig = { + Type = "simple"; + Restart = "on-failure"; + RestartSec = "5s"; + TimeoutSec = "5s"; + }; + }; + }; +} diff --git a/pkgs/all-packages.nix b/pkgs/all-packages.nix index e8738fc..b626747 100644 --- a/pkgs/all-packages.nix +++ b/pkgs/all-packages.nix @@ -2,4 +2,5 @@ final: prev: { enigma = prev.callPackage ./enigma.nix {}; vineflower = prev.callPackage ./vineflower.nix {}; koi = prev.kdePackages.callPackage ./koi.nix {}; + asus-numpad = prev.callPackage ./asus-numpad.nix {}; } diff --git a/pkgs/asus-numpad.nix b/pkgs/asus-numpad.nix new file mode 100644 index 0000000..e18289f --- /dev/null +++ b/pkgs/asus-numpad.nix @@ -0,0 +1,36 @@ +{ + lib, + fetchFromGitHub, + rustPlatform, + pkg-config, + libevdev, +}: +rustPlatform.buildRustPackage { + pname = "asus-numpad"; + version = "unstable-2024-09-15"; + + src = fetchFromGitHub { + owner = "iamkroot"; + repo = "asus-numpad"; + rev = "e78875c1f4c58e06199737f4ef5c6f48ac7cb21b"; + hash = "sha256-5FqM80zUDucDA0VocJ7ODmKAC6gcd9QwBOHVVKa6iMI="; + }; + + cargoHash = "sha256-O7Iu+ugJ81suh0a09jApyiWwxbo/RGaFW7aiZKnWQUE="; + + nativeBuildInputs = [ + pkg-config + ]; + + buildInputs = [ + libevdev + ]; + + meta = with lib; { + mainProgram = "asus-numpad"; + description = "Linux driver for Asus laptops to activate numpad on touchpad"; + homepage = "https://github.com/iamkroot/asus-numpad"; + license = licenses.mit; + platforms = platforms.linux; + }; +}