From 5d5d4714092704caf4459dc4c81abd2e82ab2bd7 Mon Sep 17 00:00:00 2001 From: Chua Hou Date: Wed, 6 Jul 2022 19:25:58 +0800 Subject: [PATCH] Set meta.mainProgram for executable components (#1539) - This allows nix run to work correctly, so that it knows the correct name of the executable, as it would otherwise attempt to execute an executable named "project-name-exe-exeName", for example. - See #1231. --- builder/comp-builder.nix | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/builder/comp-builder.nix b/builder/comp-builder.nix index 28ba9bf8..7f7fe586 100644 --- a/builder/comp-builder.nix +++ b/builder/comp-builder.nix @@ -356,6 +356,14 @@ let description = package.synopsis or ""; license = haskellLib.cabalToNixpkgsLicense package.license; platforms = if platforms == null then lib.platforms.all else platforms; + } // lib.optionalAttrs (haskellLib.isExecutableType componentId) { + # Set main executable name for executable components, so that `nix run` in + # nix flakes will work correctly. When not set, `nix run` would (typically + # erroneously) deduce the executable name from the derivation name and + # attempt to run, for example, + # `/nix/store/...-project-exe-app-0.1.0.0/bin/project-exe-app` instead of + # `/nix/store/...-project-exe-app-0.1.0.0/bin/app`. + mainProgram = exeName; }; propagatedBuildInputs =