{ # Makes outputs available on multiple platforms using a hand-rolled # `forAllSystems` helper (no extra dependencies). # Compare with the `flake-utils` approach described in notes/005-multi-system.md. description = "Multi-system outputs with forAllSystems"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; }; outputs = { self, nixpkgs, ... }: let # List every system you want to support. supportedSystems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ]; # Helper: apply a function to each system and collect results into an attrset. # `nixpkgs.lib.genAttrs` turns a list of keys + a function into { key = f key; … }. forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f (import nixpkgs { inherit system; }) ); in { # Every output that varies per system goes through `forAllSystems`. packages = forAllSystems (pkgs: { default = pkgs.writeShellScriptBin "hello-multi" '' echo "hello from $(uname -s)/$(uname -m)" ''; }); devShells = forAllSystems (pkgs: { default = pkgs.mkShell { packages = with pkgs; [ jq ripgrep ]; shellHook = '' echo "dev shell on $(uname -s)/$(uname -m)" ''; }; }); # `nix flake check` evaluates everything under `checks`. # Wrapping a simple test here shows the pattern. checks = forAllSystems (pkgs: { runs = pkgs.runCommand "hello-multi-runs" {} '' ${self.packages.${pkgs.system}.default}/bin/hello-multi > $out ''; }); }; }