summaryrefslogtreecommitdiff
path: root/pkgs/warcPackages/wget-lua/default.nix
blob: 6dfd642a57b0a7bd7b7358e686463860e4ed88b5 (about) (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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# SPDX-FileCopyrightText: 2025 OrIdow6
# SPDX-License-Identifier: GPL-3.0-or-later

{
  basex,
  autoconf-archive,
  autoreconfHook,
  c-ares,
  coreutils,
  fetchFromGitHub,
  fetchurl,
  flex,
  gettext,
  gnulib,
  gnutls,
  gperf,
  lib,
  libiconv,
  libidn2,
  libintl,
  libpsl,
  libuuid,
  lua51Packages,
  lzip,
  makeBinaryWrapper,
  nukeReferences,
  pcre2,
  perlPackages,
  pkg-config,
  stdenv,
  texinfo,
  writeText,
  zlib,
  zstd,
  brotli,
}:

let
  luaEnv = lua51Packages.lua.withPackages (
    ps: with ps; [
      luasocket
      luafilesystem
      luasec
      luazip
      #crc32
      #md5
      #base64
      cjson
      # luautf8 is a newer version of utf8;
      # the canonical DF uses the latter
      # so I assemble it manually here,
      # but I import the former anyway
      # -- OrIdow6
      (buildLuarocksPackage {
        pname = "utf8";
        version = "0.2.0-1";
        knownRockspec =
          (fetchurl {
            url = "mirror://luarocks/utf8-1.3-0.rockspec";
            sha256 = "sha256-V4otUR+uDIHTIBgfdgmdgMG4Y3knZ+w5ztv7EhbP+us=";
          }).outPath;
        src = fetchFromGitHub {
          owner = "dannote";
          repo = "luautf8";
          rev = "f36cc914ae9015cd3045987abadd83bbcfae98f0";
          sha256 = "sha256-xLWqglAzqcxY+R8GOC+D3uzL2+9ZriEx8Kj41LkI5vU=";
        };

        disabled = luaOlder "5.1";

        meta = {
          homepage = "https://github.com/dannote/luautf8";
          description = "A UTF-8 support module for Lua";
          license = lib.licenses.mit;
        };
      })
      luautf8
      luabitop
      bit32
      luaossl
      zlib
      basex
    ]
  );
in
stdenv.mkDerivation {
  pname = "wget-at";
  version = "1.21.3-at.20260319.01";

  src = fetchFromGitHub {
    owner = "archiveteam";
    repo = "wget-lua";
    rev = "e8cfe0a4ddb8a152971e5d0e22dc3f15f0080109";
    hash = "sha256-zE8hA8RI9q2JBDvzIYWP56uNV7rXwvTOCggdh7I+5Fg=";
  };

  preConfigure = ''
    patchShebangs doc
  '';

  nativeBuildInputs = [
    gettext
    pkg-config
    perlPackages.perl
    lzip
    nukeReferences
    autoreconfHook
    autoconf-archive
    flex
    gperf
    texinfo
    makeBinaryWrapper
  ];
  buildInputs = [
    libidn2
    zlib
    pcre2
    libuuid
    libiconv
    libintl
    luaEnv
    c-ares
    zstd
    brotli
    gnutls
    libpsl
    gnulib
  ];

  # Taken from the wget2.nix in nixpkgs
  autoreconfPhase = ''
    # copy gnulib into build dir and make writable.
    # Otherwise ./bootstrap copies the non-writable files from nix store and fails to modify them
    rmdir gnulib
    cp -r ${gnulib} gnulib
    chmod -R u+w gnulib/{build-aux,lib}

    ./bootstrap --no-git --gnulib-srcdir=gnulib --skip-po
  '';

  strictDeps = true;

  configureFlags = [
    "--with-cares"
  ];

  preBuild = ''
    # avoid runtime references to build-only depends
    make -C src version.c
    nuke-refs src/version.c
  '';

  patches = [
    (writeText "lua-search-for-cmake-package.patch" ''
      	  diff --git a/configure.ac b/configure.ac
      index 8e0a8a9b..63dd1d22 100644
      --- a/configure.ac
      +++ b/configure.ac
      @@ -1053,6 +1053,11 @@ AS_IF(
       
       AS_IF(
         [test "X$enable_luajit" != "Xyes"],
      +  [PKG_CHECK_MODULES([LUA], lua5.1, [
      +    CFLAGS="$LUA_CFLAGS $CFLAGS"
      +    LIBS="$LUA_LIBS $LIBS"
      +    AC_DEFINE([ENABLE_LUA], 1, [Define if Lua is available.])
      +  ],
         [
           AC_CHECK_HEADER(
             lua5.1/lua.h,
      @@ -1072,6 +1077,8 @@ AS_IF(
             AC_MSG_ERROR([lua not found])
           )
         ]
      +  )
      +  ]
       )
       
       AS_IF(
    '')
    # I cannot figure out why it tries to "make" something in this directory *after* the main wget binary is built, which then crashes for reasons I also don't understand. So just ignoring it for now. This also happens if I try to run the vanilla wget build here from Git instead of from the release tarball.
    (writeText "do-not-make-gnulib-po.patch" ''
          diff --git a/Makefile.am b/Makefile.am
      index 5e3f1d18..d9f64bd4 100644
      --- a/Makefile.am
      +++ b/Makefile.am
      @@ -40,7 +40,7 @@ distuninstallcheck_listfiles = find . -type f | \
       ACLOCAL_AMFLAGS = -I m4
       
       # subdirectories in the distribution
      -SUBDIRS = lib src doc po gnulib_po util fuzz tests testenv
      +SUBDIRS = lib src doc po util fuzz tests testenv
       
       EXTRA_DIST = MAILING-LIST \
                    msdos/config.h msdos/Makefile.DJ \

    '')
  ];

  postInstall = ''
    wrapProgram $out/bin/wget \
      --prefix LUA_CPATH ';' "${luaEnv}/lib/lua/${luaEnv.luaversion}/?.so" \
      --prefix LUA_PATH ';' "${luaEnv}/share/lua/${luaEnv.luaversion}/?.lua" \
      --prefix PATH ':' ${lib.makeBinPath [ coreutils ]} # For sleep, but bring in the other programs too in case something uses them
  '';

  enableParallelBuilding = true;

  meta = {
    description = "Tool for retrieving files using HTTP, HTTPS, and FTP AT version";
    homepage = "https://www.gnu.org/software/wget/";
    license = lib.licenses.gpl3Plus;
    mainProgram = "wget";
    platforms = lib.platforms.all;
  };
}