-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b285601
commit ffb1483
Showing
6 changed files
with
169 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
Tasks allow you to form dependencies between units, executed in parallel. | ||
|
||
Under the hood, tasks are implemented using [Taskfile](https://taskfile.dev/). | ||
|
||
## Defining tasks | ||
|
||
```nix title="devenv.nix" | ||
{ pkgs, ... }: | ||
{ | ||
tasks.hello = { | ||
exec = ''echo "Hello, world!"''; | ||
desc = "hello world in bash"; | ||
}; | ||
} | ||
``` | ||
|
||
```shell-session | ||
$ devenv shell task hello | ||
• Building shell ... | ||
• Entering shell ... | ||
Hello, world! | ||
$ | ||
``` | ||
|
||
## Using your favourite language | ||
|
||
Tasks can also reference scripts and depend on other tasks, for example when entering the shell: | ||
|
||
```nix title="devenv.nix" | ||
{ pkgs, lib, config, ... }: | ||
{ | ||
scripts.python-hello = { | ||
exec = ''print("Hello world from Python!")''; | ||
expose = false; | ||
package = config.languages.python.package; | ||
description = "hello world in Python"; | ||
}; | ||
tasks = { | ||
python-hello.exec = config.scripts.python-hello.scriptPackage; | ||
hello = { | ||
exec = "echo 'Hello world from bash!'"; | ||
deps = [ "python-hello" ]; | ||
}; | ||
enterShell.deps = [ "hello" ]; | ||
}; | ||
} | ||
``` | ||
|
||
```shell-session | ||
$ devenv shell | ||
• Building shell ... | ||
• Entering shell ... | ||
Hello world from Python! | ||
Hello world from bash! | ||
$ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
{ pkgs, lib, config, ... }: | ||
let | ||
types = lib.types; | ||
taskType = types.submodule ({ name, config, ... }: { | ||
options = { | ||
exec = lib.mkOption { | ||
type = types.str; | ||
description = "Bash code to run the process."; | ||
}; | ||
script = lib.mkOption { | ||
type = types.package; | ||
internal = true; | ||
default = pkgs.writeShellScript name config.exec; | ||
description = "Path to the script to run."; | ||
}; | ||
desc = lib.mkOption { | ||
type = types.str; | ||
default = ""; | ||
description = "Description of the task."; | ||
}; | ||
deps = lib.mkOption { | ||
type = types.listOf types.str; | ||
description = "List of tasks to run before this task."; | ||
default = [ ]; | ||
}; | ||
aliases = lib.mkOption { | ||
type = types.listOf types.str; | ||
description = "List of aliases for this task."; | ||
default = [ ]; | ||
}; | ||
}; | ||
}); | ||
# ladder is a hack to force Nix into proper indentation | ||
renderTask = name: task: '' | ||
# | ||
${name}: | ||
cmds: | ||
- ${task.script} | ||
desc: ${task.desc} | ||
deps: [${lib.concatStringsSep " " task.deps}] | ||
aliases: [${lib.concatStringsSep " " task.aliases}] | ||
''; | ||
in | ||
{ | ||
options.tasks = lib.mkOption { | ||
type = types.attrsOf taskType; | ||
}; | ||
|
||
options.task.config = lib.mkOption { | ||
type = types.package; | ||
internal = true; | ||
default = pkgs.writeText "tasks.yaml" '' | ||
# auto generated by devenv.nix | ||
version: '3' | ||
tasks: | ||
${lib.concatStringsSep "\n" (lib.mapAttrsToList renderTask config.tasks)} | ||
''; | ||
}; | ||
|
||
config = { | ||
packages = [ pkgs.go-task ]; | ||
info.infoSections.tasks = lib.mapAttrsToList (name: task: "${name}: ${task.desc} ${task.script}") config.tasks; | ||
tasks = { | ||
enterShell = { | ||
desc = "Runs when entering the shell"; | ||
exec = "echo"; | ||
}; | ||
enterTest = { | ||
desc = "Runs when entering the test environment"; | ||
exec = "echo"; | ||
}; | ||
}; | ||
enterShell = '' | ||
ln -sf ${config.task.config} Taskfile.yaml | ||
task enterShell | ||
''; | ||
enterTest = "task enterTest"; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
tasks = { | ||
shell.exec = "touch shell"; | ||
enterShell.deps = [ "shell" ]; | ||
test.exec = "touch test"; | ||
}; | ||
|
||
enterTest = '' | ||
if [ ! -f shell ]; then | ||
echo "shell does not exist" | ||
exit 1 | ||
fi | ||
task test | ||
if [ ! -f test ]; then | ||
echo "test does not exist" | ||
exit 1 | ||
fi | ||
''; | ||
} |