nixpkgs: let dummyPkgs = import nixpkgs { system = "x86_64-linux"; }; lib = dummyPkgs.lib; in rec { # Collects all the supported for drv leveraging the meta.platforms # Nixpkgs attribute. # # We callPackage the derivation with a dummy Nixpkgs x86_64 # instance, regardless of the underlying arch. It doesn't matter # much, we won't build anything here, we just need callPackage to # evaluate the meta attributes. collectPlatformsForDrv = drv: (dummyPkgs.callPackage drv {}).meta.platforms; # Generates the flake outputs for PATH for each PLATFORMS platform. # IE. from # { # path = /tmp/dummy/path; # pathName = "hello"; # platforms = [ "x86_64-linux""aarch64-linux"]; # }; # # We get: # # { # aarch64-linux = { hello = /tmp/dummy/path; }; # x86_64-linux = { hello = /tmp/dummy/path; }; # } genFlakeOutputForPlatforms = { path, name, platforms }: lib.genAttrs platforms (platform: { ${name} = path; }); # Goes through a flake-like packages output attrs to inject the # relevant callPackage function call. Obviously, this callPackage # function is platform-dependant, we'll instantiate a different one # for each platform subtree. injectCallPackage = packages: let injectPlatformCallPackage = { attrs, platform }: let pkgs = import nixpkgs { system = platform; }; callPackage = pkgs.lib.callPackageWith pkgs; in builtins.mapAttrs (_name: value: callPackage value {}) attrs; in builtins.mapAttrs (name: value: injectPlatformCallPackage { attrs = value; platform = name; }) packages; # kefla = packagesOutput: let packagesWithoutCallPackage = lib.foldlAttrs (acc: name: path: let platforms = collectPlatformsForDrv path; packageOutput = genFlakeOutputForPlatforms { inherit path platforms name; }; in lib.recursiveUpdate acc packageOutput) { } packagesOutput; in injectCallPackage packagesWithoutCallPackage; } # lib.foldlAttrs # (acc: name: value: # let # platforms = (dummyPkgs.callPackage value {}).meta.platforms; # # TODO: découper ça avec des tests intermediaires. # entries = lib.genAttrs platforms (platform: ) # in builtins.trace platforms (lib.recursiveUpdate acc { hello = platforms; })) # {} # packages # }