-
-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inputs
in nixosModule
is not available for external flake
#22
Comments
Sorry for delay; have been busy. The If you want to use packages from another flake, I'd recommend having the module use the package from the pkgs arg, and having the second flake's system use the first's overlay. |
@accelbread Should the |
To better illustrate the problem, I updated https://github.com/ratson/bug-report/blob/flakelight-nixos-module/flake1/flake.nix#L13-L19 nixosConfigurations.vm2 = nixpkgs.lib.nixosSystem {
inherit system;
modules = [
self.nixosModules.default
];
}; It is strange that Here is the https://github.com/ratson/bug-report/blob/flakelight-nixos-module/flake1/nix/nixos/vm1.nix { inputs, ... }:
{
system = "x86_64-linux";
modules = [
inputs.self.nixosModules.default
];
} |
if you change vm2 to not call nixosSystem explicitly, it will work: nixosConfigurations.vm2 = {
inherit system;
modules = [
self.nixosModules.default
];
}; If you don't call it, flakelight can propagate inputs and etc. to the nixos invocation since it calls it. If you call it yourself, flakelight can't add its stuff. You can call it yourself and add the flakelight stuff by adding Lines 965 to 977 in 2a96b83
|
I don't know if it can be generically implemented or not, here is a working example, |
Yeah the problem with that approach is that the parameters are no longer named, and the parameter names affect how modules are passed args. A module with In order to use host flake module args, you'd have to capture them. Something like the following works: nixosModules = { inputs, ... }: {
default = { pkgs, ... }: {
environment.systemPackages = [
inputs.self.packages.${pkgs.system}.hello1
];
};
}; That way To autoLoad that would have to use { inputs, ... }: { pkgs, ... }: {
environment.systemPackages = [
inputs.self.packages.${pkgs.system}.hello1
];
}; However, can't do the above automatically since given a function, we don't know if flakelight should call it or not. We could perhaps try calling it and seeing if result is a function, and if so it needs to be called else not. This could cause an evaluation failure though if its not meant to be called, and we passed the wrong args. Theres also no way to catch hard errors. For Edit: wrapping the function like I mentioned at the end would not work actually, as no way to extract the module named args from the function value without evaluating it, since the real module named args might not be the top level function. |
@accelbread Thanks for pointing out the I have generalized the wrapper code to be, nixosModules.wrapped =
let
f = lib.toFunction import ./nix/nixosModules/_default.nix;
g = args: f (args // { inherit inputs; });
in
lib.setFunctionArgs g (lib.functionArgs f); |
You'll also need to filter out inputs, so that if their nixpkgs modules don't have an inputs arg it would still work, like follows: nixosModules.wrapped =
let
f = lib.toFunction import ./nix/nixosModules/_default.nix;
g = args: f (args // { inherit inputs; });
in
lib.setFunctionArgs g (lib.removeAttrs (lib.functionArgs f) ["inputs"]); How I'd do modules that need moduleArgs from defining flake is set { lib, flakelight, moduleArgs, ... }:
lib.mapAttrs (_: v: v moduleArgs) (flakelight.importDir ./.) If you have that, then your module files are functions returning modules, for example { inputs, moduleArgs, ... }:
{ pkgs, config, ... }: {
environment.systemPackages = [ inputs.self.packages.${pkgs.system}.hello1 ];
} |
Right now, I am putting all modules requires nixosModules = { inputs, ... }: {
default = { pkgs, ... }: {
environment.systemPackages = [
inputs.self.packages.${pkgs.system}.hello1
];
};
}; @accelbread Do you think it is possible to utilize file extension convention, e.g. { inputs, ... }: { pkgs, ... }: {
environment.systemPackages = [
inputs.self.packages.${pkgs.system}.hello1
];
} Or provide such functionality via extra |
Yeah, a folder name could be used. A flakelight module could add a |
gives
While the following is working,
Source code in https://github.com/ratson/bug-report/tree/flakelight-nixos-module
@accelbread Would you check if usage in
flake2/flake.nix
is correct?FYR, here is a copy of it,
There is
test.sh
script in the repo to run locally to verify the bug.The text was updated successfully, but these errors were encountered: