Giter Club home page Giter Club logo

mission-control's Introduction

mission-control

A flake-parts module for your Nix devshell scripts

https://community.flake.parts/mission-control

Important

We recommend that you use just over this module. For migration, see this PR. Specifically, you may be interested in just-flake.

Usage

To try out mission-control using the example template, start from one of the following ways:

  • Run nix flake init -t github:Platonic-Systems/mission-control to create a template flake.nix file. Run nix develop on it.
  • Or, clone this repo and checkout the example. On this directory, run nix develop --override-input mission-control path:../.1 (or simply direnv allow if you already use direnv) to drop into the Nix shell

The example configures the scripts in Nix as follows:

mission-control.scripts = {
hello = {
description = "Say Hello";
exec = "echo Hello";
};
fmt = {
description = "Format the top-level Nix files";
exec = "${lib.getExe pkgs.nixpkgs-fmt} ./*.nix";
category = "Tools";
};
ponysay = {
exec = pkgs.ponysay;
};
};

Which produces a banner in the devshell like below:

### ️🔨 Welcome to the Nix devshell ###

Available commands:

## Commands

  , hello    : Say Hello
  , ponysay  : Cowsay reimplemention for ponies

## Tools

  , fmt  : Format the Nix files

(Run ',' to display this menu again)

Once you are in the dev shell, you can run any of these scripts prefixed with the wrapper name ,. For example, , fmt to format the Nix files.

Note: The scripts will always be run from the project root directory2 regardless of the current working directory. You can disable this behaviour by setting the cdToProjectRoot option to false.

Examples

These repositories use mission-control to provide development shell workflow scripts:

Footnotes

  1. The --override-input option is to be used when running from this repository to make sure that we are using the local version of mission-control. If you are copying this flake.nix to your project (without also copying the outdated flake.lock), you can simply run nix develop.

  2. "Project root directory" is determined by traversing the directory up until we find the unique file that exists only at the root. This unique file is flake.nix by default, which can be overridden using the flake-root module that this module mandatorily requires; i.e.; flake-root.projectRootFile = "stack.yaml";

mission-control's People

Contributors

jackinloadup avatar roberth avatar shivaraj-bh avatar srid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

mission-control's Issues

An option to not print the banner under CI

I recently started to use mission-control, and noticed that the banner is always printed when entering the devshell - normally good behaviour, but I also happen to run the dev shell during CI runs, and printing the banner for pretty much every step made my build logs much more verbose than they need to be, and a bit annoying to glance through. See here for an example - just expand any step beyond bootstrap to see what I mean.

I could work it around by setting a custom banner that checks the $CI environment variable, and does not display the banner if it is set. But that meant replicating the entire banner snippet.

Would it be possible to have an option like mission-control.banner-display-condition? A shell snippet that the default banner uses like ${banner-display-condition} && menu? It'd default to true, but would make it easier for me to override it: mission-control.banner-display-condition = ''[ -z "$CI" ]'';.

I'm happy to open a pull request adding this (possibly with a better option name - I'm not good at naming), if this is something you'd find useful too. I might even be able to name it mission-control.banner.display-condition, while also remaining backwards compatible, so mission-control.banner = ''<some text>''; would still work.

Use of backticks in `description` breaks build

When description contains backticks:

{
  description = "Foo `bar` qux";
}

we see:

error: builder for '/nix/store/bhr9lfplzh0352yh4n6gnxdbjqbba7wh--.drv' failed with exit code 1;
       last 7 log lines:
       >
       > In /nix/store/lcd5hrlm9vl4l8j15kqazr5xqm0di25p--/bin/, line 10:
       >   echo -e '## Backend';echo;echo '  , backend-ghcid : Compile the given local package using ghcid.
       >                                  ^-- SC2016 (info): Expressions don't expand in single quotes, use double quotes for that.
       >
       > For more information:
       >   https://www.shellcheck.net/wiki/SC2016 -- Expressions don't expand in singl...
       For full logs, run 'nix log /nix/store/bhr9lfplzh0352yh4n6gnxdbjqbba7wh--.drv'.
error: 1 dependencies of derivation '/nix/store/0rj05a1mlisffwyn649j17sri7bhnz3r-ghc-shell-for-packages-0-env.drv' failed to build

Expose final packages in `config`

... so that users can manually wire it to their flake outputs. For example, they can set it to apps.* so as to be able to nix run the scripts without entering the devshell.

This decoupling can also facilitate #24

Add `cdToProjectRoot` option

By default we cd automatically to the project root (as determined by flake-root module) before launching the script. It should be possible to disable this feature via a per-script option.

We need this for defining scripts like ghcid which can take arguments that are relative paths.

FLAKE_ROOT="''$(${lib.getExe flake-root})"
cd "$FLAKE_ROOT"
exec "$@"

Add `flakeApp` option

This,

   fmt = { 
     exec = "${lib.getExe pkgs.nixpkgs-fmt} ./*.nix"; 
     flakeApp = true;
   }; 

... would wire a flake app of the same name, so that nix run .#fmt will work (in addition to nix develop -c , fmt).

Useful in https://github.com/srid/nixos-config for running activation without entering the devShell. Useful for users who do not use direnv, as well.

cc @marijanp

Add zsh and bash shell completion

In the example nix shell, typing , followed by hitting the TAB should auto-complete the user-configured script names (hello and fmt in the case of the example). This should work on both bash and zsh (inasmuch as macOS uses zsh by default).

The code for this could potentially go here:

# TODO: bash and zsh completion
postInstall = (oa.postInstall or "") + ''
'';

For reference, see how purs-nix implements it:
https://github.com/purs-nix/purs-nix/blob/0fae0fd9316a20e2312cfdbcb8135b0e56330e01/purs-nix-command.nix#L254-L271

Add template

You could do something like this to avoid copying the lock:

      flake = {
        templates.default.path = (inputs.nixpkgs.lib.cleanSourceWith {
          src = ./.;
          filter = path: type: baseNameOf path == "flake.nix";
        }).outPath;
      };

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.