summaryrefslogtreecommitdiff
path: root/pkgs/tools/misc/file/default.nix
blob: ae27a481b38ff0e35b1392b9b4d8d234a3f57677 (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
{
  lib,
  stdenv,
  fetchurl,
  buildPackages,
  zlib,
  libgnurx,
  updateAutotoolsGnuConfigScriptsHook,
  testers,
}:

# Note: this package is used for bootstrapping fetchurl, and thus
# cannot use fetchpatch! All mutable patches (generated by GitHub or
# cgit) that are needed here should be included directly in Nixpkgs as
# files.

stdenv.mkDerivation (finalAttrs: {
  pname = "file";
  version = "5.47";

  src = fetchurl {
    urls = [
      "https://astron.com/pub/file/file-${finalAttrs.version}.tar.gz"
      "https://distfiles.macports.org/file/file-${finalAttrs.version}.tar.gz"
    ];
    hash = "sha256-RWcv7BZctMwTWKLXa11X0ih23Ll6sWlCesOFy+HVWXo=";
  };

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

  patches = [
    # Fixes `cat archive.zip | file -` just showing a generic "data" type. See:
    # - https://bugs.astron.com/view.php?id=764
    # - https://github.com/file/file/commit/12b76648185104ce9118d8b5fa57aa34a77ad084
    # Vendored patch because using fetchpatch is impossible for a package in
    # this part of the bootstrap chain.
    ./0001-PR-745-streamout-Don-t-flush-when-trying-to-set-nega.patch
    # Fixes breakage of python3Packages.python-magic and xdg-utils
    ./0002-PR-725-inliniac-Revert-previous-and-always-set-offse.patch
  ];

  strictDeps = true;
  enableParallelBuilding = true;

  nativeBuildInputs = [
    updateAutotoolsGnuConfigScriptsHook
  ];
  buildInputs = [ zlib ] ++ lib.optional stdenv.hostPlatform.isMinGW libgnurx;

  # https://bugs.astron.com/view.php?id=382
  doCheck = !stdenv.buildPlatform.isMusl;

  # In native builds, it will use the newly-compiled file instead.
  makeFlags = lib.optional (
    !lib.systems.equals stdenv.hostPlatform stdenv.buildPlatform
  ) "FILE_COMPILE=${lib.getExe buildPackages.file}";

  passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;

  meta = {
    homepage = "https://darwinsys.com/file";
    description = "Program that shows the type of files";
    maintainers = with lib.maintainers; [ doronbehar ];
    license = lib.licenses.bsd2;
    pkgConfigModules = [ "libmagic" ];
    platforms = lib.platforms.all;
    mainProgram = "file";
  };
})