A minimal wrapper around nixpkgs' `pkgs.mkShell`.

Files
README.md

tinyshell #

tinyshell is a minimal wrapper around nixpkgs' mkShell and mkShellNoCC builders, specifically offering the following functionality:

  • Automatically determining and setting the PRJ_ROOT environment variable.
    • git rev-parse --show-toplevel is used for this. If the project is not a git repository, this will default to $PWD instead.
  • Automatically determining and setting the PRJ_DATA_DIR environment variable. (Disable with setDataDir = false;)
    • Automatically creating the PRJ_DATA_DIR directory ($PRJ_ROOT/.data). (Disable with createDataDir = false;)

This is meant to offer some of the utility of something like devshell without the extraneous dependencies.

Usage #

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    systems.url = "github:nix-systems/default";
    tinyshell.url = "git+https://tangled.org/csw.im/tinyshell";
  };

  outputs = {
    nixpkgs,
    systems,
    tinyshell,
    ...
  }: let
    eachSystem = f: (nixpkgs.lib.genAttrs (import systems) (
      system: f system (import nixpkgs {inherit system;})
    ));
  in {
    devShells = eachSystem (system: pkgs: {
      default = (tinyshell.lib pkgs).mkTinyShell {
        shellHook = ''echo "Project root: $PRJ_ROOT"'';
      };
    });
  };
}

Templates #

tinyshell offers some minimal templates to get you started.

simple (default) #

Just the bare-bones tinyshell. No flake-utils, nothing extra but nix-systems.

nix flake init -t git+https://tangled.org/csw.im/tinyshell#simple

nixhooks #

A tinyshell with nixhooks configured.

nix flake init -t git+https://tangled.org/csw.im/tinyshell#nixhooks

Function Reference #

Exported functions #

Function Underlying implementation Description
mkTinyShell pkgs.mkShell Creates a development shell with the tinyshell project-root and data-directory setup.
mkTinyShellNoCC pkgs.mkShellNoCC Same tinyshell setup, using pkgs.mkShellNoCC for shells that do not need a C compiler toolchain by default.

_mkTinyShell Arguments #

All arguments understood by tinyshell (those listed below, aside from ...) are removed from the arguments passed through to the underlying mkShell implementation.

Argument Type Default Description
shellHook String "" Additional shell commands appended to the generated shell hook.
projectVarName String PRJ_ROOT The name of the environment variable to export the project's root directory to.
dataDirVarName String PRJ_DATA_DIR The name of the environment variable to export the project's data directory to.
dataDir String or null ".data" Relative path to the project data directory, resolved against projectVarName. Set to null to disable data-directory configuration and creation.
setDataDir Boolean dataDir != null Whether to export ${dataDirVarName} as ${projectVarName}/${dataDir}.
createDataDir Boolean setDataDir Whether to create the directory specified by dataDirVarName using mkdir -vp. Requires setDataDir = true.
gitPackage Derivation pkgs.git Git package used to determine the project root with git rev-parse --show-toplevel. Falls back to $PWD if the command fails.
... — — Accepts additional arguments supported by pkgs.mkShell or pkgs.mkShellNoCC, such as packages, buildInputs, and nativeBuildInputs.