Skip to content

Commit

Permalink
add: nixpkgs.md
Browse files Browse the repository at this point in the history
  • Loading branch information
srid committed Dec 7, 2023
1 parent 297d95e commit b0a4bf7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
6 changes: 3 additions & 3 deletions en/blog/nix-rapid.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ $ nix eval .#foo

### Graph

A flake can refer to other flakes in its inputs. Phrased differently, a flake's outputs can be used as inputs in other flakes. The most common example is the [nixpkgs](https://zero-to-nix.com/concepts/nixpkgs) flake which gets used as an input in most flakes. Intuitively, you may visualize a flake to be a node in a larger graph, with inputs being the incoming arrows and outputs being the outgoing arrows.
A flake can refer to other flakes in its inputs. Phrased differently, a flake's outputs can be used as inputs in other flakes. The most common example is the [[nixpkgs]] flake which gets used as an input in most flakes. Intuitively, you may visualize a flake to be a node in a larger graph, with inputs being the incoming arrows and outputs being the outgoing arrows.

### Inputs

> [!info] To learn more
> - [URL-like syntax][flake-url] used by the `url` attribute
Let's do something more interesting with our `flake.nix` by adding the nixpkgs input:
Let's do something more interesting with our `flake.nix` by adding the [[nixpkgs]] input:

```nix
{
Expand All @@ -123,7 +123,7 @@ Let's do something more interesting with our `flake.nix` by adding the nixpkgs i
}
```

The nixpkgs flake has an output called `legacyPackages`, which is indexed by the platform (called "system" in Nix-speak), further containing all the packages for that system. We assign that package to our flake output key `foo`.
The [[nixpkgs]] flake has an output called `legacyPackages`, which is indexed by the platform (called "system" in Nix-speak), further containing all the packages for that system. We assign that package to our flake output key `foo`.

>[!tip] You can use [[repl|`nix repl`]] to explore the outputs of any flake, using TAB completion:
>
Expand Down
10 changes: 5 additions & 5 deletions en/blog/nixify-haskell-project-intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Nix is a powerful package manager and build system that provides reproducible an
> We strongly recommend flakes for anyone getting started with Nix. Flakes is [production ready despite being marked as experimental](https://determinate.systems/posts/experimental-does-not-mean-unstable).
>[!info]
> The [Haskell infrastructure in nixpkgs](https://community.flake.parts/haskell-flake/nixpkgs-haskell) is the simplest way to get started with Nixifying a Haskell project. There are also other approaches (like [haskell.nix](https://github.com/input-output-hk/haskell.nix), [stacklock2nix](https://github.com/cdepillabout/stacklock2nix)). Later in the blog post series, we'll explore [haskell-flake](https://community.flake.parts/haskell-flake) which builds on top of the Haskell infrastructure in nixpkgs
> The [Haskell infrastructure in nixpkgs](https://community.flake.parts/haskell-flake/nixpkgs-haskell) is the simplest way to get started with Nixifying a Haskell project. There are also other approaches (like [haskell.nix](https://github.com/input-output-hk/haskell.nix), [stacklock2nix](https://github.com/cdepillabout/stacklock2nix)). Later in the blog post series, we'll explore [haskell-flake](https://community.flake.parts/haskell-flake) which builds on top of the Haskell infrastructure in [[nixpkgs]].

If you're unfamiliar with Nix, we have [[nix-rapid]] available to help you get started quickly or you can take your time and explore it at [Zero to Nix](https://zero-to-nix.com). A basic understanding of the Nix expression language is assumed.
Expand All @@ -32,7 +32,7 @@ can get the development environment up and running with one command.
- **Multi-platform**: Same configuration generally works on macOS, Linux and WSL.

>[!note] macOS support
> Although macOS doesn't have first-class support in nixpkgs, [it is getting there](https://github.com/NixOS/nixpkgs/issues/116341).
> Although [[macos]] doesn't have first-class support in [[nixpkgs]], [it is getting there](https://github.com/NixOS/nixpkgs/issues/116341).
[^1]: Considering the packages are available in Nix for the host platform.

Expand Down Expand Up @@ -90,7 +90,7 @@ A nix flake such as the one above consumes certain `inputs` and produces certain

A flake can reference other flakes, which are specified in the `inputs` attribute. We will use the [URL-like representation](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#url-like-syntax) to specify our input flakes.

In this example, we will use [GNU hello](https://www.gnu.org/software/hello) package from [`nixpkgs`](https://github.com/NixOS/nixpkgs) flake. Therefore, we'll specify the nixpkgs flake as an input, specifically using its `nixpkgs-unstable` branch.
In this example, we will use [GNU hello](https://www.gnu.org/software/hello) package from [[nixpkgs]] flake. Therefore, we'll specify the [[nixpkgs]] flake as an input, specifically using its `nixpkgs-unstable` branch.

>[!note] The `nixpkgs-unstable` naming
> The `nixpkgs-unstable` branch is named as such because of the frequent updates it receives and doesn't imply that it is unsafe.
Expand All @@ -107,7 +107,7 @@ The inputs argument is an attrset containing `self` as well as the flake inputs
[Refer here](https://nixos.wiki/wiki/Flakes#Output_schema) for a detailed schema of `outputs`. Note that the `nixpkgs` key within the inputs attrset refers to the `outputs` of the `flake.nix` located at `nixpkgs.url`. If `nixpkgs.flake = false` is set, then the parameter will represent the source code.

The body of the function defines the flake outputs. Within the `let` block we define two values -- `system` (set as "aarch64-darwin" in this example, assuming we are on an ARM mac) and `pkgs` (referring to nixpkgs packages for `system`). In our example, `system` is hardcoded to a single system, but [forAllSystems](https://zero-to-nix.com/concepts/flakes#system-specificity) can be used to define packages for an array of systems.
The body of the function defines the flake outputs. Within the `let` block we define two values -- `system` (set as "aarch64-darwin" in this example, assuming we are on an ARM mac) and `pkgs` (referring to [[nixpkgs]] packages for `system`). In our example, `system` is hardcoded to a single system, but [forAllSystems](https://zero-to-nix.com/concepts/flakes#system-specificity) can be used to define packages for an array of systems.

Here are some standard outputs a flake may produce:

Expand Down Expand Up @@ -183,7 +183,7 @@ Tl;dr Here is the `flake.nix` for this section:
Let's break it down!
### haskellPackages

Consult [the official manual](https://nixos.org/manual/nixpkgs/unstable/#haskell) to learn more about the Haskell infrastructure in nixpkgs, but for the purpose of our blog post it is suffice to know that:
Consult [the official manual](https://nixos.org/manual/nixpkgs/unstable/#haskell) to learn more about the Haskell infrastructure in [[nixpkgs]], but for the purpose of our blog post it is suffice to know that:

- `pkgs.haskellPackages` is an attribute set that contains all Haskell packages maintained within `nixpkgs`.
- Since our local package (`todo-app`) is not already included in `pkgs.haskellPackages`, we need to manually add it.
Expand Down
7 changes: 7 additions & 0 deletions en/nixpkgs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
nixpkgs (<https://github.com/NixOS/nixpkgs>) contains a collection of [[nix]] packages. It also includes various utility functions for [[nix]], as well as the [[nixos]] Linux distribution.

In [[flakes|flakes]], nixpkgs is the most commonly used input.

## Links

- [Zero to Nix: nixpkgs](https://zero-to-nix.com/concepts/nixpkgs)
2 changes: 1 addition & 1 deletion en/treefmt.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ If there are folders where you wouldn't want to run the formatter on, use the fo

### Use a different package for formatter

The package shipped with the current nixpkgs might not be the desired one, follow the snippet below to override the package (assuming `nixpkgs-21_11` is present in your flake's inputs).
The package shipped with the current [[nixpkgs]] might not be the desired one, follow the snippet below to override the package (assuming `nixpkgs-21_11` is present in your flake's inputs).

```nix
# Inside mkFlake's `perSystem.treefmt.config`
Expand Down

0 comments on commit b0a4bf7

Please sign in to comment.