Skip to content

Quickstart

Nilla provides a single entrypoint with a consistent structure for your Nix projects. In this guide we will learn how to install and run the Nilla CLI, add an input, and create a development shell.

Nilla CLI

To start working with Nilla projects we will need the Nilla CLI. This program makes it easier to do things like build packages, start development shells, etc. Install the Nilla CLI to get started.

Terminal window
# We can install the package imperatively.
nix profile install github:nilla-nix/cli
# Or we can run the Nilla CLI directly on-demand.
nix run github:nilla-nix/cli -- --help

Create a new Nilla project

To start using Nilla, we need to create a nilla.nix file which contains a Nilla project. Let’s begin by using npins to fetch Nilla.

Terminal window
# Initialize npins
npins init --bare
# Pin Nilla
npins add github nilla-nix nilla

Now, we can make our nilla.nix file.

nilla.nix
let
# Import pinned inputs.
pins = import ./npins;
# Import Nilla.
nilla = import pins.nilla;
in
# Create our Nilla project.
nilla.create {
# Your project can be configured here.
}

That is all we need to have a valid Nilla project!

Create a development shell

An empty project isn’t very useful. Let’s add Nixpkgs as an input and use it to create a development shell. To begin, we’ll use npins to fetch Nixpkgs.

Terminal window
# Pin Nixpkgs (you can use any channel you like)
npins add channel nixos-unstable

With Nixpkgs available in our pins, we can add it as an input and declare our shell.

nilla.nix
let
pins = import ./npins;
nilla = import pins.nilla;
in
nilla.create {
config = {
# Add Nixpkgs as an input (match the name you used when pinning).
inputs.nixpkgs.src = pins.nixos-unstable;
# With a package set defined, we can create a shell.
shells.default = {
# Declare what systems the shell can be used on.
systems = [ "x86_64-linux" ];
# Define our shell environment.
shell = { mkShell, hello, ... }:
mkShell {
packages = [
hello
];
};
};
};
}

Running the shell

Now that our development shell is defined in our project, we can use the Nilla CLI to start it.

Terminal window
nilla shell

To check that everything is working correctly, try running hello.

Terminal window
hello