Skip to content

Commit

Permalink
imp: provide per channel modules paths to make it easy to "backport"
Browse files Browse the repository at this point in the history
a module. imports = [ ${myChannelModulesPathk}/installer/...

Signed-off-by: David Arnold <dar@xoe.solutions>
  • Loading branch information
David Arnold committed Apr 25, 2021
1 parent e7ae270 commit 7003170
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
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"; };
}
17 changes: 13 additions & 4 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,15 @@ 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

0 comments on commit 7003170

Please sign in to comment.