nixpkgs-meta-dump/flake.nix

65 lines
2.9 KiB
Nix

{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/master";
outputs = { self, nixpkgs }: let
pkgs = import nixpkgs {
system = "x86_64-linux";
};
inherit (nixpkgs) lib;
in {
packages."x86_64-linux".default = let
metadata = lib.pipe nixpkgs.legacyPackages."x86_64-linux" [
(pkgs: builtins.removeAttrs pkgs [ "lib" ])
(builtins.mapAttrs (_: pkg: if (builtins.tryEval pkg).success then pkg else null))
(builtins.mapAttrs (_: pkg: if pkg ? meta then pkg.meta else null))
(builtins.mapAttrs (_: meta: if (builtins.tryEval meta).success then meta else null))
(lib.filterAttrs (_: meta: meta != null))
(lib.filterAttrs (_: meta: !(lib.isDerivation meta)))
# (builtins.mapAttrs (_: meta: lib.traceValSeqN 1 (builtins.removeAttrs meta ["name"])))
# (builtins.mapAttrs (_: lib.traceVal))
(builtins.mapAttrs (_: meta: meta // {
name = if (builtins.tryEval meta.name or null).success then (meta.name or null) else "@EVAL_FAILURE@";
}))
# (builtins.mapAttrs (name:
# (lib.filterAttrs (n: v: if builtins.isDerivation v then lib.trace "${name}.${n}" false else true))
# ))
# (builtins.mapAttrs (name:
# (lib.filterAttrs (n: v: if builtins.isFunction v then lib.trace "${name}.${n}" false else true))
# ))
(builtins.mapAttrs (_: meta: {
available = meta.available or null;
badPlatforms = meta.badPlatforms or [];
branch = meta.branch or null;
broken = meta.broken or null;
changelog = meta.changelog or null;
description = meta.description or null;
downloadPage = meta.downloadPage or null;
homepage = meta.homepage or null;
hydraPlatforms = meta.hydraPlatforms or [];
insecure = meta.insecure or null;
license = meta.license or [];
longDescription = meta.longDescription or null;
mainProgram = meta.mainProgram or null;
maintainers = meta.maintainers or [];
name = if (builtins.tryEval meta.name or null).success then (meta.name or null) else "@EVAL_FAILURE@";
outputsToInstall = meta.outputsToInstall or [];
pkgConfigModules = meta.pkgConfigModules or [];
platforms = meta.platforms or [];
position = meta.position or null;
priority = meta.priority or null;
sourceProvenance = meta.sourceProvenance or [];
timeout = meta.timeout or null;
unfree = meta.unfree or null;
unsupported = meta.unsupported or null;
}))
];
in pkgs.runCommandLocal "nixpkgs-meta.json" {
metadata = builtins.toJSON metadata;
# metadata = builtins.toJSON (lib.foldl' (acc: meta: acc // meta) { } (builtins.attrValues metadata))
passAsFile = [ "metadata" ];
nativeBuildInputs = [ pkgs.jq ];
} ''
jq <"$metadataPath" >"$out"
'';
};
}