1{ lib, stdenv
2, fetchurl
3, pkg-config
4, glib
5, gpm
6, file
7, e2fsprogs
8, libX11
9, libICE
10, perl
11, zip
12, unzip
13, gettext
14, slang
15, libssh2
16, openssl
17, coreutils
18, autoreconfHook
19, autoSignDarwinBinariesHook
20}:
21
22stdenv.mkDerivation rec {
23 pname = "mc";
24 version = "4.8.27";
25
26 src = fetchurl {
27 url = "https://www.midnight-commander.org/downloads/${pname}-${version}.tar.xz";
28 sha256 = "sha256-Mb5ZIl/6mSCBbpqLO+CrIloW0Z5Pr0aJDyW9/6AqT/Q=";
29 };
30
31 nativeBuildInputs = [ pkg-config autoreconfHook unzip ]
32 # The preFixup hook rewrites the binary, which invaliates the code
33 # signature. Add the fixup hook to sign the output.
34 ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) [
35 autoSignDarwinBinariesHook
36 ];
37
38 buildInputs = [
39 file
40 gettext
41 glib
42 libICE
43 libX11
44 libssh2
45 openssl
46 perl
47 slang
48 zip
49 ] ++ lib.optionals (!stdenv.isDarwin) [ e2fsprogs gpm ];
50
51 enableParallelBuilding = true;
52
53 configureFlags = [ "--enable-vfs-smb" ];
54
55 postPatch = ''
56 substituteInPlace src/filemanager/ext.c \
57 --replace /bin/rm ${coreutils}/bin/rm
58 '';
59
60 preFixup = ''
61 # remove unwanted build-dependency references
62 sed -i -e "s!PKG_CONFIG_PATH=''${PKG_CONFIG_PATH}!PKG_CONFIG_PATH=$(echo "$PKG_CONFIG_PATH" | sed -e 's/./0/g')!" $out/bin/mc
63 '';
64
65 postFixup = lib.optionalString (!stdenv.isDarwin) ''
66 # libX11.so is loaded dynamically so autopatch doesn't detect it
67 patchelf \
68 --add-needed ${libX11}/lib/libX11.so \
69 $out/bin/mc
70 '';
71
72 meta = with lib; {
73 description = "File Manager and User Shell for the GNU Project";
74 downloadPage = "https://www.midnight-commander.org/downloads/";
75 homepage = "https://www.midnight-commander.org";
76 license = licenses.gpl2Plus;
77 maintainers = with maintainers; [ sander ];
78 platforms = with platforms; linux ++ darwin;
79 repositories.git = "https://github.com/MidnightCommander/mc.git";
80 updateWalker = true;
81 };
82}