Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tasks: use lib.getExe to fetch the package binary by default #1745

Merged
merged 3 commits into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/reference/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -83325,17 +83325,17 @@ list of string



Override the binary name if it doesn’t match package name
Override the binary name from the default ` package.meta.mainProgram `.



*Type:*
string
null or string



*Default:*
` config.package.pname `
` null `

*Declared by:*
- [https://github.com/cachix/devenv/blob/main/src/modules/tasks.nix](https://github.com/cachix/devenv/blob/main/src/modules/tasks.nix)
Expand Down
19 changes: 12 additions & 7 deletions src/modules/tasks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ let
if builtins.isNull command
then null
else
let
binary =
if config.binary != null
then "${pkgs.lib.getBin config.package}/bin/${config.binary}"
else pkgs.lib.getExe config.package;
in
pkgs.writeScript name ''
#!${pkgs.lib.getBin config.package}/bin/${config.binary}
#!${binary}
${lib.optionalString (!isStatus) "set -e"}
${command}
${lib.optionalString (config.exports != [] && !isStatus) "${devenv}/bin/devenv-tasks export ${lib.concatStringsSep " " config.exports}"}
Expand All @@ -28,10 +34,9 @@ let
description = "Command to execute the task.";
};
binary = lib.mkOption {
type = types.str;
description = "Override the binary name if it doesn't match package name";
default = config.package.pname;
defaultText = lib.literalExpression "config.package.pname";
type = types.nullOr types.str;
description = "Override the binary name from the default `package.meta.mainProgram`.";
default = null;
};
package = lib.mkOption {
type = types.package;
Expand Down Expand Up @@ -118,8 +123,8 @@ in

assertions = [
{
assertion = lib.all (task: lib.hasPrefix "bash" task.binary || task.exports == [ ]) (lib.attrValues config.tasks);
message = "The 'exports' option for a task can only be set when 'binary' is set to 'bash' or 'bash-interactive'.";
assertion = lib.all (task: task.package.meta.mainProgram == "bash" || task.binary == "bash" || task.exports == [ ]) (lib.attrValues config.tasks);
message = "The 'exports' option for a task can only be set when 'package' is a bash package.";
}
];

Expand Down