File: flake.nix

package info (click to toggle)
ffmpegthumbnailer 2.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 904 kB
  • sloc: cpp: 11,154; ansic: 76; sh: 37; makefile: 11
file content (330 lines) | stat: -rw-r--r-- 11,627 bytes parent folder | download
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
{
  description = "ffmpegthumbnailer";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05";
  };

  outputs =
    { self, ... }@inputs:

    let
      supportedSystems = [
        "x86_64-linux"
        "aarch64-linux"
        "x86_64-darwin"
        "aarch64-darwin"
      ];

      forEachSupportedSystem =
        f:
        inputs.nixpkgs.lib.genAttrs supportedSystems (
          system:
          f {
            pkgs = import inputs.nixpkgs {
              inherit system;
            };

            pkgsStatic = import inputs.nixpkgs {
              inherit system;
            };

            pkgsWindows = (
              import inputs.nixpkgs {
                inherit system;
                crossSystem = {
                  config = "x86_64-w64-mingw32";
                };
                config = {
                  allowBroken = true;
                };
              }
            );
          }
        );
    in
    {
      packages = forEachSupportedSystem (
        {
          pkgs,
          pkgsStatic,
          pkgsWindows,
        }:
        let
          mkPackage =
            pkgsForBuild: pkgsForHost: isStatic: isWindows:
            let
              baseStdenv = pkgsForHost.stdenv;

              # On Windows, use win32 threads to get a fully static binary
              stdenv' =
                if isWindows && baseStdenv.cc.isGNU && baseStdenv.targetPlatform.isWindows then
                  let
                    buildPkgs = pkgsForHost.buildPackages;
                    gccWin32 = buildPkgs.wrapCC (
                      buildPkgs.gcc-unwrapped.override {
                        threadsCross = {
                          model = "win32";
                          package = null;
                        };
                      }
                    );
                  in
                  pkgsForHost.overrideCC baseStdenv gccWin32
                else
                  baseStdenv;

              # zlib-ng in zlib-compatible mode
              zlibNgCompat = pkgsForHost.zlib-ng.override {
                withZlibCompat = true;
              };

              # Use zlib-ng and force it to be static-only (we mainly care on Windows)
              zlibNgStatic = zlibNgCompat.overrideAttrs (old: {
                dontDisableStatic = true;
                cmakeFlags = (old.cmakeFlags or [ ]) ++ [
                  "-DBUILD_SHARED_LIBS=OFF"
                ];
              });

              # libpng that uses zlib-ng instead of plain zlib
              libpngWithZlibNg = pkgsForHost.libpng.override {
                zlib = zlibNgStatic;
              };

            in
            stdenv'.mkDerivation {
              pname = "ffmpegthumbnailer";
              version = "dev";

              src = ./.;

              nativeBuildInputs = with pkgsForBuild; [
                cmake
                ninja
                pkg-config
              ];

              buildInputs =
                with pkgsForHost;
                [
                  (
                    if isStatic || isWindows then
                      (ffmpeg-headless.override {
                        withGPL = true;
                        withShared = false;
                        withStatic = true;
                        zlib = zlibNgStatic;

                        # Disable CUDA/LLVM to avoid compiler-rt dependency
                        withCuda = false;
                        withCudaLLVM = false;
                        withCudaNVCC = false;
                        buildAvdevice = false;
                        buildSwresample = false;
                        buildFfmpeg = false;
                        buildFfplay = false;
                        buildFfprobe = false;
                        buildPostproc = false;
                        withBin = false;
                        withDocumentation = false;
                        withHtmlDoc = false;
                        withPodDoc = false;
                        withTxtDoc = false;
                        withManPages = false;
                        # Disable all audio dependencies (not needed for thumbnailing)
                        withPulse = false;
                        withAlsa = false;
                        withJack = false;
                        withSdl2 = false;
                        withOpenal = false;
                        withOpus = false;
                        withVorbis = false;
                        withMp3lame = false;
                        withSpeex = false;
                        withSoxr = false;
                        withAmf = false;
                        withCelt = false;
                        # Disable X11 for headless
                        withXcb = false;
                        withFontconfig = false;
                        withFreetype = false;
                        withAss = false;
                        withFribidi = false;
                        withHarfbuzz = false;
                        # Disable other unnecessary features
                        withSsh = false;
                        withSrt = false;
                        withBluray = false;
                        withOpencl = false;
                        withOpenmpt = false;
                        withVulkan = false;
                        withVaapi = false;
                        withVdpau = false;
                        # Disable gnutls to avoid gettext/libevent/unbound deps
                        withGnutls = false;
                        withVmaf = false;
                        withVidStab = false;
                        withRist = false;
                        withZvbi = false;
                        withAom = false;
                        withZimg = false;
                        withOpenjpeg = false;
                        withV4l2 = false;
                        withDrm = false;
                        # only needed for dash demuxing
                        withXml2 = false;
                        # These deps are only needed for encoding
                        withWebp = false;
                        withTheora = false;
                        withX264 = false;
                        withX265 = false;
                        withXvid = false;
                        withSvtav1 = false;
                        # Disable dav1d for static macOS builds
                        withDav1d = if (isStatic && stdenv'.isDarwin) then false else true;
                      }).overrideAttrs
                        (old: {
                          doCheck = false;
                          configureFlags = old.configureFlags ++ [
                            "--disable-encoders"
                            "--disable-muxers"
                            "--disable-devices"
                            "--disable-hwaccels"
                          ];
                        })
                    else
                      ffmpeg-headless
                  )
                  # Use static versions of libpng and libjpeg for Windows
                  (
                    if isWindows then
                      libjpeg.override {
                        enableStatic = true;
                        enableShared = false;
                      }
                    else
                      libjpeg
                  )
                  (
                    if isWindows then
                      libpngWithZlibNg.overrideAttrs (old: {
                        dontDisableStatic = true;
                        configureFlags = (old.configureFlags or [ ]) ++ [
                          "--enable-static"
                          "--disable-shared"
                        ];
                      })
                    else
                      libpng
                  )

                ]
                ++ pkgsForHost.lib.optionals isWindows [
                  # ffmpeg transitive dependencies needed for linking on Windows
                  zlibNgStatic
                  (xz.overrideAttrs (old: {
                    dontDisableStatic = true;
                    configureFlags = (old.configureFlags or [ ]) ++ [
                      "--enable-static"
                      "--disable-shared"
                    ];
                  }))
                  (bzip2.overrideAttrs (old: {
                    dontDisableStatic = true;
                    configureFlags = (old.configureFlags or [ ]) ++ [
                      "--enable-static"
                      "--disable-shared"
                    ];
                  }))
                  (libiconv.overrideAttrs (old: {
                    dontDisableStatic = true;
                    configureFlags = (old.configureFlags or [ ]) ++ [
                      "--enable-static"
                      "--disable-shared"
                    ];
                  }))
                  (dav1d.overrideAttrs (old: {
                    mesonFlags = (old.mesonFlags or [ ]) ++ [
                      "-Ddefault_library=static"
                      "-Denable_tools=false"
                      "-Denable_tests=false"
                    ];
                  }))
                ]
                ++ pkgsForHost.lib.optionals (pkgsForHost.stdenv.isLinux && !isStatic) [
                  glib
                ];

              cmakeFlags = [
                "-DCMAKE_BUILD_TYPE=Release"
              ]
              ++ pkgsForHost.lib.optionals (!isWindows) [
                "-DENABLE_THUMBNAILER=ON"
              ]
              ++ pkgsForHost.lib.optionals (!isStatic && !isWindows) [
                "-DBUILD_SHARED_LIBS=ON"
              ]
              ++ pkgsForHost.lib.optionals (isStatic || isWindows) [
                "-DENABLE_TESTS=OFF"
                "-DENABLE_SHARED=OFF"
                "-DENABLE_STATIC=ON"
              ]
              ++ pkgsForHost.lib.optionals isStatic [
                "-DENABLE_FULL_STATIC=ON"
              ]
              ++ pkgsForHost.lib.optionals (pkgsForHost.stdenv.isLinux && !isStatic && !isWindows) [
                "-DENABLE_GIO=ON"
              ];

              # Explicitly strip binaries completely (including static builds)
              stripAllList = [ "bin" ];

              meta = {
                description = "Lightweight video thumbnailer";
                homepage = "https://github.com/dirkvdb/ffmpegthumbnailer";
                platforms = pkgsForHost.lib.platforms.unix ++ pkgsForHost.lib.platforms.windows;
              };
            };
        in
        {
          default = mkPackage pkgs pkgs false false;
          static = mkPackage pkgs pkgsStatic.pkgsStatic true false;
          windows = mkPackage pkgs pkgsWindows true true;
        }
      );

      checks = forEachSupportedSystem (
        { pkgs, ... }:
        {
          default = self.packages.${pkgs.system}.default;
          static = self.packages.${pkgs.system}.static;
        }
      );

      devShells = forEachSupportedSystem (
        { pkgs, ... }:
        let
          pkg = self.packages.${pkgs.system}.default;
        in
        {
          default =
            pkgs.mkShell.override
              {
                # Override stdenv in order to change compiler:
                # stdenv = pkgs.clangStdenv;
              }
              {
                inputsFrom = [ pkg ];
                packages =
                  with pkgs;
                  [
                    # development tools
                    clang-tools
                  ]
                  ++ (if pkgs.system == "aarch64-darwin" then [ ] else [ gdb ]);
              };
        }
      );
    };
}