Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
srid committed Nov 28, 2023
1 parent 9d25d9f commit a177aea
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

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

> [!IMPORTANT]
> 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).
Expand Down
120 changes: 120 additions & 0 deletions doc/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
---
slug: /mission-control
sidebar_label: Scripts
sidebar_position: 2
---

# Devshell scripts using `mission-control`

:::info Note
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)).
:::

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.

## Usage

To use this module, add `mission-control` to `inputs`,

```nix
{
# Inside inputs
mission-control.url = "github:Platonic-Systems/mission-control";
}
```

and import its flakeModule:

```nix
{
# Inside mkFlake
imports = [
inputs.mission-control.flakeModule
];
}
```

## Add a script (Haskell)

Here we'll show a sample of scripts that are particular useful when developing `[Haskell](/haskell-flake)` projects.

### Docs (Hoogle)

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.

```nix
{
# Inside perSystem
mission-control.scripts = {
docs = {
description = "Start Hoogle server for project dependencies";
exec = ''
echo http://127.0.0.1:8888
hoogle serve -p 8888 --local
'';
category = "Dev Tools";
};
};
}
```
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.

### Cabal repl

To start a cabal repl from your devShell on running `, repl`, use:

```nix
{
# Inside perSystem
mission-control.scripts = {
repl = {
description = "Start the cabal repl";
exec = ''
cabal repl "$@"
'';
category = "Dev Tools";
};
};
}
```

[`"$@"`](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`.

### treefmt

If you use the [treefmt](/treefmt-nix) module for autoformatting the source tree, you can alias it as `, fmt`:

```nix
{
# Inside perSystem
mission-control.scripts = {
fmt = {
description = "Format the source tree";
exec = config.treefmt.build.wrapper;
category = "Dev Tools";
};
};
}
```

Note that `exec` in this example is a Nix package.

## Tips

### wrapperName

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:
```nix
{
# Inside perSystem
mission-control = {
wrapperName = "s";
};
}
```

## Example

- [haskell-template's flake.nix](https://github.com/srid/haskell-template/blob/7e4d9c630204c2b64bb071837a5a63f35cfac5d8/flake.nix#L83-L112)

[mission-control]: https://github.com/Platonic-Systems/mission-control

0 comments on commit a177aea

Please sign in to comment.