Commit 92a76e7c authored by emaryn's avatar emaryn Committed by emaryn
Browse files
parent 70646658
Loading
Loading
Loading
Loading
+61 −53
Original line number Diff line number Diff line
{
  lib,
  buildPythonApplication,
  fetchFromGitHub,
  pkgconfig,
  wrapGAppsHook3,
  gettext,
@@ -14,10 +16,9 @@
  pydantic,
  pydbus,
  psutil,
  fetchFromGitHub,
  buildPythonApplication,
  procps,
  gtksourceview4,
  bash,
  nixosTests,
  # Change the default log level to debug for easier debugging of package issues
  withDebugLogLevel ? false,
@@ -36,40 +37,84 @@ let
in
(buildPythonApplication rec {
  pname = "input-remapper";
  version = "2.0.1";
  version = "2.1.1";

  src = fetchFromGitHub {
    owner = "sezanzeb";
    repo = "input-remapper";
    rev = version;
    hash = "sha256-rwlVGF/cWSv6Bsvhrs6nMDQ8avYT80aasrhWyQv55/A=";
    tag = version;
    hash = "sha256-GMKcs2UK1yegGT/TBsLGgTBJROQ38M6WwnLbJIuAZwg=";
  };

  postPatch =
    ''
      # fix FHS paths
      substituteInPlace inputremapper/configs/data.py \
        --replace "/usr/share"  "$out/usr/share"
        --replace-fail "/usr/share"  "$out/usr/share"
    ''
    + lib.optionalString withDebugLogLevel ''
      # if debugging
      substituteInPlace inputremapper/logger.py --replace "logger.setLevel(logging.INFO)"  "logger.setLevel(logging.DEBUG)"
      substituteInPlace inputremapper/logger.py \
        --replace-fail "logger.setLevel(logging.INFO)"  "logger.setLevel(logging.DEBUG)"
    '';

  doCheck = withDoCheck;
  nativeCheckInputs = [
  nativeBuildInputs = [
    wrapGAppsHook3
    gettext # needed to build translations
    gtk3
    glib
    gobject-introspection
    pygobject3
  ] ++ maybeXmodmap;

  dependencies = [
    setuptools # needs pkg_resources
    pygobject3
    evdev
    pkgconfig
    pydantic
    pydbus
    gtksourceview4
    psutil
  ];

  doCheck = withDoCheck;

  nativeCheckInputs = [ psutil ];

  pythonImportsCheck = [
    "evdev"
    "inputremapper"
  ];

  postInstall = ''
    substituteInPlace data/99-input-remapper.rules \
      --replace-fail 'RUN+="/bin/input-remapper-control' "RUN+=\"$out/bin/input-remapper-control"
    substituteInPlace data/input-remapper.service \
      --replace-fail "ExecStart=/usr/bin/input-remapper-service" "ExecStart=$out/bin/input-remapper-service"
    substituteInPlace data/input-remapper-autoload.desktop \
      --replace-fail "bash" "${lib.getExe bash}"

    install -m644 -D -t $out/share/applications/ data/*.desktop
    install -m644 -D -t $out/share/polkit-1/actions/ data/input-remapper.policy
    install -m644 -D data/99-input-remapper.rules $out/etc/udev/rules.d/99-input-remapper.rules
    install -m644 -D data/input-remapper.service $out/lib/systemd/system/input-remapper.service
    install -m644 -D data/input-remapper.policy $out/share/polkit-1/actions/input-remapper.policy
    install -m644 -D data/inputremapper.Control.conf $out/etc/dbus-1/system.d/inputremapper.Control.conf
    install -m644 -D data/input-remapper.svg $out/share/icons/hicolor/scalable/apps/input-remapper.svg
    install -m644 -D -t $out/usr/share/input-remapper/ data/*

    # Only install input-remapper prefixed binaries, we don't care about deprecated key-mapper ones
    install -m755 -D -t $out/bin/ bin/input-remapper*
  '';

  # Custom test script, can't use plain pytest / pytestCheckHook
  # We only run tests in the unit folder, integration tests require UI
  # To allow tests which access the system and session DBUS to run, we start a dbus session
  # and bind it to both the system and session buses
  installCheckPhase = ''
    runHook preInstallCheck

    echo "<busconfig>
      <type>session</type>
      <listen>unix:tmpdir=$TMPDIR</listen>
@@ -97,10 +142,13 @@ in
      DBUS_SYSTEM_BUS_ADDRESS=unix:path=/build/system_bus_socket \
      ${dbus}/bin/dbus-run-session --config-file dbus.cfg \
      python tests/test.py --start-dir unit

    runHook postInstallCheck
  '';

  # Nixpkgs 15.9.4.3. When using wrapGAppsHook3 with special derivers you can end up with double wrapped binaries.
  dontWrapGApps = true;

  preFixup = ''
    makeWrapperArgs+=(
      "''${gappsWrapperArgs[@]}"
@@ -108,54 +156,14 @@ in
    )
  '';

  nativeBuildInputs = [
    wrapGAppsHook3
    gettext # needed to build translations
    gtk3
    glib
    gobject-introspection
    pygobject3
  ] ++ maybeXmodmap;

  propagatedBuildInputs = [
    setuptools # needs pkg_resources
    pygobject3
    evdev
    pkgconfig
    pydantic
    pydbus
    gtksourceview4
  ];

  postInstall = ''
    substituteInPlace data/99-input-remapper.rules \
      --replace-fail 'RUN+="/bin/input-remapper-control' "RUN+=\"$out/bin/input-remapper-control"
    substituteInPlace data/input-remapper.service \
      --replace-fail 'ExecStart=/usr/bin/input-remapper-service' "ExecStart=$out/bin/input-remapper-service"
    substituteInPlace data/input-remapper-*.desktop \
      --replace-fail 'Icon=/usr/share/input-remapper/input-remapper.svg' 'Icon=input-remapper.svg'

    install -m644 -D -t $out/share/applications/ data/*.desktop
    install -m644 -D -t $out/share/polkit-1/actions/ data/input-remapper.policy
    install -m644 -D data/99-input-remapper.rules $out/etc/udev/rules.d/99-input-remapper.rules
    install -m644 -D data/input-remapper.service $out/lib/systemd/system/input-remapper.service
    install -m644 -D data/input-remapper.policy $out/share/polkit-1/actions/input-remapper.policy
    install -m644 -D data/inputremapper.Control.conf $out/etc/dbus-1/system.d/inputremapper.Control.conf
    install -m644 -D data/input-remapper.svg $out/share/icons/hicolor/scalable/apps/input-remapper.svg
    install -m644 -D -t $out/usr/share/input-remapper/ data/*

    # Only install input-remapper prefixed binaries, we don't care about deprecated key-mapper ones
    install -m755 -D -t $out/bin/ bin/input-remapper*
  '';

  passthru.tests = nixosTests.input-remapper;

  meta = with lib; {
  meta = {
    description = "Easy to use tool to change the mapping of your input device buttons";
    homepage = "https://github.com/sezanzeb/input-remapper";
    license = licenses.gpl3Plus;
    platforms = platforms.linux;
    maintainers = with maintainers; [ LunNova ];
    license = lib.licenses.gpl3Plus;
    platforms = lib.platforms.linux;
    maintainers = with lib.maintainers; [ LunNova ];
    mainProgram = "input-remapper-gtk";
  };
}).overrideAttrs