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

imp: provide per channel modules paths to make it easy to "backport" #42

Merged
merged 2 commits into from
Apr 25, 2021
Merged
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
8 changes: 6 additions & 2 deletions examples/fully-featured/configurations/Morty.host.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{ ... }: {
# auto-special args <channelName>ModulesPath for easy backporting of modules
{ unstableModulesPath, ... }: {

imports = [ "${unstableModulesPath}/installer/cd-dvd/installation-cd-minimal-new-kernel.nix" ];
disabledModules = [ "installer/cd-dvd/installation-cd-minimal-new-kernel.nix" ];

boot.loader.grub.devices = [ "nodev" ];
fileSystems."/" = { device = "test"; fsType = "ext4"; };
}
22 changes: 16 additions & 6 deletions systemFlake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

let
inherit (flake-utils-plus.lib) eachSystem patchChannel;
inherit (builtins) foldl' mapAttrs removeAttrs attrValues isAttrs isList;
inherit (builtins) foldl' mapAttrs removeAttrs attrValues attrNames isAttrs isList;

# set defaults and validate host arguments
evalHostArgs =
Expand All @@ -42,7 +42,9 @@ let
, extraArgs ? { }
# These are not part of the module system, so they can be used in `imports` lines without infinite recursion
, specialArgs ? { }
}: { inherit channelName system output builder modules extraArgs specialArgs; };
}: {
inherit channelName system output builder modules extraArgs specialArgs;
};

# recursively merge attribute sets and lists up to a certain depth
mergeAny = lhs: rhs:
Expand Down Expand Up @@ -91,8 +93,16 @@ let
lib = selectedNixpkgs.lib;
# Use nixos modules from patched nixpkgs
baseModules = import (patchedChannel + "/nixos/modules/module-list.nix");
# Override `modulesPath` because otherwise imports from there will not use patched nixpkgs
specialArgs = { modulesPath = builtins.toString (patchedChannel + "/nixos/modules"); } // host.specialArgs;
specialArgs =
let
f = channelName:
{ "${channelName}ModulesPath" = builtins.toString (channels.${channelName}.input + "/nixos/modules"); };
in
# Add `<channelName>ModulesPath`s
(foldl' (lhs: rhs: lhs // rhs) { } (map f (attrNames channels)))
# Override `modulesPath` because otherwise imports from there will not use patched nixpkgs
// { modulesPath = builtins.toString (patchedChannel + "/nixos/modules"); }
// host.specialArgs;
# The only way to find out if a host has `nixpkgs.config` set to
# the non-default value is by evalling most of the config.
hostConfig = (lib.evalModules {
Expand Down Expand Up @@ -149,9 +159,9 @@ let
];
})
] ++ host.modules;
specialArgs = host.specialArgs;
inherit specialArgs;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this was in failure mode before. we have to remain careful about the builder generalization.

Copy link
Collaborator

Choose a reason for hiding this comment

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

There was actually a reason for this: setting modulesPath on a non-nixos builder to a nixos path would break things.
I'll address this in #44

Copy link
Collaborator Author

@blaggacao blaggacao Apr 25, 2021

Choose a reason for hiding this comment

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

Ok thanks! We have to be really careful about rhose kind of things. There are now +- 5 design dimenstion in 3 lines of code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe we'd need to split them eventually apart completely and implement a generic builder and a specific nixos one on top.

} // (optionalAttrs (host.output == "nixosConfigurations") {
inherit lib baseModules specialArgs;
inherit lib baseModules;
}));
}
);
Expand Down