Skip to content

Adding Inputs

Nilla uses a system of loaders to import inputs you define. Out of the box, Nilla is able to load other Nilla projects, Nixpkgs, Nix Flakes, legacy default.nix files, and raw directories. By default, Nilla will try and select the loader for an input automatically by detecting its contents. However, you can customize this by manually setting the loader option for a specific input.

Adding an input

Before modifying your Nilla project, pin your dependency using a tool like npins.

Terminal window
# For example, if the dependency we want to pin is on GitHub
npins add github my-user my-repo --branch main --name my-input

To add a new input to your Nilla project, set the option inputs.<my-input>.

nilla.nix
let
pins = import ./npins;
nilla = import pins.nilla;
in
nilla.create {
config = {
# Let's add a new input.
inputs.my-input = {
# Set the source of our input to the fetched pin.
src = pins.my-input;
# Nilla will automatically set a loader by default, but we can choose one
# manually if we prefer.
#
# Available loaders: nilla, nixpkgs, flake, legacy, raw
loader = "legacy";
# Sometimes we want to apply additional configuration to an input. This can
# be done by giving the loader some settings. Each loader has its own
# settings schema, so be sure to check the documentation for the loader you
# are using.
#
# In this case we will customize the settings for the legacy loader.
settings = {
target = "non-default.nix";
args = {
enableFeature = true;
};
};
};
};
}

Adding pins automatically

Nilla makes it easy to quickly and easily add all of your pinned dependencies to your project. To do so, set your project’s inputs to the following.

nilla.nix
let
pins = import ./npins;
nilla = import pins.nilla;
in
nilla.create {
config = {
# Add each pin as an input.
inputs = builtins.mapAttrs (name: value: { src = value; }) pins;
};
}

Referring to inputs

Once an input has been added, you can access the loaded form of the input via the input’s result attribute.

nilla.nix
let
pins = import ./npins;
nilla = import pins.nilla;
in
# We'll adjust our call to `nilla.create` to be a function so we can access module
# arguments like `config`.
nilla.create ({ config }:
let
# Access the loaded form of `my-input`.
my-input = config.inputs.my-input.result;
in
{
config = {
inputs = builtins.mapAttrs (name: value: { src = value; }) pins;
};
}
)