From 3f197dc7591cc6edc83e1eb44698283c19fd28a2 Mon Sep 17 00:00:00 2001 From: Jonas Chevalier Date: Thu, 20 Jan 2022 18:42:55 +0100 Subject: [PATCH] add system map for convenience (#55) --- README.md | 14 +++++++++++--- default.nix | 9 +++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ccacc3d..a1b43f6 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,14 @@ flakes. ## Usage +### `system -> ( -> )` + +A map from system to system built from `allSystems`. It's mainly useful to +detect typos and auto-complete if you use +[rnix-lsp](https://github.com/nix-community/rnix-lsp). + +Eg: instead of typing `"x86_64-linux"`, use `system.x86_64-linux` + ### `allSystems -> []` A list of all systems defined in nixpkgs. For a smaller list see `defaultSystems` @@ -22,7 +30,7 @@ The list of systems supported by nixpkgs and built by hydra. Useful if you want add additional platforms: ```nix -eachSystem (defaultSystems ++ ["armv7l-linux"]) (system: { hello = 42; }) +eachSystem (defaultSystems ++ [system.armv7l-linux]) (system: { hello = 42; }) ``` ### `eachSystem -> [] -> ( -> attrs)` @@ -34,7 +42,7 @@ then re-build the hierarchy. Eg: ```nix -eachSystem ["x86_64-linux"] (system: { hello = 42; }) +eachSystem [ system.x86_64-linux ] (system: { hello = 42; }) # => { hello = { x86_64-linux = 42; }; } eachSystem allSystems (system: { hello = 42; }) # => { @@ -132,7 +140,7 @@ Input: , # maps to the devShell output. Pass in a shell.nix file or function. shell ? null , # pass the list of supported systems - systems ? [ "x86_64-linux" ] + systems ? [ system.x86_64-linux ] }: null ``` diff --git a/default.nix b/default.nix index 57dd73c..4963107 100644 --- a/default.nix +++ b/default.nix @@ -57,6 +57,14 @@ let "x86_64-genode" ]; + # A map from system to system. It's useful to detect typos. + # + # Instead of typing `"x86_64-linux"`, type `flake-utils.lib.system.x86_64-linux` + # and get an error back if you used a dash instead of an underscore. + system = + builtins.listToAttrs + (map (system: { name = system; value = system; }) allSystems); + # eachSystem using defaultSystems eachDefaultSystem = eachSystem defaultSystems; @@ -183,6 +191,7 @@ let flattenTree mkApp simpleFlake + system ; }; in