Skip to content

Commit

Permalink
cached-profiles: init
Browse files Browse the repository at this point in the history
This should speed up the identifyProfiles call for users who do not want
to download sha256sums and profiles.json for all platforms.
  • Loading branch information
astro committed Nov 8, 2023
1 parent 5eac42b commit 8554e7f
Show file tree
Hide file tree
Showing 26 changed files with 951,078 additions and 13 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/update-hashes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ jobs:
nix eval -f generate-latest-release.nix > latest-release.nix
git add latest-release.nix
git commit -m "latest-release: update" || true
- name: Cache OpenWrt profile information
shell: bash
run: |
git rm cached-profiles/*
nix build -vL .#cached-profiles
cp -L result/*.nix cached-profiles/
git add cached-profiles
git commit -m "cached-profiles: update" || true
- name: Push changes
uses: ad-m/github-push-action@master
with:
Expand Down
55 changes: 55 additions & 0 deletions cached-profiles.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# To search through openwrt profiles we need the `sha256sums` and
# `profiles.json` files for all platforms locally. Therefore it makes
# sense to cache them given that we already update hashes daily.
{ pkgs ? import <nixpkgs> {}
}:

let
inherit (pkgs) lib;

# Only OpenWrt >= 19.07.4 contains profiles.json files
releases =
builtins.filter (release:
builtins.compareVersions release "19.07.4" >= 0
) (
map (builtins.replaceStrings [ ".nix" ] [ "" ]) (
builtins.filter (lib.hasSuffix ".nix") (
builtins.attrNames (builtins.readDir ./hashes)
)
)
);

writeProfiles = release:
let
hashes = import ./hashes/${release}.nix;

profiles =
builtins.mapAttrs (target: variants:
lib.filterAttrs (_: profiles:
profiles != null
) (
builtins.mapAttrs (variant: h:
(import ./files.nix {
inherit pkgs release target variant;
inherit (h) sha256 feedsSha256;
}).profiles
) variants
)
) hashes.targets;

in pkgs.writeText "openwrt-cached-profiles-${release}.nix" (
lib.generators.toPretty {} profiles
);

in
pkgs.runCommand "openwrt-cached-profiles" {
passthru = lib.listToAttrs (map (release: {
name = builtins.replaceStrings [ "." ] [ "_" ] release;
value = writeProfiles release;
}) releases);
} ''
mkdir $out
${lib.concatMapStrings (release: ''
ln -s ${writeProfiles release} $out/${release}.nix
'') releases}
''
Loading

0 comments on commit 8554e7f

Please sign in to comment.