A Multi-Arch Flake Template that Stays Boring
A Multi-Arch Flake Template that Stays Boring
Thesis
A flake that only works on x86_64-linux surprises Darwin CI. List systems, loop with genAttrs, keep packages and shells inside. Not evaluated here (nix missing).
Mental model
forEach system → packages.${system} / devShells.${system}
Worked examples
{
description = "boring multi-arch template";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
outputs = { self, nixpkgs }:
let
systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ];
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f {
pkgs = import nixpkgs { inherit system; };
});
in {
packages = forAllSystems ({ pkgs }: { default = pkgs.hello; });
devShells = forAllSystems ({ pkgs }: {
default = pkgs.mkShell { packages = [ pkgs.hello ]; };
});
};
}Re-verify current nixpkgs pins when you use this.
Trap
Hard-coding system = "x86_64-linux" at the top level.
Boring rule
Enumerate systems once; put every package and shell inside the loop.
Try this
- Add formatter/checks per system.
- Compare
nix flake inittemplates. - Grow into flake-parts
perSystemif needed.
Sources
- Nix flakes manual