Skip to content

Commit a177aea

Browse files
committed
Add documentation
1 parent 9d25d9f commit a177aea

File tree

2 files changed

+121
-1
lines changed

2 files changed

+121
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A `flake-parts` module for your Nix devshell scripts
44

5-
https://zero-to-flakes.com/mission-control
5+
https://community.flake.parts/mission-control
66

77
> [!IMPORTANT]
88
> We recommend that you use [just](https://just.systems/man/en/) over this module. For migration, see [this PR](https://github.com/srid/haskell-template/pull/111).

doc/index.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
---
2+
slug: /mission-control
3+
sidebar_label: Scripts
4+
sidebar_position: 2
5+
---
6+
7+
# Devshell scripts using `mission-control`
8+
9+
:::info Note
10+
As a simpler alternative to `mission-control`, you may also use [just](https://just.systems/man/en/) (see [example use](https://github.com/srid/haskell-template/pull/111)).
11+
:::
12+
13+
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.
14+
15+
## Usage
16+
17+
To use this module, add `mission-control` to `inputs`,
18+
19+
```nix
20+
{
21+
# Inside inputs
22+
mission-control.url = "github:Platonic-Systems/mission-control";
23+
}
24+
```
25+
26+
and import its flakeModule:
27+
28+
```nix
29+
{
30+
# Inside mkFlake
31+
imports = [
32+
inputs.mission-control.flakeModule
33+
];
34+
}
35+
```
36+
37+
## Add a script (Haskell)
38+
39+
Here we'll show a sample of scripts that are particular useful when developing `[Haskell](/haskell-flake)` projects.
40+
41+
### Docs (Hoogle)
42+
43+
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.
44+
45+
```nix
46+
{
47+
# Inside perSystem
48+
mission-control.scripts = {
49+
docs = {
50+
description = "Start Hoogle server for project dependencies";
51+
exec = ''
52+
echo http://127.0.0.1:8888
53+
hoogle serve -p 8888 --local
54+
'';
55+
category = "Dev Tools";
56+
};
57+
};
58+
}
59+
```
60+
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.
61+
62+
### Cabal repl
63+
64+
To start a cabal repl from your devShell on running `, repl`, use:
65+
66+
```nix
67+
{
68+
# Inside perSystem
69+
mission-control.scripts = {
70+
repl = {
71+
description = "Start the cabal repl";
72+
exec = ''
73+
cabal repl "$@"
74+
'';
75+
category = "Dev Tools";
76+
};
77+
};
78+
}
79+
```
80+
81+
[`"$@"`](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`.
82+
83+
### treefmt
84+
85+
If you use the [treefmt](/treefmt-nix) module for autoformatting the source tree, you can alias it as `, fmt`:
86+
87+
```nix
88+
{
89+
# Inside perSystem
90+
mission-control.scripts = {
91+
fmt = {
92+
description = "Format the source tree";
93+
exec = config.treefmt.build.wrapper;
94+
category = "Dev Tools";
95+
};
96+
};
97+
}
98+
```
99+
100+
Note that `exec` in this example is a Nix package.
101+
102+
## Tips
103+
104+
### wrapperName
105+
106+
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:
107+
```nix
108+
{
109+
# Inside perSystem
110+
mission-control = {
111+
wrapperName = "s";
112+
};
113+
}
114+
```
115+
116+
## Example
117+
118+
- [haskell-template's flake.nix](https://github.com/srid/haskell-template/blob/7e4d9c630204c2b64bb071837a5a63f35cfac5d8/flake.nix#L83-L112)
119+
120+
[mission-control]: https://github.com/Platonic-Systems/mission-control

0 commit comments

Comments
 (0)