Is it possible to create a function f
that accepts two functions g
and h
and returns a function with the arguments of g
and h
?
E.g: g = { x }: {}
, h = { y }: {}
and f = { g, h }: ??: {}
such that builtins.functionArgs f = { x = false; y = false; }
.
Background
This might be an xy-problem so here’s the background to the question:
I’m getting into writing tests for my nixos modules. I also want to run these tests for multiple nixpkgs revisions. To reduce code duplication I am trying to create a helper function that generates a test for every specified nixpkgs from a single test definition but that also allows changing parts of the definition for some revisions.
For example (reduced to the essential parts):
{
inputs = {
nixpkgs-21-11.url = github:NixOS/nixpkgs/nixos-21.11;
nixpkgs-22-05.url = github:NixOS/nixpkgs/nixos-22.05;
};
outputs = { self, nixpkgs-21-11, nixpkgs-22-05 }: {
nixosModules =
{
my-module = foobar;
};
checks = testForAllNixpkgs {
system = "x86_64-linux";
# generate tests for these nixpkgs
nixpkgs = { inherit nixpkgs-21-11 nixpkgs-22-05; };
# arguments for makeTest (nixos/lib/testing-python.nix)
test = {
machine = { ... }: {
imports = [ self.nixosModules.my-module ];
my-module.enable = true;
};
testScript = ''
machine.wait_for_unit("default.target")
machine.succeed("true")
'';
};
# let's say 21.11 requires some additional configuration
specialisations = {
nixpkgs-21-11.machine = { pkgs, ... }: {
nix.package = pkgs.nixUnstable;
};
};
};
};
}
testForAllNixpkgs
is (reduced):
with builtins;
{ system, nixpkgs ? { }, test ? { }, specialisations ? { } }:
builtins.mapAttrs
(nixpkgs-name: nixpkgs:
let
machine = inputs:
lib.recursiveUpdate
(test.machine inputs)
(specialisations.${nixpkgs-name}.machine inputs);
in
with import (nixpkgs + "/nixos/lib/testing-python.nix") { inherit system; };
makeTest (test // { inherit machine; })
)
nixpkg
which returns an attribute set nixpkgs-name -> test
and it works when called manually with the required arguments for test.machine
and specialisations.nixpkgs-21-11.machine
but because
builtins.functionArgs (testForAllNixpkgs { inherit system nixpkgs test speciallisations; }) = {}
it fails with called without required argument 'pkgs'
when invoked through nix flake check
.
I might also have gone too far in one direction to see another solution or that I’m reinventing a wheel.
Any help or a different approach to testing multiple nixpkgs revisions is appreciated.