Nix By Examples

Basics

The Nix Language

Flakes

flake-utils

flake.nix

Writing the same build instructions for each systems is a bit tedious, fortunately you can use [flake-utils](https://github.com/numtide/flake-utils) to automate all of that.
{
  description = "My own hello world";

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs { inherit system; };
      in
      rec {

        packages.hello = pkgs.stdenv.mkDerivation {
          name = "hello";
          src = self;
          buildInputs = [ pkgs.gcc ];
          buildPhase = "gcc -o hello ./hello.c";
          installPhase = "mkdir -p $out/bin; install -t $out/bin hello";
        };

        defaultPackage = packages.hello;

      }
    );
}
next: devshells