-
Notifications
You must be signed in to change notification settings - Fork 11
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
Showing
2 changed files
with
121 additions
and
1 deletion.
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,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 |