Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev tools quick-install script: Paul's changes #373

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion src/pages/get-building/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ For this example we will scaffold the canonical example, a To-do hApp.

Run the holochain scaffolding tool by typing in your terminal:
```bash
nix-shell https://holochain.love --run "hc scaffold web-app"
nix run github:/holochain/holochain#hc-scaffold -- web-app"
```
You should then see:
```text
Expand Down
32 changes: 16 additions & 16 deletions src/pages/get-building/install-advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@ hide:
---

::: coreconcepts-intro
This guide assumes that you've already followed the [quick installation guide](../install/) and want to learn more about the set up. It describes how to manually recreate and maintain the development environment, use your default shell and preferred code editor with Nix, explains how to install specific versions of Holochain, and discusses why we use `nix develop` in the first place.
This guide assumes that you've already followed the [quick installation guide](../../install/) and want to learn more about the setup. It describes how to manually recreate and maintain the development environment, use your default shell and preferred code editor with Nix, or install specific versions of Holochain, and explains why we use `nix develop` in the first place.
:::

## Holonix - the Holochain app development environment
## Holonix, the Holochain app development environment

Each Holochain application repository will contain its own setup of the development environment.
If you use the scaffolding to generate the project structure, this will already be taken care of in the scaffolded directory.

If you want to learn more about how this setup works and how to create it manually and how to maintain it, please find all the information below.

### Holonix's usage of [Nix's Flakes](https://nixos.wiki/wiki/Flakes) features
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Holonix's usage of [Nix's Flakes](https://nixos.wiki/wiki/Flakes) features
### Holonix's usage of [Nix Flakes](https://nixos.wiki/wiki/Flakes) features


### Holonix' usage of [Nix' Flakes](https://nixos.wiki/wiki/Flakes) features

As of [holochain#1863](https://github.com/holochain/holochain/pull/1863) Holonix is implemented as Holochain's [flake.nix](https://github.com/holochain/holochain/blob/develop/flake.nix) output named _#holonix_ a.k.a. _devShells.${system}.holonix_.
As of [holochain#1863](https://github.com/holochain/holochain/pull/1863) Holonix is implemented as Holochain's [`flake.nix`](https://github.com/holochain/holochain/blob/develop/flake.nix) output named `#holonix` a.k.a. `devShells.${system}.holonix`.

The flake-based one-liner to get you an ad-hoc Holonix shell looks like this:

```shell
nix develop github:holochain/holochain#holonix
```

#### Enabling Flake features on your system

At the time of writing, flakes are still considered an experimental in the nix world and thus require being enabled. This happens either ad-hoc on the command itself or permanently via Nix's configuration.

If you've completed the [quick installation guide](../install/), including the scaffolding example, then you'll likely already had the scaffolding configure it for you via the file at _~/.config/nix/nix.conf_.
If you've completed the [quick installation guide](../../install/), then the install script will have already configured this for you via the file at `~/.config/nix/nix.conf`.

To manually configure it via this file you can run the following commands:

Expand Down Expand Up @@ -78,12 +78,13 @@ In the root directory of your app's code, you will either find the scaffolded on
In principle a flake implements a function that produces a set of _outputs_ from a given set of _inputs_, keeping the side-effects to an absolute minimum if not at zero.

#### `inputs`
This flake declares one input named `holochain-flake` that the Holochain Github repository. This input will look for a `flake.nix` in the default branch of the remote repository.
The `versions` input of the `holochain-flake` input is explicitly specified to track the _0_1_ series, which refers to Holochain's Beta 0.1 and its compatible tools.

The flake follows (think inherits) the `nixpkgs` input of the `holochain-flake` input. This ensures that your development environment passes all the same buildinputs to the component packages, giving you very high chances to make use of our Cachix binary cache.
This flake declares one input named `holochain-flake` that the Holochain Github repository. This input will look for a `flake.nix` in the default branch of the remote repository. The `versions` input of the `holochain-flake` input is explicitly specified to track the _0_1_ series, which refers to Holochain's Beta 0.1 and its compatible tools.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This flake declares one input named `holochain-flake` that the Holochain Github repository. This input will look for a `flake.nix` in the default branch of the remote repository. The `versions` input of the `holochain-flake` input is explicitly specified to track the _0_1_ series, which refers to Holochain's Beta 0.1 and its compatible tools.
This flake declares one input named `holochain-flake` that represents the Holochain Github repository. This input will look for a `flake.nix` in the default branch of the remote repository. The `versions` input of the `holochain-flake` input is explicitly specified to track the _0_1_ series, which refers to Holochain's Beta 0.1 and its compatible tools.


