2024-10-12 10:35:54 -05:00
|
|
|
{
|
|
|
|
|
callPackage,
|
|
|
|
|
fetchtorrent,
|
|
|
|
|
lib,
|
2025-06-24 22:44:32 -05:00
|
|
|
stdenvNoCC,
|
2024-10-12 10:35:54 -05:00
|
|
|
...
|
|
|
|
|
}:
|
|
|
|
|
let
|
|
|
|
|
inherit (lib.attrsets) mapAttrs mapAttrsRecursiveCond;
|
2024-10-12 17:32:32 -05:00
|
|
|
# Converts the inputs from the file into a fetchtorrent command
|
2024-10-12 10:35:54 -05:00
|
|
|
zim =
|
|
|
|
|
type: val:
|
2025-06-24 22:44:32 -05:00
|
|
|
stdenvNoCC.mkDerivation (finalAttrs: {
|
|
|
|
|
inherit (val) name;
|
|
|
|
|
src = (
|
|
|
|
|
fetchtorrent {
|
|
|
|
|
inherit (val) hash;
|
|
|
|
|
url = "https://download.kiwix.org/zim/${type}/${val.name}.torrent";
|
2025-10-15 23:13:06 -05:00
|
|
|
backend = "transmission";
|
2025-10-16 10:46:02 -05:00
|
|
|
postUnpack = "mkdir -p $downloadedDirectory/tmp; mv $downloadedDirectory/*.zim $downloadedDirectory/tmp";
|
2025-06-24 22:44:32 -05:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
phases = [ "installPhase" ];
|
|
|
|
|
installPhase = ''
|
2025-10-16 10:46:02 -05:00
|
|
|
set -x
|
2025-06-24 22:44:32 -05:00
|
|
|
ls -lR ${finalAttrs.src}
|
2025-10-16 16:10:10 -05:00
|
|
|
ln -s ${finalAttrs.src}/${finalAttrs.name} $out
|
2025-06-24 22:44:32 -05:00
|
|
|
'';
|
2024-10-12 17:32:32 -05:00
|
|
|
});
|
|
|
|
|
rawZims = builtins.fromJSON (builtins.readFile ./zim/blobs.json);
|
|
|
|
|
# Uses the function above to convert the JSON into a structure of fetchtorrent derivations
|
|
|
|
|
zims = mapAttrs (_: types: (mapAttrs (type: info: zim type info) types)) (rawZims);
|
|
|
|
|
# Turns the fetchtorrent derivations into a list of strings, copying the results into a final output
|
2024-10-12 10:35:54 -05:00
|
|
|
copies = builtins.concatStringsSep "\n" (
|
|
|
|
|
lib.attrsets.collect builtins.isString (
|
|
|
|
|
mapAttrsRecursiveCond (as: !(lib.attrsets.isDerivation as)) # don't recurse derivations
|
2024-10-12 17:32:32 -05:00
|
|
|
(_: v: "ln -s ${v} $out/") # copy derivation to destination
|
2024-10-12 10:35:54 -05:00
|
|
|
zims
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
in
|
2025-06-24 22:44:32 -05:00
|
|
|
stdenvNoCC.mkDerivation {
|
2024-10-12 10:35:54 -05:00
|
|
|
name = "zims";
|
2025-10-15 23:13:06 -05:00
|
|
|
version = "2025-10";
|
2024-10-12 10:35:54 -05:00
|
|
|
|
|
|
|
|
passthru = {
|
2024-10-12 17:32:32 -05:00
|
|
|
inherit zims rawZims;
|
2024-10-12 10:35:54 -05:00
|
|
|
updater = (callPackage ./zim/updater.nix { });
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
phases = [ "installPhase" ];
|
|
|
|
|
|
|
|
|
|
# Collect all the zim files into a single folder derivation
|
|
|
|
|
installPhase = ''
|
|
|
|
|
mkdir -p $out
|
2024-10-12 17:32:32 -05:00
|
|
|
${copies}
|
2024-10-12 10:35:54 -05:00
|
|
|
'';
|
|
|
|
|
}
|