hercules-ci / flake-parts

❄️ Simplify Nix Flakes with the module system
https://flake.parts
MIT License
727 stars 41 forks source link

Declaring perSystem output that is not a package #241

Open lenianiva opened 4 weeks ago

lenianiva commented 4 weeks ago

I want to declare an output in perSystem.packages or perSystem that is not a package. The use case is that an upstream project (Lean4 in this example) has a function buildPackage which generates a custom set of attributes containing metadata, but the set of attributes is itself not a package. I need to expose this metadata to downstream users.

{
  description = "Mystery";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    flake-parts.url = "github:hercules-ci/flake-parts";
    mystery-builder = {
      ...
    };
  };

  outputs = inputs @ {
    self,
    nixpkgs,
    flake-parts,
    mystery-builder,
    ...
  } : flake-parts.lib.mkFlake { inherit inputs; } {
    flake = {
    };
    systems = [
      "x86_64-linux"
      "x86_64-darwin"
    ];
    perSystem = { system, pkgs, ... }: let
      builder = mystery-builder.packages.${system};
      project = builder.buildPackage {
        src = ./.;
      };
    in rec {
      packages = {
        inherit (project) sharedLib executable;
        inherit project;
        default = project.executable;
      };
    };
  };
}

In this case I want to expose the output project. If I do this directly, I get

       error: A definition for option `perSystem.x86_64-linux.packages.project' is not of type `package'. Definition values:
       - In `/nix/store/id24xzy1kvigzs141gz2ncxc8n2pl0sf-source/flake.nix, via option perSystem':
           {
             allExternalDeps = [
               {
                 allExternalDeps = [
                   {
           ...

Is there a way to expose this output so I can use it in another derivation in the form of mystery.packages.${system}.project?

lenianiva commented 4 weeks ago

legacyPackages would work here, but IMHO it needs a better name