Skip to content

Commit

Permalink
docs: add commands example
Browse files Browse the repository at this point in the history
  • Loading branch information
woile committed Jun 23, 2023
1 parent 2cf8f2e commit 6dc59c8
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
6 changes: 6 additions & 0 deletions examples/project-commands/Hello.avdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
protocol Hello {
record Hello {
string message;
int timestamp;
}
}
42 changes: 42 additions & 0 deletions examples/project-commands/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# project-commands

This example shows how to create scripts for your project, by leveraging [mission-control](https://github.com/Platonic-Systems/mission-control)

This is a **potential** alternative to:

- Using a `Makefile` to manage your project's scripts
- Using the popular [Scripts To Rule Them All](https://github.com/github/scripts-to-rule-them-all) approach (having a `scripts/` folder)
- Using a `bin/` folder

## Explanation

In this example we use the [avro-tools](https://avro.apache.org/) to convert our scripts from `.avdl` to `.avsc`.

You don't need to know anything about avro to understand mission-control and use this example (that's nix baby 🚀).

When setting up [mission-control](https://github.com/Platonic-Systems/mission-control), we add
one script called `build`. Because of `wrapperName = "run";`, once we open the shell created by nix,
the commands will be listed as `run build`.

mission-control depends on flake-root, which also exposes the helpful `$FLAKE_ROOT` variable.

After creating the scripts, we need to pass the newly created scripts to the desired shell, in this example we use the default shell.

## Usage

> **Warning**
> If you copy the flake.nix remember to add it to git, otherwise it won't work
Run:

```sh
nix develop
```

And mission-control will print in the new shell the available commands (you should see only one).

Try running

```sh
run build
```
37 changes: 37 additions & 0 deletions examples/project-commands/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
description = "Description for the project";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

mission-control.url = "github:Platonic-Systems/mission-control";
flake-root.url = "github:srid/flake-root";
};

outputs = inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
inputs.mission-control.flakeModule
inputs.flake-root.flakeModule
];
systems = [ "x86_64-linux" "aarch64-darwin" "x86_64-darwin" ];
perSystem = { config, self', inputs', pkgs, system, ... }: {
devShells.default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [ avro-tools ];
inputsFrom = [ config.mission-control.devShell config.flake-root.devShell ];
};
mission-control = {
wrapperName = "run";
scripts = {
build = {
description = "convert files from .avdl to .avsc";
exec = ''
avro-tools idl2schemata "$FLAKE_ROOT/Hello.avdl" .

This comment has been minimized.

Copy link
@srid

srid Jun 23, 2023

Contributor

$FLAKE_ROOT/ here is redundant, since mission-control always runs commands from project root (unless cdToProjectRoot is turned off).

'';
category = "Development";
};
};
};
};
};
}

0 comments on commit 6dc59c8

Please sign in to comment.