Skip to content

Commit

Permalink
docs(concepts): add nix to concepts
Browse files Browse the repository at this point in the history
  • Loading branch information
woile committed Jul 22, 2023
1 parent 971ea3d commit 31ee96f
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 1 deletion.
3 changes: 2 additions & 1 deletion site/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
- [Define a Module in a Separate File](./define-module-in-separate-file.md)
- [Define Custom Flake Attribute](./define-custom-flake-attribute.md)
- [Dogfood a Reusable Flake Module](./dogfood-a-reusable-module.md)
- [Explanation]()
- [Concepts]()
- [Nix](./nix.md)
- [Overlays](./overlays.md)
- [Reference Documentation]()
- [Module Arguments](./module-arguments.md)
Expand Down
103 changes: 103 additions & 0 deletions site/src/nix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Nix

This is a brief introduction to nix, in the context of flake-parts.

## What is nix?

When you read `nix`, depending on the context, it may refer to one or more of the following concepts:

1. An GNU/Linux distribution, called [NixOS](https://nixos.org/)
2. A language, called the [Nix Language](https://nixos.org/manual/nix/stable/language/index.html)
3. A package manager, see [package management](https://nixos.org/manual/nix/stable/package-management/package-management.html) or [install nix](https://nix.dev/tutorials/install-nix).

NixOS makes use of the package manager and the nix language.
But you don't need to run nixos to use the package manager, or the language.

## What are Nixpkgs?

[Nixpkgs](https://nixos.org/manual/nixpkgs/stable/) are one of the biggest collections of packages.
It's written in the Nix Language, and it's used by the nix package manager. Check the [supported platforms](https://nixos.org/manual/nix/stable/installation/supported-platforms.html).

You can search for packages on [search.nixos.org/packages](https://search.nixos.org/packages)

## How does the nix language look?

The Nix Language is, in a way, **similar** to JSON with support for functions.

```nix
{
string = "hello";
integer = 1;
float = 3.141;
bool = true;
null = null;
list = [ 1 "two" false ];
flat.objects.user = {
name = "foo";
};
}
```

```console
$ nix eval -f sample.nix
{ bool = true; flat = { objects = { user = { name = "foo"; }; }; }; float = 3.141; integer = 1; list = [ 1 "two" false ]; null = null; string = "hello"; }
```

You can even output JSON!

```console
$ nix eval --json -f sample.nix
{
"bool": true,
"flat": { "objects": { "user": { "name": "foo" } } },
"float": 3.141,
"integer": 1,
"list": [1, "two", false],
"null": null,
"string": "hello"
}
```

And a function:

```nix
{ name }: {
hello = "My name is ${name}, running on ${builtins.currentSystem}";
}
```

```console
$ nix-instantiate --eval hello.nix --argstr name jon -A hello
"My name is jon, running on x86_64-darwin"
```

To learn more, head to

- [nix.dev's nix language tutorial](https://nix.dev/tutorials/first-steps/nix-language) or;
- [A tour of Nix](https://nixcloud.io/tour/?id=1).

## What are people using nix for?

- To package applications (with flakes)
- A declarative CI ([hercules-ci](https://hercules-ci.com/))
- Control a fleet of machines (using [nixops](https://nixos.wiki/wiki/NixOps), [deploy-rs](https://github.com/serokell/deploy-rs))
- Manage dotfiles
- As a configuration or template language ([terranix](https://terranix.org/))

See more in [awesome-nix](https://github.com/nix-community/awesome-nix).

## What are nix flakes?

Nix flakes are one the newest features in the nix ecosystem, built on top of the experience with nix and its ecosystem.

The main idea is to have a file called `flake.nix` with a set of [standardized outputs](https://nixos.wiki/wiki/Flakes#Output_schema). You can also reference to other flakes, and a `flake.lock` file is used to guarantee reproducibility.

Still **considered experimental**, flakes enable packaging applications in a distributed manner.

- [nix flake manual](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html)
- [nix.dev flakes](https://nix.dev/concepts/flakes)

## What is flake-parts for?

flake-parts makes writing flakes easier, by establishing a way of working with [system](./system.md).
On top of that, it makes easier to write and reuse modules.

0 comments on commit 31ee96f

Please sign in to comment.