diff --git a/src/importers.nix b/src/importers.nix index 6ef2021..ab44553 100644 --- a/src/importers.nix +++ b/src/importers.nix @@ -100,8 +100,7 @@ in '' mkProfileAttrs; - # DEPRECATED, profiles in suites are type-checked in evalArgs - # both versions of `profileMap` are no longer necessary + # DEPRECATED, both versions of `profileMap` are no longer necessary # paths are type-checked for suites in evalArgs # and `.default` isn't special with `rakeLeaves` /** profileMap = list: map diff --git a/src/mkFlake/default.nix b/src/mkFlake/default.nix index 6775372..03dc213 100644 --- a/src/mkFlake/default.nix +++ b/src/mkFlake/default.nix @@ -16,7 +16,7 @@ let defaultModules = with lib.modules; [ (hmDefaults { - inherit (cfg.home) suites; + specialArgs = cfg.home.importables; modules = cfg.home.modules ++ cfg.home.externalModules; }) (globalDefaults { @@ -63,7 +63,7 @@ lib.systemFlake (lib.mergeAny }) ]; hostDefaults = lib.mergeAny hostDefaults { - specialArgs.suites = cfg.nixos.suites; + specialArgs = cfg.nixos.importables; modules = cfg.nixos.hostDefaults.externalModules ++ defaultModules; builder = args: args.specialArgs.channel.input.lib.nixosSystem (lib.mergeAny args { # So modules and functions can create their own version of the build diff --git a/src/mkFlake/evalArgs.nix b/src/mkFlake/evalArgs.nix index db89fc8..a2970a3 100644 --- a/src/mkFlake/evalArgs.nix +++ b/src/mkFlake/evalArgs.nix @@ -168,29 +168,62 @@ let }; }; - # profiles and suites - which are profile collections - profilesModule = { config, ... }: { + suitesDeprecationMessage = '' + WARNING: The 'suites' and `profiles` options have been deprecated, you can now create + both with the importables option. `rakeLeaves` can be used to create profiles and + by passing a module or `rec` set to `importables`, suites can access profiles. + Example: + ``` + importables = rec { + profiles = digga.lib.importers.rakeLeaves ./profiles; + suites = with profiles; { }; + } + ``` + See https://github.com/divnix/digga/pull/30 for more details + ''; + importablesModule = { config, options, ... }: { + config = { + importables = mkIf options.suites.isDefined { + suites = builtins.trace suitesDeprecationMessage config.suites; + }; + }; options = with types; { profiles = mkOption { type = listOf path; default = [ ]; - description = '' - profile folders that can be collected into suites - the name of the argument passed to suites is based - on the folder name. - [ ./profiles ] => { profiles }: - ''; + description = suitesDeprecationMessage; }; suites = mkOption { type = pathTo (functionTo attrs); - default = _: { }; apply = suites: lib.mkSuites { inherit suites; inherit (config) profiles; }; + description = suitesDeprecationMessage; + }; + importables = mkOption { + type = submoduleWith { + modules = [{ + freeformType = attrs; + options = { + suites = mkOption { + type = attrsOf (listOf path); + # add `allProfiles` to it here + apply = suites: suites // { + allProfiles = lib.foldl + (lhs: rhs: lhs ++ rhs) [ ] + (builtins.attrValues suites); + }; + description = '' + collections of profiles + ''; + }; + }; + }]; + }; + default = { }; description = '' - Function that takes profiles and returns suites for this config system - These can be accessed through the 'suites' special argument. + Packages of paths to be passed to modules as `specialArgs`. ''; }; }; @@ -248,7 +281,7 @@ let nixos = mkOption { type = submoduleWith { # allows easy use of the `imports` key - modules = [ (includeHostsModule "nixos") profilesModule ]; + modules = [ (includeHostsModule "nixos") importablesModule ]; }; default = { }; description = '' @@ -259,7 +292,7 @@ let type = submoduleWith { # allows easy use of the `imports` key modules = [ - profilesModule + importablesModule (exportModulesModule "home") externalModulesModule ]; diff --git a/src/modules.nix b/src/modules.nix index 20c6c86..7580075 100644 --- a/src/modules.nix +++ b/src/modules.nix @@ -1,13 +1,13 @@ { lib }: { - hmDefaults = { suites, modules }: + hmDefaults = { specialArgs, modules }: { options, ... }: { config = lib.optionalAttrs (options ? home-manager) { home-manager = { useGlobalPkgs = true; useUserPackages = true; - extraSpecialArgs = { inherit suites; }; + extraSpecialArgs = specialArgs; sharedModules = modules; }; }; diff --git a/tests/fullFlake/default.nix b/tests/fullFlake/default.nix index d66556b..0ec84ba 100644 --- a/tests/fullFlake/default.nix +++ b/tests/fullFlake/default.nix @@ -52,18 +52,24 @@ let /* set host specific properties here */ NixOS = { }; }; - profiles = [ ./profiles ./users ]; - suites = { profiles, users, ... }: with profiles; { - base = [ cachix core users.nixos users.root ]; + importables = rec { + profiles = lib.importers.rakeLeaves ./profiles // { + users = lib.importers.rakeLeaves ./users; + }; + suites = with profiles; { + base = [ cachix core users.nixos users.root ]; + }; }; }; home = { modules = ./users/modules/module-list.nix; externalModules = [ ]; - profiles = [ ./users/profiles ]; - suites = { profiles, ... }: with profiles; { - base = [ direnv git ]; + importables = rec { + profiles = lib.importers.rakeLeaves ./profiles; + suites = with profiles; { + base = [ direnv git ]; + }; }; };