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

embed info in channels and pass host's channel as specialArg #44

Merged
merged 2 commits into from
Apr 26, 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
1 change: 0 additions & 1 deletion examples/fully-featured/configurations/Rick.host.nix

This file was deleted.

4 changes: 4 additions & 0 deletions examples/fully-featured/configurations/Rick.host.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
boot.loader.grub.devices = [ "nodev" ];
fileSystems."/" = { device = "test"; fsType = "ext4"; };
}
18 changes: 11 additions & 7 deletions systemFlake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -89,28 +89,31 @@ let
selectedNixpkgs = getNixpkgs host;
host = evalHostArgs (mergeAny hostDefaults host');
patchedChannel = selectedNixpkgs.path;

specialArgs = host.specialArgs // { channel = selectedNixpkgs; };

/* nixos specific arguments */
# Use lib from patched nixpkgs
lib = selectedNixpkgs.lib;
# Use nixos modules from patched nixpkgs
baseModules = import (patchedChannel + "/nixos/modules/module-list.nix");
specialArgs =
nixosSpecialArgs =
let
f = channelName:
{ "${channelName}ModulesPath" = builtins.toString (channels.${channelName}.input + "/nixos/modules"); };
{ "${channelName}ModulesPath" = 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;
// { modulesPath = toString (patchedChannel + "/nixos/modules"); };
# 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 {
prefix = [ ];
check = false;
modules = baseModules ++ host.modules;
args = { inherit inputs; } // host.extraArgs;
inherit specialArgs;
specialArgs = nixosSpecialArgs // specialArgs;
}).config;
in
{
Expand Down Expand Up @@ -162,6 +165,7 @@ let
inherit specialArgs;
} // (optionalAttrs (host.output == "nixosConfigurations") {
inherit lib baseModules;
specialArgs = nixosSpecialArgs // specialArgs;
}));
}
);
Expand All @@ -172,11 +176,11 @@ mergeAny otherArguments (
eachSystem supportedSystems
(system:
let
importChannel = name: value: import (patchChannel system value.input (value.patches or [ ])) {
importChannel = name: value: (import (patchChannel system value.input (value.patches or [ ])) {
inherit system;
overlays = sharedOverlays ++ (if (value ? overlaysBuilder) then (value.overlaysBuilder pkgs) else [ ]);
config = channelsConfig // (value.config or { });
};
}) // { inherit name; inherit (value) input; };

pkgs = mapAttrs importChannel channels;

Expand Down