The flake follows (think _inherits_) the `nixpkgs` input of the `holochain-flake` input. This ensures that your development environment passes all the same buildinputs to the component packages, giving you very high chances to make use of our Cachix binary cache.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The flake follows (think _inherits_) the `nixpkgs` input of the `holochain-flake` input. This ensures that your development environment passes all the same buildinputs to the component packages, giving you very high chances to make use of our Cachix binary cache.
The flake follows (think _inherits_) the `nixpkgs` input of the `holochain-flake` input. This ensures that your development environment passes all the same build inputs to the component packages, giving you very high chances to make use of our Cachix binary cache.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but it's one word, even though a compound one 🤔 maybe build-inputs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In plain English it's not one word. If you want to use syntax, then put it in "quotes" or in back ticks.


#### `outputs`

In the `outputs` set, this flake composes a devShell that inherits its inputs from the `holonix` devShell and adds the NodeJS package.
To find the names of the packages you're interested in, the [nixos.org package search](https://search.nixos.org/packages?channel=unstable&) can be used.

Expand All @@ -94,9 +95,9 @@ The resulting `flake.lock` records pinned references to all the `inputs` at the

### A Gotcha with Flakes and Git

The behavior of `nix` commands that rely on a `flake.nix` as its input such as `nix develop` can be counterintuitive in a git repository.
The behavior of `nix` commands that rely on a `flake.nix` as its input such as `nix develop` can be counterintuitive in a Git repository.

