1{
2 lib,
3 buildPythonPackage,
4 cmake,
5 fetchFromGitHub,
6 gettext,
7 libcomps,
8 libdnf,
9 python,
10 rpm,
11 sphinx,
12 nix-update-script,
13}:
14
15let
16 pyMajor = lib.versions.major python.version;
17in
18
19buildPythonPackage rec {
20 pname = "dnf4";
21 version = "4.23.0";
22 format = "other";
23
24 outputs = [
25 "out"
26 "man"
27 "py"
28 ];
29
30 src = fetchFromGitHub {
31 owner = "rpm-software-management";
32 repo = "dnf";
33 tag = version;
34 hash = "sha256-qlOnFtEURhyxfsprhRaYUj141vZJp8qMjLpP1wGxikw=";
35 };
36
37 patches = [ ./fix-python-install-dir.patch ];
38
39 postPatch = ''
40 substituteInPlace CMakeLists.txt \
41 --replace "@PYTHON_INSTALL_DIR@" "$out/${python.sitePackages}" \
42 --replace "SYSCONFDIR /etc" "SYSCONFDIR $out/etc" \
43 --replace "SYSTEMD_DIR /usr/lib/systemd/system" "SYSTEMD_DIR $out/lib/systemd/system"
44 substituteInPlace etc/tmpfiles.d/CMakeLists.txt \
45 --replace "DESTINATION /usr/lib/tmpfiles.d" "DESTINATION $out/usr/lib/tmpfiles.d"
46 substituteInPlace dnf/const.py.in \
47 --replace "/etc" "$out/etc" \
48 --replace "/var/tmp" "/tmp"
49 substituteInPlace doc/CMakeLists.txt \
50 --replace 'SPHINX_BUILD_NAME "sphinx-build-3"' 'SPHINX_BUILD_NAME "${sphinx}/bin/sphinx-build"'
51 '';
52
53 nativeBuildInputs = [
54 cmake
55 gettext
56 sphinx
57 ];
58
59 propagatedBuildInputs = [
60 libcomps
61 libdnf
62 rpm
63 ];
64
65 cmakeFlags = [ "-DPYTHON_DESIRED=${pyMajor}" ];
66
67 dontWrapPythonPrograms = true;
68
69 postBuild = ''
70 make doc-man
71 '';
72
73 postInstall = ''
74 # See https://github.com/rpm-software-management/dnf/blob/41a287e2bd60b4d1100c329a274776ff32ba8740/dnf.spec#L218-L220
75 ln -s dnf-${pyMajor} $out/bin/dnf
76 ln -s dnf-${pyMajor} $out/bin/dnf4
77 mv $out/bin/dnf-automatic-${pyMajor} $out/bin/dnf-automatic
78
79 # See https://github.com/rpm-software-management/dnf/blob/41a287e2bd60b4d1100c329a274776ff32ba8740/dnf.spec#L231-L232
80 ln -s $out/etc/dnf/dnf.conf $out/etc/yum.conf
81 ln -s dnf-${pyMajor} $out/bin/yum
82
83 mkdir -p $out/share/bash-completion/completions
84 mv $out/etc/bash_completion.d/dnf-3 $out/share/bash-completion/completions/dnf4
85 ln -s $out/share/bash-completion/completions/dnf4 $out/share/bash-completion/completions/dnf
86 rm -r $out/etc/bash_completion.d
87 '';
88
89 postFixup = ''
90 moveToOutput "lib/${python.libPrefix}" "$py"
91 '';
92
93 passthru.updateScript = nix-update-script { };
94
95 meta = with lib; {
96 description = "Package manager based on libdnf and libsolv. Replaces YUM";
97 homepage = "https://github.com/rpm-software-management/dnf";
98 changelog = "https://github.com/rpm-software-management/dnf/releases/tag/${version}";
99 license = licenses.gpl2Only;
100 maintainers = with maintainers; [ katexochen ];
101 mainProgram = "dnf";
102 platforms = platforms.unix;
103 };
104}