From f735423d98928e43af93dd264da24dd4c49501c9 Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Wed, 13 May 2026 08:06:57 -0500 Subject: [PATCH] chore: make zims separate packages --- flake.lock | 16 +++++++++++++ flake.nix | 6 +++-- garnix.yaml | 8 ------- hosts/baseline.nix | 3 +-- overlays/default.nix | 1 - pkgs/default.nix | 57 ++++++++++++++++++++++---------------------- pkgs/zim/blobs.json | 50 +++++++++++++++++++++++++------------- pkgs/zim/default.nix | 24 +++++++++++++++++++ pkgs/zim/one_zim.nix | 32 +++++++++++++++++++++++++ shells.nix | 7 +++--- 10 files changed, 143 insertions(+), 61 deletions(-) create mode 100644 pkgs/zim/default.nix create mode 100644 pkgs/zim/one_zim.nix diff --git a/flake.lock b/flake.lock index 76973df..1c4322c 100644 --- a/flake.lock +++ b/flake.lock @@ -428,6 +428,21 @@ "type": "github" } }, + "nixpkgs-lib_2": { + "locked": { + "lastModified": 1778379128, + "narHash": "sha256-+yjPmoKsTqe/FQHriXzIfI0ELuEt3+1LXc0BE8nU/Yc=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "e361b0ff94723bc94283566dc2a13a46f07eaf5c", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, "nixpkgs_2": { "locked": { "lastModified": 1769461804, @@ -561,6 +576,7 @@ "minecraft": "minecraft", "niks3": "niks3", "nix-hardware": "nix-hardware", + "nixpkgs-lib": "nixpkgs-lib_2", "nixunstable": "nixunstable", "nixvimunstable": "nixvimunstable", "nurpkgs": "nurpkgs", diff --git a/flake.nix b/flake.nix index 8e124ea..13b37a2 100644 --- a/flake.nix +++ b/flake.nix @@ -26,6 +26,7 @@ minecraft.url = "github:Infinidoge/nix-minecraft"; niks3.url = "github:Mic92/niks3"; nix-hardware.url = "github:nixos/nixos-hardware"; + nixpkgs-lib.url = "github:nix-community/nixpkgs.lib"; nixvimunstable = { url = "github:nix-community/nixvim/main"; inputs.nixpkgs.follows = "nixunstable"; @@ -146,16 +147,17 @@ pkgs = imported_packages.${system}; }; - packages = (import ./pkgs { inherit pkgs; }); + packages = (import ./pkgs { inherit pkgs top; }); checks = import ./checks.nix { inherit system top self'; - inherit (pkgs) lib; + inherit (top.nixpkgs-lib) lib; }; devShells = import ./shells.nix { inherit pkgs; inherit (top) colmena; + inherit (self') packages; }; }; }; diff --git a/garnix.yaml b/garnix.yaml index 2020d5b..e9eac47 100644 --- a/garnix.yaml +++ b/garnix.yaml @@ -4,14 +4,6 @@ builds: - "homeConfigurations.*" - "nixosConfigurations.*" - "packages.*" - # bitwarden-cli package is broken on aarch64-darwin - - "packages.aarch64-darwin.img-bitwarden" - # kmod-31 is not a thing on Darwin - - "packages.aarch64-darwin.qemu-hook" - - "packages.aarch64-darwin.vfio_shutdown" - - "packages.aarch64-darwin.vfio_startup" - # This one is a bit of a beast and shouldn't take up Garnix time - - "packages.aarch64-darwin.zim" # These are just images which I will build when # I feel like it - "devShells.*" diff --git a/hosts/baseline.nix b/hosts/baseline.nix index b399fe8..0c03769 100644 --- a/hosts/baseline.nix +++ b/hosts/baseline.nix @@ -31,10 +31,9 @@ efibootmgr findutils file - gcc-tune git gnupatch - hms # My own home manager switcher + top.self.packages.${pkgs.stdenv.hostPlatform.system}.hms # My own home manager switcher iperf killall nano diff --git a/overlays/default.nix b/overlays/default.nix index d7d17d9..d6ff6bd 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -30,4 +30,3 @@ final: prev: tpmSupport = true; }; } -// (import ../pkgs { pkgs = prev; }) diff --git a/pkgs/default.nix b/pkgs/default.nix index eb77023..808958f 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -1,36 +1,37 @@ { pkgs, system ? pkgs.stdenv.hostPlatform.system, + top, ... }: let - c = pkgs.callPackage; + c = pkgs.newScope packages; + packages = if system == "x86_64-linux" then (allSys // x86Linux) else allSys; + allSys = { + #default = iso; + #iso = top.self.nixosConfigurations.iso.config.system.build.isoImage; + #iso-beta = self.nixosConfigurations.iso-beta.config.system.build.isoImage; + aacs = c ./aacs.nix { }; + adblock_update = c ./adblock_update.nix { }; + brew = c ./homebrew.nix { }; + create_ssl = c ./create_ssl.nix { }; + gcc-tune = c ./gcc-tune.nix { }; + #gen-build = c ./gen-build { }; + hms = c ./hms { }; + inject-darwin = c ./inject-darwin.nix { }; + inject = c ./inject.nix { }; + setup-ssh = c ./setup-ssh { }; + upgrade-pg-cluster = c ./upgrade-pg-cluster.nix { }; + }; + x86Linux = { + qemu-hook = c ./qemu-hook.nix { }; + vfio_startup = c ./vfio_startup.nix { }; + vfio_shutdown = c ./vfio_shutdown.nix { }; + } + // (import ./zim { + inherit (top.nixpkgs-lib) lib; + inherit pkgs; + }); in -{ - #default = iso; - #iso = top.self.nixosConfigurations.iso.config.system.build.isoImage; - #iso-beta = self.nixosConfigurations.iso-beta.config.system.build.isoImage; - aacs = c ./aacs.nix { }; - adblock_update = c ./adblock_update.nix { }; - brew = c ./homebrew.nix { }; - create_ssl = c ./create_ssl.nix { }; - gcc-tune = c ./gcc-tune.nix { }; - #gen-build = c ./gen-build { }; - hms = c ./hms { }; - inject-darwin = c ./inject-darwin.nix { }; - inject = c ./inject.nix { }; - setup-ssh = c ./setup-ssh { }; - upgrade-pg-cluster = c ./upgrade-pg-cluster.nix { }; -} -// ( - if system == "x86_64-linux" then - { - qemu-hook = c ./qemu-hook.nix { }; - vfio_startup = c ./vfio_startup.nix { }; - vfio_shutdown = c ./vfio_shutdown.nix { }; - zim = c ./zim.nix { }; - } - else - { } -) +packages diff --git a/pkgs/zim/blobs.json b/pkgs/zim/blobs.json index 091e299..d81c494 100644 --- a/pkgs/zim/blobs.json +++ b/pkgs/zim/blobs.json @@ -1,71 +1,87 @@ { "en": { "gutenberg": { - "name": "gutenberg_en_all_2023-08.zim", + "name": "gutenberg_en_all", + "version": "2023-08", "hash": "sha256-wWi0vTyMD/Es0w/jk9uyg4DN94080thPfT5uphEqbUc=" }, "phet": { - "name": "phet_en_all_2025-03.zim", + "name": "phet_en_all", + "version": "2025-03", "hash": "sha256-HT/gVNydkOitny6oUl2A+JvbFDGAIeb0h+xbMeQ2Rqs=" }, "wikibooks": { - "name": "wikibooks_en_all_maxi_2025-10.zim", + "name": "wikibooks_en_all_maxi", + "version": "2025-10", "hash": "sha256-zmcvrvGO+LEHt7x8/SoguBDODUyRXy9x5LUGAkS+fF8=" }, "wikipedia": { - "name": "wikipedia_en_all_maxi_2025-08.zim", + "name": "wikipedia_en_all_maxi", + "version": "2025-08", "hash": "sha256-r7Cd0vjEb84Ftw+EwZSlqb8qhqm8WA3LAPdHAav7wrg=" }, "wikisource": { - "name": "wikisource_en_all_maxi_2025-11.zim", + "name": "wikisource_en_all_maxi", + "version": "2025-11", "hash": "sha256-jPHh/C20PARN6K7aPNw3k9fFHhpwzsREi/1o1DIISS4=" }, "wikiversity": { - "name": "wikiversity_en_all_maxi_2025-11.zim", + "name": "wikiversity_en_all_maxi", + "version": "2025-11", "hash": "sha256-0DaE2EUdHvaX3XqD3f0lwurSAaDZ4hEKtrMEutL5xt0=" }, "wiktionary": { - "name": "wiktionary_en_all_nopic_2025-09.zim", + "name": "wiktionary_en_all_nopic", + "version": "2025-09", "hash": "sha256-EzrrruJQWY/3pP93WCTeCCfaPvpshqdkR0TFxVz7bEI=" } }, "fr": { "gutenberg": { - "name": "gutenberg_fr_all_2025-10.zim", + "name": "gutenberg_fr_all", + "version": "2025-10", "hash": "sha256-1gU7v//LYX/2LyIRjO02A1fWPQz9Y7Qt5ftgeazd3G8=" }, "phet": { - "name": "phet_fr_all_2025-03.zim", + "name": "phet_fr_all", + "version": "2025-03", "hash": "sha256-K56i55WPu5EMQHIrnnqhgJ32WozZ6oYD9X3IBytGA0A=" }, "wikibooks": { - "name": "wikibooks_fr_all_maxi_2025-09.zim", + "name": "wikibooks_fr_all_maxi", + "version": "2025-09", "hash": "sha256-PQSdPbBHwK3IfFPH5GsKaxkNGTlZVJNJEI8gNioBl1U=" }, "wikipedia": { - "name": "wikipedia_fr_all_maxi_2025-06.zim", + "name": "wikipedia_fr_all_maxi", + "version": "2025-06", "hash": "sha256-zzDhITMd1nRMYTUlvn56l4VBnpFuhiNrhhYMcrrBuOQ=" }, "wikisource": { - "name": "wikisource_fr_all_maxi_2025-09.zim", + "name": "wikisource_fr_all_maxi", + "version": "2025-09", "hash": "sha256-2gEY5nTBecrmg61VJerxO4/oV7dZJmRgzLkqrcocW/0=" }, "wikiversity": { - "name": "wikiversity_fr_all_maxi_2025-09.zim", + "name": "wikiversity_fr_all_maxi", + "version": "2025-09", "hash": "sha256-4vOxYiX3TYht7ARY+PeCJ0ArVZZn9TeGtwCieqn3xUw=" }, "wiktionary": { - "name": "wiktionary_fr_all_nopic_2025-11.zim", + "name": "wiktionary_fr_all_nopic", + "version": "2025-11", "hash": "sha256-oQS8DzKioceCER1p1oAvaS1gRooMLJLYnCqy1aLARi4=" } }, "ht": { "phet": { - "name": "phet_ht_all_2025-03.zim", - "hash": "sha256-UjC0REJ5d5wIKccutZADX74IxvZuF+CD/caVzZfHg9s=" + "name": "phet_ht_all", + "version": "2025-03", + "hash": "sha256-bHrPzE8H7ptrP6r5wPlXSsXNlTiKxJ9KatABC4kwx+s=" }, "wikipedia": { - "name": "wikipedia_ht_all_maxi_2025-09.zim", + "name": "wikipedia_ht_all_maxi", + "version": "2025-09", "hash": "sha256-spT7EFXLnI0FWT9Vlvp7QEP0urntmQ2C+fQB5bVLoLE=" } } diff --git a/pkgs/zim/default.nix b/pkgs/zim/default.nix new file mode 100644 index 0000000..f2c3de7 --- /dev/null +++ b/pkgs/zim/default.nix @@ -0,0 +1,24 @@ +{ pkgs, lib, ... }: +let + zimMetadata = builtins.fromJSON (builtins.readFile ./blobs.json); + oneZim = + sourceType: info: + pkgs.callPackage ./one_zim.nix { + inherit sourceType; + sourceName = info.name; + sourceHash = info.hash; + sourceVersion = info.version; + }; + # Preserves structure in the blobs.json file, turning leaves into drvs + zimFileDrvs = builtins.mapAttrs ( + _language: types: (builtins.mapAttrs (sourceType: info: oneZim sourceType info) types) + ) zimMetadata; + # Flattens leaf drvs into the structure that flake packages expects + zimFilePkgs = builtins.listToAttrs ( + lib.mapAttrsToListRecursiveCond (_path: x: !(x ? "name")) (_path: drv: { + inherit (drv) name; + value = drv; + }) zimFileDrvs + ); +in +zimFilePkgs diff --git a/pkgs/zim/one_zim.nix b/pkgs/zim/one_zim.nix new file mode 100644 index 0000000..c6fd4fb --- /dev/null +++ b/pkgs/zim/one_zim.nix @@ -0,0 +1,32 @@ +{ + sourceType, + sourceName, + sourceVersion, + sourceHash, + + fetchurl, + stdenvNoCC, +}: + +stdenvNoCC.mkDerivation (finalAttrs: { + name = "zim-${sourceType}-${sourceName}.zim"; + version = sourceVersion; + + src = ( + fetchurl { + url = "https://download.kiwix.org/zim/${sourceType}/${sourceName}_${sourceVersion}.zim"; + hash = sourceHash; + } + # fetchtorrent { + # inherit (val) hash; + # url = "https://download.kiwix.org/zim/${type}/${val.name}.torrent"; + # backend = "transmission"; + # postUnpack = "mkdir -p $downloadedDirectory/tmp; mv $downloadedDirectory/*.zim $downloadedDirectory/tmp"; + # } + ); + phases = [ "installPhase" ]; + installPhase = '' + set -x + ln -s ${finalAttrs.src} $out + ''; +}) diff --git a/shells.nix b/shells.nix index c1d19fd..1a3c722 100644 --- a/shells.nix +++ b/shells.nix @@ -1,6 +1,7 @@ { - pkgs, colmena, + packages, + pkgs, ... }: let @@ -16,8 +17,8 @@ in git gnutar gzip - inject - inject-darwin + packages.inject + packages.inject-darwin nano ]; };