From: Scott Worley Date: Mon, 23 Aug 2021 19:51:27 +0000 (-0700) Subject: Make --arg work X-Git-Url: http://git.scottworley.com/warn-nixpkgs/commitdiff_plain/787cc66cd15159ab80b3a1b7644aa86cd3467bff Make --arg work --- diff --git a/default.nix b/default.nix index 95c7a7e..15034d1 100644 --- a/default.nix +++ b/default.nix @@ -1,4 +1,33 @@ -args@{ ... }: -let actualNixpkgs = import args; -in actualNixpkgs.lib.warn -("Using legacy channel nixpkgs from " + ) actualNixpkgs +let + # We declare some parameters explicitly because nix's --arg command line + # flag requires this. Getting the list of parameters & constructing this + # function dynamically would require import-from-derivation, which is not + # permitted in some evaluation contexts, so we can't do that. Instead, we + # duplicate nixpkgs' list of explicit parameters here, with a check in case + # it drifts out of sync. + unused = builtins.throw "These default values are not used"; + toplevel = args@{ localSystem ? unused, system ? unused, platform ? unused + , crossSystem ? unused, config ? unused, overlays ? unused + , crossOverlays ? unused, ... }: + let + + actualNixpkgs = import args; + noisyNixpkgs = actualNixpkgs.lib.warn + ("Using legacy channel nixpkgs from " + ) actualNixpkgs; + + local-parameters = builtins.attrNames (builtins.functionArgs toplevel); + remote-parameters = + builtins.attrNames (builtins.functionArgs (import )); + missing-parameters = + actualNixpkgs.lib.subtractLists local-parameters remote-parameters; + # Don't warn about extra parameters to avoid spurious warnings as everyone + # rolls past nixpkgs commit 2dde58903e0f2f490088c3b0cedadc9b479da085 + # which removed the platform parameter. + # extra-parameters = + # actualNixpkgs.lib.subtractLists remote-parameters local-parameters; + in actualNixpkgs.lib.traceIf (missing-parameters != [ ]) + ("Note: warn-nixpkgs doesn't know about these nixpkgs parameters, warned" + + "so they might not work with --arg on the nix command line: " + + actualNixpkgs.lib.concatStringsSep " " missing-parameters) noisyNixpkgs; + +in toplevel