Skip to content

Add an attribute that can be used to label custom attributes in nix flake show #6454

@NobbZ

Description

@NobbZ

Is your feature request related to a problem? Please describe.

In a common flake there are some custom attributes used, that appear in nix flake show just as "unknown". One of the commonly used custom attributes is lib (used by nixpkgs itself). Also homeConfigurations and homeModules are rather common since home-manager got flake support. And I am sure there are equivalent attributes for nix-darwin.

Describe the solution you'd like

There should be a way to label these. This could be done by adding an extra attribute labelers to the flake schema.

A labeler then is a function that returns either a string or an arbitrary nested set of strings. nix flake show will use each attribute name as a "node" in the tree and increase nesting, while a string value will be used as label. As far as I can tell, this would pretty much match what one sees in the nix flake show --json output.

Whenever nix flake show discovers an unknown attribute foo it will call self.labelers.foo self.foo. The labeler then has to inspect the value and build the aforementioned label tree.

The following show snippet could have been created by the returned nix value below it:

├───homeConfigurations
│   ├───nobbz@enceladeus: Home Manager configuration
│   ├───nobbz@mimas: Home Manager configuration
│   └───nobbz@thetys: Home Manager configuration
{
  "nobbz@enceladeus" = "Home Manager configuration";
  "nobbz@mimas" = "Home Manager configuration";
  "nobbz@thetys" = "Home Manager configuration";
}

Describe alternatives you've considered

External programs that are required to increase discoverability of custom attributes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions