From ed94388c2e622f28cb45108a4e73c9d2b2a796da Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar <3998+srid@users.noreply.github.com> Date: Mon, 2 Sep 2024 18:08:10 -0400 Subject: [PATCH] Add `meta.description` to flake apps (#356) --- CHANGELOG.md | 5 +++++ nix/modules/project/outputs.nix | 15 +++++++++------ nix/types/app-type.nix | 11 +++++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1036a51..be1701f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Revision history for haskell-flake +## Unreleased + +- Enhancements + - Support `meta.description` in flake apps. Requires newer version of flake-parts. + ## 0.5.0 (Jun 24, 2024) - Breaking changes diff --git a/nix/modules/project/outputs.nix b/nix/modules/project/outputs.nix index a489d186..16c70419 100644 --- a/nix/modules/project/outputs.nix +++ b/nix/modules/project/outputs.nix @@ -54,7 +54,7 @@ let exes = mkOption { type = types.lazyAttrsOf appType; description = '' - Attrset of executables from `.cabal` file. + Attrset of executables from `.cabal` file. If the associated Haskell project has a separate bin output (cf. `enableSeparateBinOutput`), then this exe will refer @@ -90,15 +90,19 @@ in finalPackages = config.basePackages.extend finalOverlay; - buildPackageInfo = name: value: { + buildPackageInfo = name: value: rec { package = finalPackages.${name}; exes = lib.listToAttrs (map (exe: - lib.nameValuePair exe { - program = "${lib.getBin finalPackages.${name}}/bin/${exe}"; - } + lib.nameValuePair exe ({ + program = "${lib.getBin package}/bin/${exe}"; + meta.description = + if lib.hasAttrByPath [ "meta" "description" ] package + then "${if exe != name then "[${exe}] " else ""}${package.meta.description}" + else "Executable ${if exe != name then "${exe} from " else "for "}package ${name}"; + }) ) value.cabal.executables ); @@ -122,4 +126,3 @@ in }; }; } - diff --git a/nix/types/app-type.nix b/nix/types/app-type.nix index b1ebcdd3..3a4b70db 100644 --- a/nix/types/app-type.nix +++ b/nix/types/app-type.nix @@ -24,6 +24,17 @@ let A path to an executable or a derivation with `meta.mainProgram`. ''; }; + meta = lib.mkOption { + type = lib.types.lazyAttrsOf lib.types.raw; + default = { }; + # TODO refer to Nix manual 2.25 + description = '' + Metadata information about the app. + Standardized in Nix at . + + Note: `nix flake check` is only aware of the `description` attribute in `meta`. + ''; + }; }; }; in