Nix flakes
Nix flakes provide a standardized interface for nixified git repos. garnix reads the flake.nix file from the root directory of your repos and uses the flake outputs — the declared packages, apps and NixOS configurations — to figure out what to build, run and deploy.
Here's a very simple example flake.nix file:
{ inputs = { nixpkgs.url = "github:nixos/nixpkgs"; }; outputs = { self, nixpkgs }: { packages.x86_64-linux = let pkgs = import nixpkgs { system = "x86_64-linux"; }; in { myExamplePackage = pkgs.runCommand "example" { } '' echo hello from nix! echo "build output" > $out ''; }; }; }
You can build the flake locally with:
nix build -L .#myExamplePackage
Further reading about Nix flakes:
-
If you're new to writing flakes we recommend you start by looking at this three-part flakes tutorial written by Eelco Dolstra, the creator of nix.
-
Xe Iaso's nix flakes series is also wonderful!
-
We've written a blog post that show you how to convert an existing nix project to flakes.
-
The Nix wiki page about flakes.