summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/tz/tzdata/package.nix
blob: 7e3f8f38535d1dd23f132a411d41af67fd82f29a (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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
{
  lib,
  stdenv,
  fetchurl,
  buildPackages,
  postgresql,
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "tzdata";
  version = "2026c";

  srcs = [
    (fetchurl {
      url = "https://data.iana.org/time-zones/releases/tzdata${finalAttrs.version}.tar.gz";
      hash = "sha256-5KF4pEd/PQ6nfMMYKP9yqjj+/41hqhPn6Z4ULp2QK+Q=";
    })
    (fetchurl {
      url = "https://data.iana.org/time-zones/releases/tzcode${finalAttrs.version}.tar.gz";
      hash = "sha256-sc/8Os5MTHzQ77ovet2G7D0LedpIvPA1gmcf08j+rOg=";
    })
  ];

  sourceRoot = ".";

  patches = lib.optionals (stdenv.hostPlatform.isWindows || stdenv.hostPlatform.isCygwin) [
    ./0001-Add-exe-extension-for-MS-Windows-binaries.patch
  ];

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

  strictDeps = true;

  makeFlags = [
    "TOPDIR=${placeholder "out"}"
    "TZDIR=${placeholder "out"}/share/zoneinfo"
    "BINDIR=${placeholder "bin"}/bin"
    "ZICDIR=${placeholder "bin"}/bin"
    "ETCDIR=$(TMPDIR)/etc"
    "TZDEFAULT=tzdefault-to-remove"
    "LIBDIR=${placeholder "dev"}/lib"
    "MANDIR=${placeholder "man"}/share/man"
    "AWK=awk"
    "CURL=:" # disable network access
    "CFLAGS=-DHAVE_LINK=0"
    "CFLAGS+=-DZIC_BLOAT_DEFAULT=\\\"fat\\\""
    "cc=${stdenv.cc.targetPrefix}cc"
    "AR=${stdenv.cc.targetPrefix}ar"
    "REDO=posix_right"
  ]
  ++ lib.optionals stdenv.hostPlatform.isWindows [
    "CFLAGS+=-DHAVE_DIRECT_H"
    "CFLAGS+=-DHAVE_FCHMOD=0"
    "CFLAGS+=-DHAVE_GETEUID=0"
    "CFLAGS+=-DHAVE_GETRESUID=0"
    "CFLAGS+=-DHAVE_MEMPCPY=1"
    "CFLAGS+=-DHAVE_SETENV=0"
    "CFLAGS+=-DHAVE_STRUCT_STAT_ST_CTIM=0"
    "CFLAGS+=-DHAVE_SYMLINK=0"
    "CFLAGS+=-DRESERVE_STD_EXT_IDS"
    # sys/stat.h does exist on Windows for us
    "CFLAGS+=-DHAVE_SYS_STAT_H=1"
    # It is called st_ctime on windows, this forces that
    # choice
    "CFLAGS+=-DHAVE_STRUCT_STAT_ST_CTIM=0"
    "CFLAGS+=-DHAVE_MEMPCPY=1"
    "CFLAGS+=-DHAVE_GETRESUID=0"
    "CFLAGS+=-DHAVE_GETEUID=0"
    "CFLAGS+=-DHAVE_FCHMOD=0"
  ]
  ++ lib.optionals stdenv.hostPlatform.isCygwin [
    "CFLAGS+=-DHAVE_GETRESUID=0"
    "CFLAGS+=-DHAVE_ISSETUGID=1"
  ]
  ++ lib.optionals stdenv.hostPlatform.isFreeBSD [
    "CFLAGS+=-DNETBSD_INSPIRED=0"
    "CFLAGS+=-DSTD_INSPIRED=0"
    "CFLAGS+=-DUSE_TIMEX_T=1"
    "CFLAGS+=-DMKTIME_FITS_IN\\(min,max\\)=0"
    "CFLAGS+=-DEXTERN_TIMEOFF=1"
  ];

  enableParallelBuilding = true;

  doCheck = true;
  checkTarget = "check";

  installFlags = lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
    "zic=${buildPackages.tzdata.bin}/bin/zic"
  ];

  postInstall = ''
    rm $out/share/zoneinfo-posix
    rm $out/share/zoneinfo/tzdefault-to-remove
    mkdir $out/share/zoneinfo/posix
    ( cd $out/share/zoneinfo/posix; ln -s ../* .; rm posix )
    mv $out/share/zoneinfo-leaps $out/share/zoneinfo/right

    cp leap-seconds.list $out/share/zoneinfo

    mkdir -p "$dev/include"
    cp tzfile.h "$dev/include/tzfile.h"
  '';

  setupHook = ./tzdata-setup-hook.sh;

  # PostgreSQL is sensitive to tzdata updates, because the test-suite often breaks.
  # Upstream provides patches very quickly, we just need to apply them until the next
  # minor releases.
  passthru.tests = postgresql;

  __structuredAttrs = true;

  meta = {
    homepage = "http://www.iana.org/time-zones";
    description = "Database of current and historical time zones";
    changelog = "https://github.com/eggert/tz/blob/${finalAttrs.version}/NEWS";
    license = with lib.licenses; [
      bsd3 # tzcode
      publicDomain # tzdata
    ];
    platforms = lib.platforms.all;
    maintainers = with lib.maintainers; [
      ajs124
      fpletz
    ];
  };
})