1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-12-03 07:31:03 +01:00

treewide: assertions at top of config

Moving assertions to be consistently at top of the config blocks.

Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
Austin Horstman 2025-11-22 14:50:05 -06:00
parent 0b44044694
commit 9a5042a88c
9 changed files with 92 additions and 92 deletions

View file

@ -127,19 +127,6 @@ in
portalsDir = "${config.home.profileDirectory}/share/xdg-desktop-portal/portals"; portalsDir = "${config.home.profileDirectory}/share/xdg-desktop-portal/portals";
in in
mkIf cfg.enable { mkIf cfg.enable {
warnings = optional (cfg.configPackages == [ ] && cfg.config == { }) ''
xdg-desktop-portal 1.17 reworked how portal implementations are loaded, you
should either set `xdg.portal.config` or `xdg.portal.configPackages`
to specify which portal backend to use for the requested interface.
https://github.com/flatpak/xdg-desktop-portal/blob/1.18.1/doc/portals.conf.rst.in
If you simply want to keep the behaviour in < 1.17, which uses the first
portal implementation found in lexicographical order, use the following:
xdg.portal.config.common.default = "*";
'';
assertions = [ assertions = [
(lib.hm.assertions.assertPlatform "xdg.portal" pkgs lib.platforms.linux) (lib.hm.assertions.assertPlatform "xdg.portal" pkgs lib.platforms.linux)
@ -168,6 +155,19 @@ in
} }
]; ];
warnings = optional (cfg.configPackages == [ ] && cfg.config == { }) ''
xdg-desktop-portal 1.17 reworked how portal implementations are loaded, you
should either set `xdg.portal.config` or `xdg.portal.configPackages`
to specify which portal backend to use for the requested interface.
https://github.com/flatpak/xdg-desktop-portal/blob/1.18.1/doc/portals.conf.rst.in
If you simply want to keep the behaviour in < 1.17, which uses the first
portal implementation found in lexicographical order, use the following:
xdg.portal.config.common.default = "*";
'';
home = { home = {
packages = packages ++ cfg.configPackages; packages = packages ++ cfg.configPackages;
sessionVariables = mkMerge [ sessionVariables = mkMerge [

View file

@ -221,22 +221,6 @@ in
in in
mkIf cfg.enable { mkIf cfg.enable {
warnings =
if genAccountsConf && (cfg.extraConfig.general.unsafe-accounts-conf or false) == false then
[
''
aerc: `programs.aerc.enable` is set, but `...extraConfig.general.unsafe-accounts-conf` is set to false or unset.
This will prevent aerc from starting; see `unsafe-accounts-conf` in the man page aerc-config(5):
> By default, the file permissions of accounts.conf must be restrictive and only allow reading by the file owner (0600).
> Set this option to true to ignore this permission check. Use this with care as it may expose your credentials.
These permissions are not possible with home-manager, since the generated file is in the nix-store (permissions 0444).
Therefore, please set `programs.aerc.extraConfig.general.unsafe-accounts-conf = true`.
This option is safe; if `passwordCommand` is properly set, no credentials will be written to the nix store.
''
]
else
[ ];
assertions = [ assertions = [
{ {
assertion = assertion =
@ -254,6 +238,22 @@ in
} }
]; ];
warnings =
if genAccountsConf && (cfg.extraConfig.general.unsafe-accounts-conf or false) == false then
[
''
aerc: `programs.aerc.enable` is set, but `...extraConfig.general.unsafe-accounts-conf` is set to false or unset.
This will prevent aerc from starting; see `unsafe-accounts-conf` in the man page aerc-config(5):
> By default, the file permissions of accounts.conf must be restrictive and only allow reading by the file owner (0600).
> Set this option to true to ignore this permission check. Use this with care as it may expose your credentials.
These permissions are not possible with home-manager, since the generated file is in the nix-store (permissions 0444).
Therefore, please set `programs.aerc.extraConfig.general.unsafe-accounts-conf = true`.
This option is safe; if `passwordCommand` is properly set, no credentials will be written to the nix store.
''
]
else
[ ];
home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; home.packages = lib.mkIf (cfg.package != null) [ cfg.package ];
home.file = { home.file = {

View file

@ -252,25 +252,6 @@ in
config = mkIf cfg.enable ( config = mkIf cfg.enable (
lib.mkMerge [ lib.mkMerge [
(mkIf (missingNotmuchAccounts != [ ]) {
warnings = [
''
lieer is enabled for the following email accounts, but notmuch is not:
${concatStringsSep "\n " missingNotmuchAccounts}
Notmuch can be enabled with:
${concatStringsSep "\n " notmuchConfigHelp}
If you have configured notmuch outside of Home Manager, you can suppress this
warning with:
programs.lieer.notmuchSetupWarning = false;
''
];
})
{ {
assertions = [ assertions = [
{ {
@ -297,6 +278,25 @@ in
home.file = lib.listToAttrs (map configFile lieerAccounts); home.file = lib.listToAttrs (map configFile lieerAccounts);
} }
(mkIf (missingNotmuchAccounts != [ ]) {
warnings = [
''
lieer is enabled for the following email accounts, but notmuch is not:
${concatStringsSep "\n " missingNotmuchAccounts}
Notmuch can be enabled with:
${concatStringsSep "\n " notmuchConfigHelp}
If you have configured notmuch outside of Home Manager, you can suppress this
warning with:
programs.lieer.notmuchSetupWarning = false;
''
];
})
] ]
); );
} }

View file

@ -484,6 +484,13 @@ in
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
assertions = [
{
assertion = ((filter (b: (lib.length (lib.toList b.map)) == 0) (cfg.binds ++ cfg.macros)) == [ ]);
message = "The 'programs.neomutt.(binds|macros).map' list must contain at least one element.";
}
];
home.packages = [ cfg.package ]; home.packages = [ cfg.package ];
home.file = home.file =
let let
@ -541,13 +548,6 @@ in
); );
}; };
assertions = [
{
assertion = ((filter (b: (lib.length (lib.toList b.map)) == 0) (cfg.binds ++ cfg.macros)) == [ ]);
message = "The 'programs.neomutt.(binds|macros).map' list must contain at least one element.";
}
];
warnings = warnings =
let let
hasOldBinds = binds: (filter (b: !(lib.isList b.map)) binds) != [ ]; hasOldBinds = binds: (filter (b: !(lib.isList b.map)) binds) != [ ];

View file

@ -55,6 +55,13 @@ in
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
assertions = [
{
assertion = cfg.package != null || cfg.enableTelevisionIntegration;
message = "Cannot enable television integration when config.programs.nix-search-tv.package is null.";
}
];
home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; home.packages = lib.mkIf (cfg.package != null) [ cfg.package ];
xdg.configFile."nix-search-tv/config.json" = lib.mkIf (cfg.settings != { }) { xdg.configFile."nix-search-tv/config.json" = lib.mkIf (cfg.settings != { }) {
@ -75,12 +82,5 @@ in
preview.command = ''${path} preview "{}"''; preview.command = ''${path} preview "{}"'';
} }
); );
assertions = [
{
assertion = cfg.package != null || cfg.enableTelevisionIntegration;
message = "Cannot enable television integration when config.programs.nix-search-tv.package is null.";
}
];
}; };
} }

