nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 rustPlatform,
4 stdenv,
5 fetchFromGitHub,
6 pkg-config,
7 wrapGAppsHook4,
8 bashNonInteractive,
9 clinfo,
10 gdk-pixbuf,
11 gtk4,
12 libdrm,
13 ocl-icd,
14 vulkan-loader,
15 vulkan-tools,
16 coreutils,
17 systemdMinimal,
18 nix-update-script,
19 nixosTests,
20 hwdata,
21 fuse3,
22 autoAddDriverRunpath,
23}:
24
25rustPlatform.buildRustPackage (finalAttrs: {
26 pname = "lact";
27 version = "0.8.4";
28
29 src = fetchFromGitHub {
30 owner = "ilya-zlobintsev";
31 repo = "LACT";
32 tag = "v${finalAttrs.version}";
33 hash = "sha256-5z4IAiApUjlsSL0EX1PQH6rceeQxAD8f3CKmYO2x8gQ=";
34 };
35
36 cargoHash = "sha256-mCmAj9yLei0ZNtsBh+YeVlCmbHyT69LIHFnwbAk+Ido=";
37
38 nativeBuildInputs = [
39 pkg-config
40 wrapGAppsHook4
41 rustPlatform.bindgenHook
42 autoAddDriverRunpath
43 ];
44
45 buildInputs = [
46 gdk-pixbuf
47 gtk4
48 libdrm
49 ocl-icd
50 vulkan-loader
51 vulkan-tools
52 hwdata
53 fuse3
54 ];
55
56 # we do this here so that the binary is usable during integration tests
57 env.RUSTFLAGS = lib.optionalString stdenv.targetPlatform.isElf (
58 lib.concatStringsSep " " [
59 "-C link-arg=-Wl,-rpath,${
60 lib.makeLibraryPath [
61 vulkan-loader
62 libdrm
63 ocl-icd
64 ]
65 }"
66 "-C link-arg=-Wl,--add-needed,${vulkan-loader}/lib/libvulkan.so"
67 "-C link-arg=-Wl,--add-needed,${libdrm}/lib/libdrm.so"
68 "-C link-arg=-Wl,--add-needed,${ocl-icd}/lib/libOpenCL.so"
69 ]
70 );
71
72 postPatch = ''
73 substituteInPlace lact-daemon/src/server/handler.rs \
74 --replace-fail 'run_command("journalctl",' 'run_command("${systemdMinimal}/bin/journalctl",'
75
76 substituteInPlace lact-daemon/src/server/handler.rs \
77 --replace-fail 'Command::new("sh")' 'Command::new("${bashNonInteractive}/bin/bash")'
78
79 substituteInPlace lact-daemon/src/server/handler.rs \
80 --replace-fail 'Command::new("clinfo")' 'Command::new("${clinfo}/bin/clinfo")'
81
82 substituteInPlace lact-daemon/src/server/vulkan.rs \
83 --replace-fail 'Command::new("vulkaninfo")' 'Command::new("${vulkan-tools}/bin/vulkaninfo")'
84
85 substituteInPlace lact-daemon/src/server/opencl.rs \
86 --replace-fail 'Command::new("clinfo")' 'Command::new("${clinfo}/bin/clinfo")'
87
88
89 substituteInPlace lact-daemon/src/socket.rs \
90 --replace-fail 'run_command("chown"' 'run_command("${coreutils}/bin/chown"'
91
92 substituteInPlace res/lactd.service \
93 --replace-fail ExecStart={lact,$out/bin/lact}
94
95 # read() looks for the database in /usr/share so we use read_from_file() instead
96 substituteInPlace lact-daemon/src/server/handler.rs \
97 --replace-fail 'Database::read()' 'Database::read_from_file("${hwdata}/share/hwdata/pci.ids")'
98 '';
99
100 postInstall = ''
101 install -Dm444 res/lactd.service -t $out/lib/systemd/system
102 install -Dm444 res/io.github.ilya_zlobintsev.LACT.desktop -t $out/share/applications
103 install -Dm444 res/io.github.ilya_zlobintsev.LACT.svg -t $out/share/pixmaps
104 '';
105
106 preFixup = ''
107 gappsWrapperArgs+=(
108 --prefix PATH : "${lib.makeBinPath [ vulkan-tools ]}"
109 )
110 '';
111
112 postFixup = lib.optionalString stdenv.targetPlatform.isElf ''
113 patchelf $out/bin/.lact-wrapped \
114 --add-needed libvulkan.so \
115 --add-needed libdrm.so \
116 --add-needed libOpenCL.so \
117 --add-rpath ${
118 lib.makeLibraryPath [
119 vulkan-loader
120 libdrm
121 ocl-icd
122 ]
123 }
124 '';
125
126 passthru.updateScript = nix-update-script { };
127 passthru.tests = {
128 inherit (nixosTests) lact;
129 };
130
131 meta = {
132 description = "Linux GPU Configuration Tool for AMD and NVIDIA";
133 homepage = "https://github.com/ilya-zlobintsev/LACT";
134 license = lib.licenses.mit;
135 maintainers = with lib.maintainers; [
136 atemu
137 cything
138 johnrtitor
139 ];
140 platforms = lib.platforms.linux;
141 mainProgram = "lact";
142 };
143})