about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/python-modules/dnf4/default.nix
blob: c9b7e5113b8c93435dc2dddf091cbd4e0804075e (plain) (blame)
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
{ lib
, buildPythonPackage
, cmake
, fetchFromGitHub
, gettext
, libcomps
, libdnf
, python
, rpm
, sphinx
}:

let
  pyMajor = lib.versions.major python.version;
in

buildPythonPackage rec {
  pname = "dnf4";
  version = "4.19.0";
  format = "other";

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

  src = fetchFromGitHub {
    owner = "rpm-software-management";
    repo = "dnf";
    rev = version;
    hash = "sha256-LY2D3A3la58/8V2zKqPZWbR5iAMkrsG36gP8EvwANaA=";
  };

  patches = [
    ./fix-python-install-dir.patch
  ];

  postPatch = ''
    substituteInPlace CMakeLists.txt \
      --replace "@PYTHON_INSTALL_DIR@" "$out/${python.sitePackages}" \
      --replace "SYSCONFDIR /etc" "SYSCONFDIR $out/etc" \
      --replace "SYSTEMD_DIR /usr/lib/systemd/system" "SYSTEMD_DIR $out/lib/systemd/system"
    substituteInPlace etc/tmpfiles.d/CMakeLists.txt \
      --replace "DESTINATION /usr/lib/tmpfiles.d" "DESTINATION $out/usr/lib/tmpfiles.d"
    substituteInPlace dnf/const.py.in \
      --replace "/etc" "$out/etc" \
      --replace "/var/tmp" "/tmp"
    substituteInPlace doc/CMakeLists.txt \
      --replace 'SPHINX_BUILD_NAME "sphinx-build-3"' 'SPHINX_BUILD_NAME "${sphinx}/bin/sphinx-build"'
  '';

  nativeBuildInputs = [
    cmake
    gettext
    sphinx
  ];

  propagatedBuildInputs = [
    libcomps
    libdnf
    rpm
  ];

  cmakeFlags = [
    "-DPYTHON_DESIRED=${pyMajor}"
  ];

  dontWrapPythonPrograms = true;

  postBuild = ''
    make doc-man
  '';

  postInstall = ''
    # See https://github.com/rpm-software-management/dnf/blob/41a287e2bd60b4d1100c329a274776ff32ba8740/dnf.spec#L218-L220
    ln -s dnf-${pyMajor} $out/bin/dnf
    ln -s dnf-${pyMajor} $out/bin/dnf4
    mv $out/bin/dnf-automatic-${pyMajor} $out/bin/dnf-automatic

    # See https://github.com/rpm-software-management/dnf/blob/41a287e2bd60b4d1100c329a274776ff32ba8740/dnf.spec#L231-L232
    ln -s $out/etc/dnf/dnf.conf $out/etc/yum.conf
    ln -s dnf-${pyMajor} $out/bin/yum

    mkdir -p $out/share/bash-completion/completions
    mv $out/etc/bash_completion.d/dnf $out/share/bash-completion/completions/dnf
    rm -r $out/etc/bash_completion.d
  '';

  postFixup = ''
    moveToOutput "lib/${python.libPrefix}" "$py"
  '';

  meta = with lib; {
    description = "Package manager based on libdnf and libsolv. Replaces YUM";
    homepage = "https://github.com/rpm-software-management/dnf";
    changelog = "https://github.com/rpm-software-management/dnf/releases/tag/${version}";
    license = licenses.gpl2Only;
    maintainers = with maintainers; [ katexochen ];
    mainProgram = "dnf";
    platforms = platforms.unix;
  };
}