View file

@ -785,13 +785,6 @@ in
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
warnings = lib.optionals (!cfg.darwinSetupWarning) [
''
Using programs.thunderbird.darwinSetupWarning is deprecated and will be
removed in the future. Thunderbird is now supported on Darwin.
''
];
assertions = [ assertions = [
( (
let let
@ -884,6 +877,13 @@ in
) )
]; ];
warnings = lib.optionals (!cfg.darwinSetupWarning) [
''
Using programs.thunderbird.darwinSetupWarning is deprecated and will be
removed in the future. Thunderbird is now supported on Darwin.
''
];
home.packages = [ home.packages = [
cfg.package cfg.package
] ]

View file

@ -219,6 +219,13 @@ in
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
assertions = [
{
assertion = cfg.extraPackages != [ ] -> cfg.package != null;
message = "{option}programs.zed-editor.extraPackages requires non null {option}programs.zed-editor.package";
}
];
home.packages = mkIf (cfg.package != null) ( home.packages = mkIf (cfg.package != null) (
if cfg.extraPackages != [ ] then if cfg.extraPackages != [ ] then
[ [
@ -307,12 +314,5 @@ in
"zed/debug.json".source = jsonFormat.generate "zed-user-debug" cfg.userDebug; "zed/debug.json".source = jsonFormat.generate "zed-user-debug" cfg.userDebug;
}) })
]; ];
assertions = [
{
assertion = cfg.extraPackages != [ ] -> cfg.package != null;
message = "{option}programs.zed-editor.extraPackages requires non null {option}programs.zed-editor.package";
}
];
}; };
} }

View file

@ -30,12 +30,12 @@ in
config = lib.mkMerge [ config = lib.mkMerge [
(lib.mkIf cfg.enable { (lib.mkIf cfg.enable {
home.packages = [ cfg.package ];
assertions = [ assertions = [
(lib.hm.assertions.assertPlatform "services.kdeconnect" pkgs lib.platforms.linux) (lib.hm.assertions.assertPlatform "services.kdeconnect" pkgs lib.platforms.linux)
]; ];
home.packages = [ cfg.package ];
systemd.user.services.kdeconnect = { systemd.user.services.kdeconnect = {
Unit = { Unit = {
Description = "Adds communication between your desktop and your smartphone"; Description = "Adds communication between your desktop and your smartphone";

View file

@ -704,20 +704,6 @@ in
config = mkIf cfg.enable ( config = mkIf cfg.enable (
lib.mkMerge [ lib.mkMerge [
(mkIf (cfg.config != null) {
warnings =
(optional (lib.isList cfg.config.fonts) "Specifying sway.config.fonts as a list is deprecated. Use the attrset version instead.")
++ lib.flatten (
map (
b:
optional (lib.isList b.fonts) "Specifying sway.config.bars[].fonts as a list is deprecated. Use the attrset version instead."
) cfg.config.bars
)
++ [
(mkIf cfg.config.focus.forceWrapping "sway.config.focus.forceWrapping is deprecated, use focus.wrapping instead.")
];
})
{ {
assertions = [ assertions = [
(lib.hm.assertions.assertPlatform "wayland.windowManager.sway" pkgs lib.platforms.linux) (lib.hm.assertions.assertPlatform "wayland.windowManager.sway" pkgs lib.platforms.linux)
@ -753,6 +739,20 @@ in
}; };
}; };
} }
(mkIf (cfg.config != null) {
warnings =
(optional (lib.isList cfg.config.fonts) "Specifying sway.config.fonts as a list is deprecated. Use the attrset version instead.")
++ lib.flatten (
map (
b:
optional (lib.isList b.fonts) "Specifying sway.config.bars[].fonts as a list is deprecated. Use the attrset version instead."
) cfg.config.bars
)
++ [
(mkIf cfg.config.focus.forceWrapping "sway.config.focus.forceWrapping is deprecated, use focus.wrapping instead.")
];
})
] ]
); );
} }