From b1b17434146d1d54ce4ccfa3f080f313888bdf56 Mon Sep 17 00:00:00 2001 From: _cry64 Date: Sat, 14 Mar 2026 21:01:02 +1000 Subject: [PATCH] warn if reserved inputs provided --- nix/snow/flake/default.nix | 54 ++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/nix/snow/flake/default.nix b/nix/snow/flake/default.nix index fad3c6d..b90126b 100644 --- a/nix/snow/flake/default.nix +++ b/nix/snow/flake/default.nix @@ -4,23 +4,55 @@ systems, ... }: let + inherit + (builtins) + attrNames + concatStringsSep + filter + length + removeAttrs + warn + ; + inherit (inputs.nixpkgs) lib; in { # snow.flake flake = flakeInputs: root: let snowflake = lib.evalModules { class = "snowflake"; - # XXX: TODO: abort if inputs contains reserved names - specialArgs = - (flakeInputs - // { - inherit (this) snow; - inherit systems root; - inputs = flakeInputs; - }) - # XXX: TODO: - # |> (x: builtins.removeAttrs x ["self" "nodes"]); - |> (x: builtins.removeAttrs x ["self"]); + specialArgs = let + reservedInputs = { + inherit (this) snow; + inherit systems root; + inputs = flakeInputs; + }; + + warnIfReserved = let + getReservedNames = names: + reservedInputs + |> attrNames + |> filter (name: names?${name}); + + reservedNames = + flakeInputs + |> attrNames + |> getReservedNames; + in + (length reservedNames == 0) + || warn '' + [snow] Your `flake.nix` declares inputs using reserved names! + [snow] These will be accessible only via `inputs.''${NAME}` + [snow] Please rename the following: + [snow] ${concatStringsSep reservedNames ", "} + '' + true; + in + assert warnIfReserved; + flakeInputs + // reservedInputs + # XXX: TODO: + # |> (x: builtins.removeAttrs x ["self" "nodes"]); + |> (x: removeAttrs x ["self"]); modules = [ ./module.nix