summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/tu/tuned/package.nix
blob: 53dcd7d20ea1cb1c710e42c6b5e1a4a32608f2dd (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
{
  lib,
  stdenv,
  asciidoctor,
  desktop-file-utils,
  dmidecode,
  ethtool,
  fetchFromGitHub,
  gawk,
  gobject-introspection,
  hdparm,
  iproute2,
  kmod,
  nix-update-script,
  nixosTests,
  pkg-config,
  powertop,
  python3Packages,
  tuna,
  util-linux,
  versionCheckHook,
  virt-what,
  wirelesstools,
  wrapGAppsHook3,
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "tuned";
  version = "2.27.0";

  outputs = [
    "out"
    "doc"
    "man"
  ];

  src = fetchFromGitHub {
    owner = "redhat-performance";
    repo = "tuned";
    tag = "v${finalAttrs.version}";
    hash = "sha256-PlF2T+EpveFkKPMU/6ZMXDO0q8Efzol4HJ4CX0wsBoY=";
  };

  patches = [
    # Some tests require a TTY to run
    ./remove-tty-tests.patch
  ];

  postPatch = ''
    patchShebangs .

    substituteInPlace tuned-gui.py tuned.service tuned/ppd/tuned-ppd.service \
      --replace-fail "/usr/sbin/" "$out/bin/"

    substituteInPlace tuned-gui.desktop \
      --replace-fail "/usr/sbin/tuned-gui" "tuned-gui"

    substituteInPlace experiments/powertop2tuned.py \
      --replace-fail "/usr/sbin/powertop" "${lib.getExe powertop}"

    substituteInPlace \
      tuned/{gtk/tuned_dialog.py,consts.py} tuned-gui.py tuned-adm.bash \
      $(find profiles/ -type f -executable -name '*.sh') \
      --replace-warn "/usr/share" "$out/share" \
      --replace-warn "/usr/lib" "$out/lib"
  '';

  strictDeps = true;

  nativeBuildInputs = [
    asciidoctor
    desktop-file-utils
    gobject-introspection
    pkg-config
    wrapGAppsHook3
    python3Packages.wrapPython
  ];

  propagatedBuildInputs = with python3Packages; [
    dbus-python
    pygobject3
    pyinotify
    pyperf
    python-linux-procfs
    pyudev
    tuna
  ];

  makeFlags = [
    "DESTDIR=${placeholder "out"}"
    "PREFIX="

    "PYTHON=${lib.getExe python3Packages.python}"
    "PYTHON_SITELIB=/${python3Packages.python.sitePackages}"
    "TMPFILESDIR=/lib/tmpfiles.d"
    "UNITDIR=/lib/systemd/system"
  ];

  installTargets = [
    "install"
    "install-ppd"
  ];

  dontWrapGApps = true;
  makeWrapperArgs = [
    "\${gappsWrapperArgs[@]}"
    "--prefix"
    "PATH"
    ":"
    (lib.makeBinPath [
      dmidecode
      ethtool
      gawk
      hdparm
      iproute2
      kmod
      util-linux
      virt-what
      wirelesstools
    ])
  ];

  doCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform;
  checkTarget = "test";

  doInstallCheck = true;
  nativeInstallCheckInputs = [
    python3Packages.pythonImportsCheckHook
    versionCheckHook
  ];

  pythonImportsCheck = [ "tuned" ];

  postInstall = ''
    rm -rf $out/{run,var}
  '';

  postFixup = ''
    wrapPythonPrograms
  '';

  passthru = {
    tests = lib.optionalAttrs stdenv.hostPlatform.isLinux {
      nixos = nixosTests.tuned;
    };
    updateScript = nix-update-script { };
  };

  meta = {
    description = "Tuning Profile Delivery Mechanism for Linux";
    homepage = "https://tuned-project.org";
    changelog = "https://github.com/redhat-performance/tuned/releases/tag/v${finalAttrs.version}";
    license = lib.licenses.gpl2Only;
    maintainers = with lib.maintainers; [ getchoo ];
    mainProgram = "tuned";
    platforms = lib.platforms.linux;
  };
})