# Installing Packages from Nix Flakes
Source: https://www.jetify.com/docs/docs/devbox/guides/using-flakes/index

Devbox supports installing packages with .

Devbox currently provides two ways to use Flakes to install packages in your project:

1. You can reference a Flake hosted in Github using the `github:` reference
2. You can reference a local Flake using the `path:` reference

## What are Flakes?[​](#what-are-flakes "Direct link to What are Flakes?")

[Flakes](https://www.jetify.com/blog/powered-by-flakes/) are a new feature in the Nix language that
lets you package software and create development shells in a declarative, fully reproducible way.
You can use Nix Flakes to define packages, apps, templates, and dev environments.

Flakes are defined as a directory with a `flake.nix` and a `flake.lock` file. You import flakes to
your project using a flake reference, which describes where to find the Flake, and what version or
revision to use

## Using a Flake from Github[​](#using-a-flake-from-github "Direct link to Using a Flake from Github")

You can add a Flake hosted on Github using the following string in your packages list:

```
"packages": [    "github:<org>/<repo>/<ref>#<optional_flake_attr>"]
```

The Ref and Flake Attribute is optional and will default to the main branch and
`packages.default|defaultPackage` attribute, respectively.

For example, to install [Process Compose](https://github.com/F1bonacc1/process-compose) from its
repository using Nix Flakes, you can use the following string in your packages list. This will
install the latest version of Process Compose from the `main` branch.

```nix theme={null}
github:F1bonacc1/process-compose
```

### Installing a Flake from a specific branch or tag[​](#installing-a-flake-from-a-specific-branch-or-tag "Direct link to Installing a Flake from a specific branch or tag")

You can install a specific release or branch by adding it to your flake reference. The following
example will install Process Compose version 0.40.2 from the `v0.40.2` tag.

```nix theme={null}
github:F1bonacc1/process-compose/v0.40.2
```

### Installing a specific attribute or package from a Flake[​](#installing-a-specific-attribute-or-package-from-a-flake "Direct link to Installing a specific attribute or package from a Flake")

You can also install a specific attribute or package from a Flake by adding a `#` and the attribute
name to the end of the package string. If you don't specify an attribute, Devbox will use `default`
or `defaultPackage`

For example, if you want to use [Fenix](https://github.com/nix-community/fenix) to install a
specific version of Rust, you can use the following string in your packages list. This example will
install the `stable.toolchain` packages from the `fenix` package.

```nix theme={null}
github:nix-community/fenix#stable.toolchain
```

### Using Flakes with Nixpkgs[​](#using-flakes-with-nixpkgs "Direct link to Using Flakes with Nixpkgs")

The Nixpkgs repo on Github also provides a Flake for installing packages. You can use the following
flake reference to install packages from a specific Nixpkgs commit or reference:

```nix theme={null}
github:NixOS/nixpkgs/<ref>#<package>
```

For example, if you want to install the `hello` package from the `nixos-20.09` branch, you can use
the following string in your packages list:

```nix theme={null}
github:NixOS/nixpkgs/nixos-20.09#hello
```

## Installing Additional Outputs from a Flake[​](#installing-additional-outputs-from-a-flake "Direct link to Installing Additional Outputs from a Flake")

Some packages provide additional outputs that are not installed by default. For example, the
`libcap` package provides a `dev` output that contains development headers and libraries, or the
`prometheus` package includes the `promtool` CLI in a `cli` output.

You can install these additional outputs by adding a `^` and a comma-separated list of outputs to
the end of your flake reference. For example, the following command will install the default (`out`)
and `dev` outputs of the `libcap` package:

```nix theme={null}
github:nixos/nixpkgs#libcap^out,dev
```

## Using a Local Flake[​](#using-a-local-flake "Direct link to Using a Local Flake")

You can also use a local Flake using the `path` attribute in your package list. Using a local flake
can be helpful if you want to install your custom packages with Nix, or if you need to modify
packages before using them in your Devbox project

Your flake reference should point to a directory that contains a `flake.nix` file.

```
path:<path_to_flake>#<optional_flake_attr>
```

For example, if you have a local Flake in the `./my-flake` directory, you can use the following
string in your `packages` list. This example will install all the packages under the `my-package`
attribute.

```nix theme={null}
path:./my-flake#my-package
```

## Caching Flakes with the Jetify Cache[​](#caching-flakes-with-the-jetify-cache "Direct link to Caching Flakes with the Jetify Cache")

Because flakes are not automatically built and cached by Nix, you may experience slower build times
when using flakes in your Devbox project. To speed up your builds, you can use the
[Jetify Cache](/docs/cloud/cache/) to cache the binaries built by your flakes for future use.

After setting up your cache directly, you can upload the flake by running:

```bash theme={null}
devbox cache upload <flake-reference>
```

Alternatively, you can cache your entire project closure by running the following command from your
project root:

```bash theme={null}
devbox cache upload
```

### Examples[​](#examples "Direct link to Examples")

For more examples of using Nix Flakes with Devbox, check out the examples in our Devbox Repo:

* [Using Nix Flakes from Github](https://github.com/jetify-com/devbox/tree/main/examples/flakes/remote)
* [Using a Local Flake](https://github.com/jetify-com/devbox/tree/main/examples/flakes/php)
* [Applying an Overlay with Nix Flakes](https://github.com/jetify-com/devbox/tree/main/examples/flakes/overlay)

[Edit this page](https://github.com/jetify-com/devbox/tree/main/docs/app/docs/guides/using-flakes.md)