1
1
mirror of https://github.com/divnix/digga.git synced 2024-12-24 00:21:47 +03:00

Replace profiles/suites with general importables

profiles and suites is created with the old mkProfileAttrs, this makes
the new auto-importing strategies backwards compatible. But warnings are
printed when using profiles and suites instructing you on how to switch
your profiles folder format and add suites to importables
This commit is contained in:
Pacman99 2021-05-26 08:30:39 -07:00 committed by Parthiv Seetharaman
parent 271cfd0c18
commit e838f60e29
5 changed files with 63 additions and 25 deletions

View File

@ -100,8 +100,7 @@ in
'' ''
mkProfileAttrs; mkProfileAttrs;
# DEPRECATED, profiles in suites are type-checked in evalArgs # DEPRECATED, both versions of `profileMap` are no longer necessary
# both versions of `profileMap` are no longer necessary
# paths are type-checked for suites in evalArgs # paths are type-checked for suites in evalArgs
# and `.default` isn't special with `rakeLeaves` # and `.default` isn't special with `rakeLeaves`
/** profileMap = list: map /** profileMap = list: map

View File

@ -16,7 +16,7 @@ let
defaultModules = with lib.modules; [ defaultModules = with lib.modules; [
(hmDefaults { (hmDefaults {
inherit (cfg.home) suites; specialArgs = cfg.home.importables;
modules = cfg.home.modules ++ cfg.home.externalModules; modules = cfg.home.modules ++ cfg.home.externalModules;
}) })
(globalDefaults { (globalDefaults {
@ -63,7 +63,7 @@ lib.systemFlake (lib.mergeAny
}) })
]; ];
hostDefaults = lib.mergeAny hostDefaults { hostDefaults = lib.mergeAny hostDefaults {
specialArgs.suites = cfg.nixos.suites; specialArgs = cfg.nixos.importables;
modules = cfg.nixos.hostDefaults.externalModules ++ defaultModules; modules = cfg.nixos.hostDefaults.externalModules ++ defaultModules;
builder = args: args.specialArgs.channel.input.lib.nixosSystem (lib.mergeAny args { builder = args: args.specialArgs.channel.input.lib.nixosSystem (lib.mergeAny args {
# So modules and functions can create their own version of the build # So modules and functions can create their own version of the build

View File

@ -168,29 +168,62 @@ let
}; };
}; };
# profiles and suites - which are profile collections suitesDeprecationMessage = ''
profilesModule = { config, ... }: { 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; { options = with types; {
profiles = mkOption { profiles = mkOption {
type = listOf path; type = listOf path;
default = [ ]; default = [ ];
description = '' description = suitesDeprecationMessage;
profile folders that can be collected into suites
the name of the argument passed to suites is based
on the folder name.
[ ./profiles ] => { profiles }:
'';
}; };
suites = mkOption { suites = mkOption {
type = pathTo (functionTo attrs); type = pathTo (functionTo attrs);
default = _: { };
apply = suites: lib.mkSuites { apply = suites: lib.mkSuites {
inherit suites; inherit suites;
inherit (config) profiles; 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 = '' description = ''
Function that takes profiles and returns suites for this config system Packages of paths to be passed to modules as `specialArgs`.
These can be accessed through the 'suites' special argument.
''; '';
}; };
}; };
@ -248,7 +281,7 @@ let
nixos = mkOption { nixos = mkOption {
type = submoduleWith { type = submoduleWith {
# allows easy use of the `imports` key # allows easy use of the `imports` key
modules = [ (includeHostsModule "nixos") profilesModule ]; modules = [ (includeHostsModule "nixos") importablesModule ];
}; };
default = { }; default = { };
description = '' description = ''
@ -259,7 +292,7 @@ let
type = submoduleWith { type = submoduleWith {
# allows easy use of the `imports` key # allows easy use of the `imports` key
modules = [ modules = [
profilesModule importablesModule
(exportModulesModule "home") (exportModulesModule "home")
externalModulesModule externalModulesModule
]; ];

View File

@ -1,13 +1,13 @@
{ lib }: { lib }:
{ {
hmDefaults = { suites, modules }: hmDefaults = { specialArgs, modules }:
{ options, ... }: { { options, ... }: {
config = lib.optionalAttrs (options ? home-manager) { config = lib.optionalAttrs (options ? home-manager) {
home-manager = { home-manager = {
useGlobalPkgs = true; useGlobalPkgs = true;
useUserPackages = true; useUserPackages = true;
extraSpecialArgs = { inherit suites; }; extraSpecialArgs = specialArgs;
sharedModules = modules; sharedModules = modules;
}; };
}; };

View File

@ -52,18 +52,24 @@ let
/* set host specific properties here */ /* set host specific properties here */
NixOS = { }; NixOS = { };
}; };
profiles = [ ./profiles ./users ]; importables = rec {
suites = { profiles, users, ... }: with profiles; { profiles = lib.importers.rakeLeaves ./profiles // {
base = [ cachix core users.nixos users.root ]; users = lib.importers.rakeLeaves ./users;
};
suites = with profiles; {
base = [ cachix core users.nixos users.root ];
};
}; };
}; };
home = { home = {
modules = ./users/modules/module-list.nix; modules = ./users/modules/module-list.nix;
externalModules = [ ]; externalModules = [ ];
profiles = [ ./users/profiles ]; importables = rec {
suites = { profiles, ... }: with profiles; { profiles = lib.importers.rakeLeaves ./profiles;
base = [ direnv git ]; suites = with profiles; {
base = [ direnv git ];
};
}; };
}; };