summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/ke/keyd/package.nix
blob: 313cfa130fb6bd28cf8456a05b8160361462eb60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
{
  stdenv,
  lib,
  fetchFromGitHub,
  runtimeShell,
  python3Packages,
  versionCheckHook,
  nixosTests,
  nix-update-script,
}:
stdenv.mkDerivation (finalAttrs: {
  pname = "keyd";
  version = "2.6.0";

  __structuredAttrs = true;
  strictDeps = true;

  src = fetchFromGitHub {
    owner = "rvaiya";
    repo = "keyd";
    tag = "v${finalAttrs.version}";
    hash = "sha256-l7yjGpicX1ly4UwF7gcOTaaHPRnxVUMwZkH70NDLL5M=";
  };

  postPatch = ''
    substituteInPlace Makefile \
      --replace-fail /usr/local ""

    substituteInPlace keyd.service.in \
      --replace-fail @PREFIX@ $out
  '';

  installFlags = [ "DESTDIR=${placeholder "out"}" ];

  enableParallelBuilding = true;

  postInstall = ''
    ln -sf ${lib.getExe finalAttrs.passthru.appMap} $out/bin/${finalAttrs.passthru.appMap.pname}
    rm -rf $out/etc
  '';

  nativeInstallCheckInputs = [ versionCheckHook ];
  doInstallCheck = true;

  passthru = {
    tests.keyd = nixosTests.keyd;
    updateScript = nix-update-script { };
    appMap = python3Packages.buildPythonApplication (finalAttrsApp: {
      pname = "keyd-application-mapper";
      inherit (finalAttrs) version src;
      pyproject = false;

      postPatch = ''
        substituteInPlace scripts/${finalAttrsApp.pname} \
          --replace-fail /bin/sh ${runtimeShell}
      '';

      propagatedBuildInputs = with python3Packages; [
        python-xlib
        pygobject3.out
        dbus-python.out
      ];

      dontBuild = true;

      installPhase = ''
        install -Dm555 -t $out/bin scripts/${finalAttrsApp.pname}
      '';

      meta.mainProgram = "keyd-application-mapper";
    });
  };

  meta = {
    description = "Key remapping daemon for Linux";
    homepage = "https://github.com/rvaiya/keyd";
    changelog = "https://github.com/rvaiya/keyd/blob/master/docs/CHANGELOG.md";
    license = lib.licenses.mit;
    mainProgram = "keyd";
    maintainers = with lib.maintainers; [ alfarel ];
    platforms = lib.platforms.linux;
  };
})