Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{
2 lib,
3 autoPatchelfHook,
4 bash,
5 copyDesktopItems,
6 coreutils,
7 cryptsetup,
8 dosfstools,
9 e2fsprogs,
10 exfat,
11 fetchurl,
12 gawk,
13 gnugrep,
14 gnused,
15 gtk3,
16 hexdump,
17 makeDesktopItem,
18 makeWrapper,
19 ntfs3g,
20 parted,
21 procps,
22 stdenv,
23 util-linux,
24 which,
25 xfsprogs,
26 xz,
27 defaultGuiType ? "",
28 withCryptsetup ? false,
29 withXfs ? false,
30 withExt4 ? false,
31 withNtfs ? false,
32 withGtk3 ? defaultGuiType == "gtk3",
33 withQt5 ? defaultGuiType == "qt5",
34 libsForQt5,
35}:
36
37assert lib.elem defaultGuiType [
38 ""
39 "gtk3"
40 "qt5"
41];
42assert defaultGuiType == "gtk3" -> withGtk3;
43assert defaultGuiType == "qt5" -> withQt5;
44
45let
46 inherit (lib) optionals optionalString;
47 inherit (libsForQt5) qtbase wrapQtAppsHook;
48 arch =
49 {
50 x86_64-linux = "x86_64";
51 i686-linux = "i386";
52 aarch64-linux = "aarch64";
53 mipsel-linux = "mips64el";
54 }
55 .${stdenv.hostPlatform.system} or (throw "Unsupported platform: ${stdenv.hostPlatform.system}");
56in
57stdenv.mkDerivation (finalAttrs: {
58 pname =
59 "ventoy"
60 + optionalString (defaultGuiType == "gtk3") "-gtk3"
61 + optionalString (defaultGuiType == "qt5") "-qt5";
62 version = "1.1.05";
63
64 src = fetchurl {
65 url = "https://github.com/ventoy/Ventoy/releases/download/v${finalAttrs.version}/ventoy-${finalAttrs.version}-linux.tar.gz";
66 hash = "sha256-M3nJmJA1nc/1Wqt/ezKG+HyYjR2i/WFuap4wX7Ch3p4=";
67 };
68
69 patches = [
70 ./000-nixos-sanitization.patch
71 ];
72
73 postPatch = ''
74 # Fix permissions.
75 find -type f -name \*.sh -exec chmod a+x '{}' \;
76
77 # Fix path to log.
78 sed -i 's:log\.txt:/var/log/ventoy\.log:g' \
79 WebUI/static/js/languages.js tool/languages.json
80 '';
81
82 nativeBuildInputs = [
83 autoPatchelfHook
84 makeWrapper
85 ]
86 ++ optionals (withQt5 || withGtk3) [ copyDesktopItems ]
87 ++ optionals withQt5 [ wrapQtAppsHook ];
88
89 buildInputs = [
90 bash
91 coreutils
92 dosfstools
93 exfat
94 gawk
95 gnugrep
96 gnused
97 hexdump
98 parted
99 procps
100 util-linux
101 which
102 xz
103 ]
104 ++ optionals withCryptsetup [ cryptsetup ]
105 ++ optionals withExt4 [ e2fsprogs ]
106 ++ optionals withGtk3 [ gtk3 ]
107 ++ optionals withNtfs [ ntfs3g ]
108 ++ optionals withXfs [ xfsprogs ]
109 ++ optionals withQt5 [ qtbase ];
110
111 strictDeps = true;
112
113 desktopItems = [
114 (makeDesktopItem {
115 name = "Ventoy";
116 desktopName = "Ventoy";
117 comment = "Tool to create bootable USB drive for ISO/WIM/IMG/VHD(x)/EFI files";
118 icon = "VentoyLogo";
119 exec = "ventoy-gui";
120 terminal = false;
121 categories = [ "Utility" ];
122 startupNotify = true;
123 })
124 ];
125
126 dontConfigure = true;
127 dontBuild = true;
128
129 installPhase = ''
130 runHook preInstall
131
132 # Setup variables
133 local VENTOY_PATH="$out"/share/ventoy
134 local ARCH='${arch}'
135
136 # Prepare
137 cd tool/"$ARCH"
138 rm ash* hexdump* mkexfatfs* mount.exfat-fuse* xzcat*
139 for archive in *.xz; do
140 xzcat "$archive" > "''${archive%.xz}"
141 rm "$archive"
142 done
143 chmod a+x *
144 cd -
145
146 # Cleanup.
147 case "$ARCH" in
148 x86_64) rm -r {tool/,VentoyGUI.}{i386,aarch64,mips64el};;
149 i386) rm -r {tool/,VentoyGUI.}{x86_64,aarch64,mips64el};;
150 aarch64) rm -r {tool/,VentoyGUI.}{x86_64,i386,mips64el};;
151 mips64el) rm -r {tool/,VentoyGUI.}{x86_64,i386,aarch64};;
152 esac
153 rm README
154 rm tool/"$ARCH"/Ventoy2Disk.gtk2 || true # For aarch64 and mips64el.
155
156 # Copy from "$src" to "$out"
157 mkdir -p "$out"/bin "$VENTOY_PATH"
158 cp -r . "$VENTOY_PATH"
159
160 # Fill bin dir
161 for f in Ventoy2Disk.sh_ventoy VentoyWeb.sh_ventoy-web \
162 CreatePersistentImg.sh_ventoy-persistent \
163 ExtendPersistentImg.sh_ventoy-extend-persistent \
164 VentoyPlugson.sh_ventoy-plugson; do
165 local bin="''${f%_*}" wrapper="''${f#*_}"
166 makeWrapper "$VENTOY_PATH/$bin" "$out/bin/$wrapper" \
167 --prefix PATH : "${lib.makeBinPath finalAttrs.buildInputs}" \
168 --chdir "$VENTOY_PATH"
169 done
170 ''
171 # VentoGUI uses the `ventoy_gui_type` file to determine the type of GUI.
172 # See: https://github.com/ventoy/Ventoy/blob/v1.0.78/LinuxGUI/Ventoy2Disk/ventoy_gui.c#L1096
173 + optionalString (withGtk3 || withQt5) ''
174 echo "${defaultGuiType}" > "$VENTOY_PATH/ventoy_gui_type"
175 makeWrapper "$VENTOY_PATH/VentoyGUI.$ARCH" "$out/bin/ventoy-gui" \
176 --prefix PATH : "${lib.makeBinPath finalAttrs.buildInputs}" \
177 --chdir "$VENTOY_PATH"
178 mkdir "$out"/share/{applications,pixmaps}
179 ln -s "$VENTOY_PATH"/WebUI/static/img/VentoyLogo.png "$out"/share/pixmaps/
180 ''
181 + optionalString (!withGtk3) ''
182 rm "$VENTOY_PATH"/tool/{"$ARCH"/Ventoy2Disk.gtk3,VentoyGTK.glade}
183 ''
184 + optionalString (!withQt5) ''
185 rm "$VENTOY_PATH/tool/$ARCH/Ventoy2Disk.qt5"
186 ''
187 + optionalString (!withGtk3 && !withQt5) ''
188 rm "$VENTOY_PATH"/VentoyGUI.*
189 ''
190 + ''
191
192 runHook postInstall
193 '';
194
195 meta = {
196 homepage = "https://www.ventoy.net";
197 description =
198 "New Bootable USB Solution" + optionalString (defaultGuiType != "") " with GUI support";
199 longDescription = ''
200 Ventoy is an open source tool to create bootable USB drive for
201 ISO/WIM/IMG/VHD(x)/EFI files. With ventoy, you don't need to format the
202 disk over and over, you just need to copy the ISO/WIM/IMG/VHD(x)/EFI files
203 to the USB drive and boot them directly. You can copy many files at a time
204 and ventoy will give you a boot menu to select them. You can also browse
205 ISO/WIM/IMG/VHD(x)/EFI files in local disk and boot them. x86 Legacy
206 BIOS, IA32 UEFI, x86_64 UEFI, ARM64 UEFI and MIPS64EL UEFI are supported
207 in the same way. Most type of OS supported
208 (Windows/WinPE/Linux/ChromeOS/Unix/VMware/Xen...). With ventoy you can
209 also browse ISO/WIM/IMG/VHD(x)/EFI files in local disk and boot them.
210 800+ image files are tested. 90%+ distros in DistroWatch supported.
211 '';
212 changelog = "https://www.ventoy.net/doc_news.html";
213 knownVulnerabilities = [
214 ''
215 Ventoy uses binary blobs which can't be trusted to be free of malware or compliant to their licenses.
216 https://github.com/NixOS/nixpkgs/issues/404663
217 See the following Issues for context:
218 https://github.com/ventoy/Ventoy/issues/2795
219 https://github.com/ventoy/Ventoy/issues/3224
220 ''
221 ];
222 license = lib.licenses.unfree;
223 mainProgram = "ventoy";
224 maintainers = with lib.maintainers; [
225 johnrtitor
226 ];
227 platforms = [
228 "x86_64-linux"
229 "i686-linux"
230 "aarch64-linux"
231 "mipsel-linux"
232 ];
233 sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
234 };
235})