Skip to content
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

Fix #7272 - Allow users to override importsArgs in eval-config.nix. #8932

Closed
wants to merge 1 commit into from

Conversation

nbp
Copy link
Member

@nbp nbp commented Jul 21, 2015

These changes renames the lib.evalModules argument attribute from specialArgs into importsArgs, to represent the actual use of this argument. Also, this change modify nixos lib/eval-config.nix to expose this argument and to use it to override the default set of arguments defined in this file.

This would solve the issue #7272, by renaming extraArgs into importsArgs. The difference between the 2 arguments is that extraArgs is now evaluated as _module.args, and importsArgs is for arguments which are used for the resolution of imports attributes value.

cc @edolstra , @shlevy

@wizeman
Copy link
Member

wizeman commented Aug 2, 2015

Could you tell me how this fixes #7272?

I've tried applying your commit and then evaluating the following configuration:

{ config, pkgs, lib, hydra_path, ... }:

{
  _module.importsArgs.hydra_path = lib.mkDefault "/root/src/localrepos/hydra";

  imports = [
    "${hydra_path}/hydra-module.nix"
  ];
}

... but this fails with:

error: while evaluating the attribute ‘config.system.build.toplevel’ at /nixdev/nixpkgs/nixos/lib/eval-config.nix:54:5:
while evaluating the attribute ‘config’ at /nixdev/nixpkgs/lib/modules.nix:86:25:
while evaluating ‘yieldConfig’ at /nixdev/nixpkgs/lib/modules.nix:73:29, called from /nixdev/nixpkgs/lib/modules.nix:72:16:
while evaluating ‘mergeModules’ at /nixdev/nixpkgs/lib/modules.nix:164:26, called from /nixdev/nixpkgs/lib/modules.nix:63:17:
while evaluating ‘mergeModules'’ at /nixdev/nixpkgs/lib/modules.nix:168:36, called from /nixdev/nixpkgs/lib/modules.nix:165:5:
while evaluating ‘concatMap’ at /nixdev/nixpkgs/lib/lists.nix:54:18, called from /nixdev/nixpkgs/lib/modules.nix:204:9:
while evaluating ‘fold’ at /nixdev/nixpkgs/lib/lists.nix:20:19, called from /nixdev/nixpkgs/lib/modules.nix:63:38:
while evaluating ‘fold'’ at /nixdev/nixpkgs/lib/lists.nix:23:15, called from /nixdev/nixpkgs/lib/lists.nix:27:8:
while evaluating ‘closeModules’ at /nixdev/nixpkgs/lib/modules.nix:90:27, called from /nixdev/nixpkgs/lib/modules.nix:58:16:
while evaluating anonymous function at /nixdev/nixpkgs/lib/modules.nix:92:49, called from /nixdev/nixpkgs/lib/lists.nix:49:19:
infinite recursion encountered

When trying the old way:

{ config, pkgs, lib
, hydra_path ? "/root/src/localrepos/hydra"
, ... }:

{
  imports = [
    "${hydra_path}/hydra-module.nix"
  ];
}

... it also fails with infinite recursion.

What am I doing wrong?

@nbp
Copy link
Member Author

nbp commented Aug 2, 2015

@wizeman,

Basically, this would work the same way as you described in #7272 (comment) , except that instead of having an argument named extraArgs it would be named importsArgs, in your release.nix file:

 1 {
 2   wizynet
 3 , hydra_path
 4 , rg_path
 5 , wizytests_path
 6 , kodiOffPath
 7 , nixpkgs
 8 }:
 9 
10 let
11 
12   pkgs = import nixpkgs { };
13 
14   eval = modules: (import <nixpkgs/nixos/lib/eval-config.nix> {
15     inherit modules;
16     importsArgs = {
17       inherit hydra_path rg_path wizytests_path kodiOffPath;
18     };
19   });

Also, I recall @edolstra mentioning that hydra updates NIX_PATH environment variable with the path of the project inputs, such that you should be able to use <hydra_path> in your import statements. If this alternative works for you, this would avoid landing the current fix.

@wizeman
Copy link
Member

wizeman commented Aug 2, 2015

Right, I understand how the release.nix file would look like (the file evaluated by Hydra which overrides the default values), but how would the individual config-*.nix files declare and use arguments with default values?

The point of having the default values was so that I could directly evaluate (e.g.) config-wizylap.nix locally using nixos-rebuild switch or nixops deploywithout having to manually specify those values.

@domenkozar
Copy link
Member

@nbp what's the status of this?

@nbp
Copy link
Member Author

nbp commented Nov 16, 2015

@wizeman ,
Right, this only solve a problem which is that we can set default values from out-side NixOS, so the current patch does not solve the issue, and I originaly thought that the issue was related to the modulePaths, which as it got reverted made me accidentally thought that this was fixed, but this is not.

I suggested an alternative in #7272 (comment) which I think might work for your use case, if you were to separate the module arguments from the paths arguments.

@domenkozar Thanks for pinging.

@nbp
Copy link
Member Author

nbp commented Nov 18, 2015

Note, #11106 should solve this problem without the need of adding extra arguments to modules, by importing the configuration with nixos.extraModules option. The idea then would be that you define the paths as options in one special module that you include everywhere, and then do the following:

{ config, lib, ... }:

with lib;
{
  options = {
    customImports.hydra_path = mkOption { default = "/root/src/localrepos/hydra"; };
    …
  };

  config = {
    nixos.path = <nixos>;
    nixos.extraModules = with config.customImports; [ hydra_path rg_path wizytests_path kodiOffPath ];
  };
}

This module will basically re-evaluate NixOS with the additional extra modules as-if they were dynamic-imports.

@nbp nbp added this to the 16.03 milestone Nov 20, 2015
@nbp
Copy link
Member Author

nbp commented Nov 20, 2015

Closing as this issue is solved by #11106.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants