Home

Awesome

nixos-flake-example

warning

WARNING: You should understand that:

overview

NOTE: nixflk is a better example repo for a full NixOS config layout, this repo is mostly to provide more context+examples around flakes, and to show that you can produce the same EXACT system with flakes as with nix-build, if you know what to do.

This readme starts out with an attempt to explain and justify flakes. It also contains some examples of nix cli flakes syntax and tips for adopting flakes in your project.

Finally, at the end of the readme is an example NixOS config with a supporting flake.nix, and instructions to build it with and without flakes support at the same time.

Overview of Flakes (and why you want it)

Flakes is a few things:

This ultimately enables:

This removes the need for:

Important Related Reading

Nix CLI - Flakes Usage

Nix is in flakes mode when:

When in this mode:

Useful Commands and Examples

nixos-rebuild

nix build

nix flake

Auto-coercion examples

Nix CLI will try to be ... smart and auto-coerce some output attribute paths for you.

Tips for Porting to Flakes

Remove Impurities - Since nix flakes does a 'pure' build by default,

To fix these:

Example NixOS Config with optional Flake support

Consider the nixos configuration in this repo:

These represent an example, minimal NixOS system configuration.

The easiest way to build it, without cloning this repo:

nix build 'github:colemickens/nixos-flake-example#nixosConfigurations.mysystem.config.system.build.toplevel'

Let's prove that we can build this config, with and without flakes:

Flake Feedback/Ponderings