owned this note
owned this note
Published
Linked with GitHub
# Updating your Holochain dev environment for the new Holonix
###### tags: `Holonix`
## Context
For the Beta 0.1 release we targeted adding full support for MacOS (x86_64 and aarch64) and Windows (WSL2) to our development environment, such that our CI setup could automatically build binaries of the development environment components (like `holochain`, `lair-keystore`, `hc`, etc) on all platforms. Additionally we wanted to improve the mechanism by which developers can specify exactly which versions of which components they want to be automatically loaded into their nix shell.
We determined that achieving these goals would be greatly eased by switching to [Nix Flakes](https://nixos.wiki/wiki/Flakes). So, `holonix` has been re-written and we're happy to say that we've been able to reach these goals.
## What this means
Assuming you have been using holonix (and a `default.nix`) file along with `nix-shell` to load all your development dependencies, this means that:
1. to gain access to any future updates, you will have to start using a `flake.nix` file instead of `default.nix`.
2. to update holonix you will run `nix flake update` instead of `nix-shell --run "niv update"`
3. to open the holonix shell you will run `nix develop` instead of `nix-shell`
4. (in case you want to run an ad-hoc dev shell, type `nix develop github:holochain/holochain#holonix` instead of `nix-shell https://holochain.love`)
## How to switch
If you're running a single-user install of Nix, you will have to reinstall. Refer to these resources on how to uninstall
- https://nixos.org/manual/nix/stable/installation/installing-binary.html?highlight=uninstal#uninstalling.
- https://gist.github.com/chriselsner/3ebe962a4c4bd1f14d39897fc5619732#uninstalling-nix
Please follow the instructions here: https://developer.holochain.org/quick-start/ in the section marked: *Install the Nix Package Manager*.
> NOTE: those instructions now install nix in the multi-user context. As you have probably previously installed nix in the single user context, you may have to manually remove nix file. When you re-run the Nix installer, it will give you instructions on how to do this. However, you may have to manually remove any `substituters` that were added to your `~/.config/nix/nix.conf` file from previous installs.
In your hApp directory remove the old nix files with:
```bash
$ git rm -r nix
$ git rm default.nix
```
Enable Nix commands and Nix flakes for your use:
```bash
mkdir -p ~/.config/nix
echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf
```
Create a new `flake.nix` file at the root level of your hApp directory containing:
```nix=
{
description = "Flake for Holochain app development";
inputs = {
nixpkgs.follows = "holochain-dev/nixpkgs";
holochain-dev = {
url = "github:holochain/holochain";
inputs.versions.url = "github:holochain/holochain/?dir=versions/0_1";
};
};
outputs = inputs @ { ... }:
inputs.holochain-dev.inputs.flake-parts.lib.mkFlake
{
inherit inputs;
}
{
systems = builtins.attrNames inputs.holochain-dev.devShells;
perSystem =
{ config
, pkgs
, system
, ...
}: {
devShells.default = pkgs.mkShell {
inputsFrom = [ inputs.holochain-dev.devShells.${system}.holonix ];
packages = [ pkgs.nodejs-18_x ];
};
};
};
}
```
Now add the flake file to git with:
```bash
$ git add flake.nix
```
Then you can initialize the `flake.lock` file for the first time with:
```
$ nix flake update
```
This command looks up the revisions of the components and locks them in the `flake.lock` file.
Note: When you run `nix flake update` again, the latest available revisions of all inputs will be looked up again and the lock-file will be updated. The `flake.nix` above is set up so that this kind of update will only update to the latest components that are compatible with Holochain 0.1.
Now add the `flake.lock` file to git with:
```bash
$ git add flake.lock
```
Now you can enter the nix shell with:
```bash
$ nix develop
```
You should then see something like this:
```shell
Holochain development shell spawned. Type exit to leave.
[holonix:~/path/to/my/happ]$
```
## How to pick specific component versions
Edit your flake file to override the inputs like this for example, which picks a different version of the `holochain` component, which includes the conductor and the `hc` CLI tool:
```nix
inputs = {
...
holochain-dev = {
url = "github:holochain/holochain";
inputs.versions.url = "github:holochain/holochain?dir=versions/0_1";
inputs.versions.inputs.holochain.url = "github:holochain/holochain/<whichever-git-branch-tag-or-commit>";
};
...
```
You can override the versions of four different Holochain components: `holochain`, `lair`, `launcher`, and `scaffolding`. The `inputs.versions.url` field points to a file in the `holochain/holochain` GitHub repo containing versions of each of these which are known to be mutually compatible. As you can see in the snippet above, the URLs of any of those components can be overridden. Take a look at the [versions flake](https://github.com/holochain/holochain/blob/develop/versions/0_1/flake.nix) for an example of how we specify their URLs using Git tags.
<!--
The input names of all the currently included components can be found with this command:
$ nix flake metadata github:holochain/holochain --json | jq --raw-output '.locks.nodes.versions.inputs | .[]'
holochain
lair
launcher
scaffolding
-->
Note that by specifying custom component URLs, you will probably get a binary cache miss when entering the shell, and it will have to compile the custom component versions ad-hoc.
## What's different in the new shell
The new holonix has removed all the old `hn-X` commands, specifically the one most folks used is the `hn-versions` command. Instead that has been replaced with `hn-introspect`:
```text
[holonix:~/myapp]$ hn-introspect
holochain (holochain 0.1.3): ed5b7bb461c2a8bfd4d2633bad604a20b8f2da03
lair-keystore (lair_keystore 0.2.3): cbfbefefe43073904a914c8181a450209a74167b
hc-launch (holochain_cli_launch 0.0.10): b3a14c79198ef0b52f55a0e646a371fcb49f53e4
hc-scaffold (holochain_scaffolding_cli 0.1.6): 519e23c31f094fb49d12d24094a6a5b688a8ff86
```