Specifically, if the `flake.nix` is not tracked in git, the command will fail altogether with a message that it cannot find a `flake.nix` file. Even though by design, this is a [known UX issue in Nix](https://github.com/NixOS/nix/issues/6642).
Specifically, if the `flake.nix` is not tracked in Git, the command will fail altogether with a message that it cannot find a `flake.nix` file. Even though by design, this is a [known UX issue in Nix](https://github.com/NixOS/nix/issues/6642).

The simple solution to is to `git add flake.*` after your initial creation of your flake if you manually create a repository. In case of scaffolding a repository this is taken care of by the scaffolding process for you.

Expand All @@ -114,8 +115,7 @@ If you want to only update a specific input, you can use the following command.
$ nix flake lock --update-input holochain
```

_Note that if your directory is a git repository it is recommended to `git commit flake.lock` to ensure consistency between the development environment and your app's source code._

_Note that if your directory is a Git repository it is recommended to `git commit flake.lock` to ensure consistency between the development environment and your app's source code._

### Holonix inspection commands

Expand Down Expand Up @@ -194,7 +194,7 @@ To do this, just open your editor from the command line while you are in the `ni
```shell
nix develop github:holochain/holochain#holonix
cd my_project
vim my_file.rs
codium my_file.rs
```

## More info on Nix
Expand All @@ -219,9 +219,9 @@ The full suite of Nix tooling is broad and deep. There’s even a dedicated prog

### `nix develop`

While working on Holochain, you will usually have an active `nix develop` to run commands. This shell overlays Holochain-specific configuration on top of your existing shell - environment variables, Rust toolchains, binaries, libraries, and development tools - giving you a consistent development environment to build Holochain apps. The shell environment is only set up in the current shell session, and will be reset automatically when you `exit` the shell.
While working on Holochain, you will usually have an active `nix develop` to run commands. This shell overlays Holochain-specific configuration on top of your existing shell --- environment variables, Rust toolchains, binaries, libraries, and development tools --- giving you a consistent development environment to build Holochain apps. The shell environment is only set up in the current shell session, and will be reset automatically when you `exit` the shell.

If you want to re-enter the shell to do more work, or create multiple terminals to work in, you'll need to re-enter the `nix develop` in each new instance. The packages are cached locally on your machine, so they will be ready the next time you enter the shell. You do need to get the package configuration files from somewhere, though. If you use the Holochain repo cloning method, they're cached on your machine too, but the ['quick install'](../install/) and ['using a specific version'](#using-a-specific-version-of-the-development-tools) methods require an internet connection every time you want to enter the shell.
If you want to do more work, or create multiple terminals to work in, you'll need to re-enter the `nix develop` shell in each new instance. The packages are cached locally on your machine, so they will be ready the next time you enter the shell. If you follow the practices above to create a per-project `flake.nix` file, you can work completely offline, but you need an internet connection in order to enter the [ad-hoc shell](#holonix%27s-usage-of-nix%27s-flakes-features). If you're going to be working offline, you can [download a snapshot of the holochain GitHub repository](https://github.com/holochain/holochain/archive/refs/heads/develop.zip) and enter the shell once using the contained `flake.nix`. After that, the packages will be cached and you can continue to use this flake for ad-hoc shells.
Copy link
Member

@steveej steveej Feb 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-reading this it's actually somewhat confusing. specifically, in my mind the offline instructions mentioning the snapshot and its flake.nix blur into setting up a custom flake.nix and working offline with that. this paragraph just seems to try to cram too much information in it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, fair enough. Is there a skeleton flake.nix that we can put there instead?

And also -- is it actually true that this is all you need in order to work offline? Just have a local flake.nix and enter it once while you're online?

Copy link
Collaborator Author

@pdaoust pdaoust Feb 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If you want to do more work, or create multiple terminals to work in, you'll need to re-enter the `nix develop` shell in each new instance. The packages are cached locally on your machine, so they will be ready the next time you enter the shell. If you follow the practices above to create a per-project `flake.nix` file, you can work completely offline, but you need an internet connection in order to enter the [ad-hoc shell](#holonix%27s-usage-of-nix%27s-flakes-features). If you're going to be working offline, you can [download a snapshot of the holochain GitHub repository](https://github.com/holochain/holochain/archive/refs/heads/develop.zip) and enter the shell once using the contained `flake.nix`. After that, the packages will be cached and you can continue to use this flake for ad-hoc shells.
If you want to do more work, or create multiple terminals to work in, you'll need to re-enter the `nix develop` shell in each new instance. The packages are cached locally on your machine, so they will be ready the next time you enter the shell. If you follow the practices above to create a per-project `flake.nix` file, you can work completely offline, but you need an internet connection in order to enter the [ad-hoc shell](#holonix%27s-usage-of-nix%27s-flakes-features). If you're going to be working offline, you can copy the following code into a `flake.nix` file, then enter the shell using `nix run flake.nix#holonix` once before you go offline. The packages will all be cached, and you can use the same command to enter an ad-hoc shell while you are offline.
```nix
inputs = {
holochain-flake = {
url = "github:holochain/holochain";
};
};

just a wild guess that this would work ☝🏼 testing my understanding by writing code for review!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, doesn't work. The files are cached and you can enter a per-project nix develop shell while offline (albeit with a few spurious errors), but that skeleton didn't do anything productive.


## Uninstalling Nix

Expand Down
32 changes: 6 additions & 26 deletions src/pages/quick-start/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,29 @@ pageStyleId: install
* 30GB+ available disk space
* High Speed Internet connection

## Install Holochain on Linux, macOS and Windows
## Holochain on Linux, macOS and Windows

!!! note Prerequisite for Windows: WSL2

Holochain development uses the same tools across Mac, Windows, and Linux. However, the Nix toolkit, which we use to install and manage those tools, only works natively on Mac and Linux. Linux can be run under Windows with [WSL2 (Windows Subsystem for Linux)](https://learn.microsoft.com/en-us/windows/wsl/install){target=_blank}.
The Nix package manager, which we use to install and manage Holochain development tools, only supports Mac and Linux. Linux can be run under Windows with [WSL2 (Windows Subsystem for Linux)](https://learn.microsoft.com/en-us/windows/wsl/install){target=_blank}.

_Holochain is supported for the Ubuntu distribution under WSL2._
!!!

### Install the Nix Package Manager
### Install the Nix Package Manager & set up Holochain binary cache

At a command line:

```bash
sh <(curl -L https://nixos.org/nix/install) --daemon
bash <(curl https://holochain.github.io/holochain/setup.sh)
```

After installing Nix, close the terminal and open a new one.

Check that Nix is correctly installed:

```bash
nix-shell --version
```

You should see something like:

```bash
nix-shell (Nix) 2.13.2
```

Run the following command to set up the cache for precompiled Holochain executables:

```bash
sudo --preserve-env=PATH $(which nix) run nixpkgs/nixos-22.11#cachix --extra-experimental-features nix-command --extra-experimental-features flakes -- use holochain-ci -m root-nixconf && sudo pkill nix-daemon
```

## Scaffold Your First Holochain App
### Scaffold Your First Holochain App

Type the following at the command line:

```bash
nix-shell https://holochain.love --run "hc scaffold example forum"
nix run github:holochain/holochain#hc-scaffold -- example forum
```

When prompted, select the UI framework you prefer.
Expand Down