{ inputs = { # we of course want nixpkgs to provide stdenv, dependency packages, and # various nix functions nixpkgs.url = "github:nixos/nixpkgs?ref=release-21.05"; # we need the overlay at cargo2nix/overlay cargo2nix.url = "github:cargo2nix/cargo2nix/master"; # we will need a rust toolchain at least to build our project rust-overlay.url = "github:oxalica/rust-overlay"; rust-overlay.inputs.nixpkgs.follows = "nixpkgs"; rust-overlay.inputs.flake-utils.follows = "flake-utils"; # convenience functions for writing flakes flake-utils.url = "github:numtide/flake-utils"; }; # outputs is a function that unsurprisingly consumes the inputs outputs = { self, nixpkgs, cargo2nix, flake-utils, rust-overlay, ... }: # Build the output set for each default system and map system sets into # attributes, resulting in paths such as: # nix build .#packages.x86_64-linux. flake-utils.lib.eachDefaultSystem (system: # let-in expressions, very similar to Rust's let bindings. These names # are used to express the output but not themselves paths in the output. let # create nixpkgs that contains rustBuilder from cargo2nix overlay pkgs = import nixpkgs { inherit system; overlays = [(import "${cargo2nix}/overlay") rust-overlay.overlay]; }; # create the workspace & dependencies package set rustPkgs = pkgs.rustBuilder.makePackageSet' { rustChannel = "1.56.1"; packageFun = import ./Cargo.nix; }; in rec { # this is the output (recursive) set (expressed for each system) # the packages in `nix build .#packages..` packages = { # nix build .#hello-world # nix build .#packages.x86_64-linux.hello-world gorn = (rustPkgs.workspace.gorn {}).bin; }; # nix build defaultPackage = packages.gorn; } ); }