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

Support multiple versions of nixpkgs in one network #665

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions nix/eval-machine-info.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,42 @@ rec {
# Get the configuration of this machine from each network
# expression, attaching _file attributes so the NixOS module
# system can give sensible error messages.

modules =
concatMap (n: optional (hasAttr machineName n)
{ imports = [(getAttr machineName n)]; inherit (n) _file; })
networks;
in
{ name = machineName;
value = import <nixpkgs/nixos/lib/eval-config.nix> {

machineConfs =
concatMap (n: optional (hasAttr machineName n)
(getAttr machineName n))
networks;

nameToPath = attrs: name: {
prefix = name;
path = attrs."${name}";
};

attrsetToPaths = attrset: map (nameToPath attrset)
(builtins.attrNames attrset);

importSources =
(concatMap (module:
if (!builtins.isFunction module
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't it be a function? Is module a "machine" definition? If yes, it usually a function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #665 (comment): we can't introspect a function in this way.

&& builtins.hasAttr "deployment" module)
&& (builtins.hasAttr "nix_path" module.deployment)
then attrsetToPaths module.deployment.nix_path
else [])
machineConfs) ++ builtins.nixPath;

__nixPath = importSources;

machineImport = builtins.scopedImport {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, scopedImport slows down evaluation because it disables the file cache in the evaluator. If that's still the case, machineImport should be something like machineImport = if __nixPath == [] then import else builtins.scopedImport ....

inherit __nixPath;
};
in {
name = machineName;
value = machineImport <nixpkgs/nixos/lib/eval-config.nix> {
modules =
modules ++
defaults ++
Expand Down
7 changes: 7 additions & 0 deletions nix/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ in
'';
};

deployment.nix_path = mkOption {
default = {};
type = types.attrsOf types.str;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe path is more adequate?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be nixPath. (NixOS already has a nix.nixPath option.)

Arguably the type should be types.listOf types.str, like nix.nixPath. Nix search path entries are not required to have a prefix.

description = ''
'';
};

deployment.hasFastConnection = mkOption {
default = false;
type = types.bool;
Expand Down