Skip to content

danieljharvey/nix-mate

Repository files navigation

nix-mate

Install things! Delete them again! Install them again! Delete them again! It's up to you!

Nix Mate is a (very much WIP) terminal front end to the Nix Package Manager. It allows clean installation of per-project dependencies.

Installation

You will need the following installed:

Nix - install instructions

Direnv - install instructions

MacOS

Easy!

brew update && brew install danieljharvey/tools/nix-mate

Ubuntu

Currently no nice packaging available, but binaries can be downloaded from the releases page.

Getting started

Set up a nix-mate project

mkdir my-excellent-project
cd my-excellent-project
nix-mate init

This will setup a new project in this folder. Direnv will probably ask you to run direnv allow at this point, so go for it.

Adding a package

nix-mate add cowsay

This will make the cowsay binary available whilst you are inside the project directory.

Removing a package

nix-mate remove cowsay

This will remove the cowsay binary from your project directory.

Searching for packages

nix-mate search nodejs

This will show a big list of packages matching that name that you can install.

Versions of nixpkgs

nix-mate uses a pinned version of nixpkgs for installing so that we get the same result every time.

View available versions

To view the available versions of nixpkgs run:

nix-mate tags

This will display all the available versions.

Use a specific version

You can choose to use a version using:

nix-mate set-version <version-number>
# for example
nix-mate set-version 19.03

This will update your project to use this new version.

Use most up to date version

If you'd just prefer to stay up to date, use:

nix-mate update

This will use the newest version.

Pinning to a custom nixpkgs commit

First, you will need to get the git hash for the commit you wish to use at nixpkgs. Then run

nix-mate pin <commit-hash>

# for example
nix-mate pin 1f795f9f44607cc5bec70d1300150bfefcef2aae

Create a Docker image

We can create and load a Docker image containing your project dependencies by running nix-mate docker. This will create an image called <project-name>:latest. This command creates Linux-based images, so if you are using MacOS, you will need to install https://github.com/nix-community/linuxkit-nix

Install as follows:

# install linux-kit
nix-env -i /nix/store/jgq3savsyyrpsxvjlrz41nx09z7r0lch-linuxkit-builder

# remove old config
rm -rf ~/.cache/nix-linuxkit-builder

# setup linux-kit
nix-linuxkit-configure

# add linuxkit ssh config to local ssh config
sudo cat /var/root/.ssh/nix-linuxkit-ssh-config >> ~/.ssh/config

Who is this for?

This project is for users that would usually install project dependencies with brew or apt-get and would like a declarative way to do this per-project.

If you're already familiar with Nix-the-language, then this project isn't for you. If you're happy creating your own shell.nix files etc and want more control, then there are great tools like lorri out there for just this.

Releasing a new version

git tag v0.0.1231233
git push origin --tags

Then, fill in the release info on the created page.