Skip to content

Commit d63943b

Browse files
authored
[Docs] mission-control (#129)
* doc: mission-control * doc/mission-control: edit description * docs/mission-control: can't use # as a wrapperName
1 parent a26aefd commit d63943b

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed

doc/howto/mission-control.md

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
---
2+
slug: mission-control
3+
---
4+
5+
# Devshell scripts using mission-control
6+
7+
The [mission-control](https://github.com/Platonic-Systems/mission-control) flake-parts module enables creating a set of scripts or commands to run in the Nix dev shell. This makes it possible for the project's user to locate all of the commands they need (to get started) in one place, often replacing the likes of `Makefile` or `bin/` scripts.
8+
9+
## Usage
10+
11+
To use this module, add `mission-control` to `inputs`,
12+
13+
```nix
14+
{
15+
# Inside inputs
16+
mission-control.url = "github:Platonic-Systems/mission-control";
17+
}
18+
```
19+
20+
and import its flakeModule:
21+
22+
```nix
23+
{
24+
# Inside mkFlake
25+
imports = [
26+
inputs.mission-control.flakeModule
27+
];
28+
}
29+
```
30+
31+
## Add a script
32+
33+
Here we'll show a sample of scripts that are particular useful when developing Haskell projects.
34+
35+
### Docs (Hoogle)
36+
37+
We can add a convenient script to start Hoogle on project dependencies as follows. As a result, typing `, docs` in the dev shell will start Hoogle.
38+
39+
```nix
40+
{
41+
# Inside perSystem
42+
mission-control.scripts = {
43+
docs = {
44+
description = "Start Hoogle server for project dependencies";
45+
exec = ''
46+
echo http://127.0.0.1:8888
47+
hoogle serve -p 8888 --local
48+
'';
49+
category = "Dev Tools";
50+
};
51+
};
52+
}
53+
```
54+
The `exec` option can be either a shell script (string) or a Nix package. The `category` option defines the group that this script belongs to, when displayed in the menu.
55+
56+
### Cabal repl
57+
58+
To start a cabal repl from your devShell on running `, repl`, use:
59+
60+
```nix
61+
{
62+
# Inside perSystem
63+
mission-control.scripts = {
64+
repl = {
65+
description = "Start the cabal repl";
66+
exec = ''
67+
cabal repl "$@"
68+
'';
69+
category = "Dev Tools";
70+
};
71+
};
72+
}
73+
```
74+
75+
[`"$@"`](https://www.gnu.org/software/bash/manual/html_node/Special-Parameters.html) represents the command-line arguments passed to `, repl`. This allows us to pass custom arguments to `cabal repl`. For example, if you wish to run an executable `foo` from your project in cabal repl, you'd run `, repl exe:foo`. Similarly, to get into the repl for a library `bar` you'd run `, run lib:bar`.
76+
77+
### treefmt
78+
79+
If you use the [[treefmt|treefmt module]] for autoformatting the source tree, you can alias it as `, fmt`:
80+
81+
```nix
82+
{
83+
# Inside perSystem
84+
mission-control.scripts = {
85+
fmt = {
86+
description = "Format the source tree";
87+
exec = config.treefmt.build.wrapper;
88+
category = "Dev Tools";
89+
};
90+
};
91+
}
92+
```
93+
94+
Note that `exec` in this example is a Nix package.
95+
96+
## Tips
97+
98+
### wrapperName
99+
100+
If you don't wish to run your command using `, <command>` you can change the `,` to be any string of your choice by setting the option `wrapperName`, as follows:
101+
```nix
102+
{
103+
# Inside perSystem
104+
mission-control = {
105+
wrapperName = "s";
106+
};
107+
}
108+
```
109+
110+
## Upcoming
111+
112+
- [Zsh and bash shell completion](https://github.com/Platonic-Systems/mission-control/issues/4)
113+
114+
## Example
115+
116+
- https://github.com/srid/haskell-template/blob/master/flake.nix
117+
118+
[mission-control]: https://github.com/Platonic-Systems/mission-control

0 commit comments

Comments
 (0)