Skip to content
This repository has been archived by the owner on Aug 17, 2023. It is now read-only.

Add documentation for Flakes #23

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft

Conversation

sevanspowell
Copy link
Contributor

  • Add some beginning resources for understanding Nix Flakes.

@sevanspowell sevanspowell self-assigned this Feb 10, 2022
Copy link
Contributor

@rvl rvl left a comment

Choose a reason for hiding this comment

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

Excellent, thanks @sevanspowell !

Can we put all the files flat under docs/code/nix and use order to control their ordering?

And there are also some (but not all) sections from cardano-wallet/docs/contributing/Nix.md that could be integrated here.

docs/code/Flakes/Reference/CommonErrors.md Show resolved Hide resolved
docs/code/Flakes/Tutorials/Hacking.md Outdated Show resolved Hide resolved
docs/code/Flakes/Tutorials/Hacking.md Show resolved Hide resolved
Comment on lines +12 to +31
{
description = "A very basic flake";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.11";
};

outputs = { self, nixpkgs }:
let
pkgs = nixpkgs.legacyPackages.x86_64-linux
in {
devShell.x86_64-linux = pkgs.mkShell {
nativeBuildInputs = [
pkgs.python3
];
};
};
}
```
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we cut down the examples so that they are still self-contained, but only deal with the topic of this page?
For example, remove pinning of nixpkgs, unless the page is about version pinning.

But here is a more interesting example of what could be put in the shell:

Suggested change
{
description = "A very basic flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.11";
};
outputs = { self, nixpkgs }:
let
pkgs = nixpkgs.legacyPackages.x86_64-linux
in {
devShell.x86_64-linux = pkgs.mkShell {
nativeBuildInputs = [
pkgs.python3
];
};
};
}
```
{
description = "Flake with a development environment";
outputs = { self, nixpkgs }: {
devShell.x86_64-linux =
with nixpkgs.legacyPackages.x86_64-linux;
mkShell {
nativeBuildInputs = [
(python3.withPackages (ps: [ ps.numpy ps.toolz ps.requests ]))
];
};
};
}
```
This is an example of adding Python and some Python Wheels to the shell. More information (for those interested) can be found in the
[Nixpkgs Manual Python section](https://nixos.org/manual/nixpkgs/stable/#python).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This builds on tutorial 2, and so I left the version pinning in to minimize required code changes from the last flake.nix, but feel free to remove.

date: 2021-02-09
---

Presuming nix is already installed, Nix flakes are available from Nix version 2.4 and up.
Copy link
Contributor

Choose a reason for hiding this comment

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

experimental-features = nix-command flakes
```

## NixOS
Copy link
Contributor

Choose a reason for hiding this comment

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

NixOS-specific instructions probably aren't necessary. Especially because nix.extraOptions has become nix.settings.experimental-features in the latest nixos-unstable versions.

## Non-NixOS

```
$ nix-env -iA nixpkgs.nixUnstable # or nixpkgs.nix_2_4
Copy link
Contributor

Choose a reason for hiding this comment

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

Simplest way is probably to ask users to run:

nix upgrade-nix

If that doesn't work, then reinstall it using the instructions here: https://nixos.org/manual/nix/stable/installation/installing-binary.html#multi-user-installation

Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't work on NixOS

  nix upgrade-nix 
error: Nix on NixOS must be upgraded via 'nixos-rebuild'

date: 2021-02-09
---

The `flake.nix` has the following schema:
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a feeling this will go out of date, and the original sources could just be linked.
On the other hand, the flake schema is not well documented.
The resources I use are:

  1. Schema - https://nixos.wiki/wiki/Flakes#Flake_schema
  2. Input references - https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-references
  3. Installables - https://nixos.org/manual/nix/stable/command-ref/new-cli/nix.html#installables


- Unify the management of inputs (make redundant tools like `niv`).
- Remove sources of impurity that existed in the previous model.
- Standardize the output format of repositories.
Copy link
Contributor

Choose a reason for hiding this comment

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

One other benefit of this new format is that it facilitates composability, so it becomes easier to connect one flake's outputs to other flake's inputs.

@rvl rvl force-pushed the sevanspowell/flakes-docs branch from e6bbfe1 to 47779b6 Compare April 22, 2022 07:52
@JBlaze2029
Copy link

JBlaze2029 commented Apr 22, 2022 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants