Files
home-manager/modules/default.nix
Austin Horstman 01ea51d706 treewide: use inherit for attribute assignments
This change converts redundant attribute assignments of the form `a =
a;` or `a = someSet.a;` into cleaner `inherit` statements. This reduces
verbosity and follows common Nix style for bringing attributes into
scope.

Statix Codes: W03 (manual_inherit), W04 (manual_inherit_from)

Also include statix and the rule in our configuration.
2026-04-08 14:47:48 -05:00

78 lines
1.7 KiB
Nix
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{
configuration,
pkgs,
lib ? pkgs.lib,
minimal ? false,
# Whether to check that each option has a matching declaration.
check ? true,
# Extra arguments passed to specialArgs.
extraSpecialArgs ? { },
}:
let
collectFailed = cfg: map (x: x.message) (lib.filter (x: !x.assertion) cfg.assertions);
showWarnings =
res:
let
f = w: x: builtins.trace "warning: ${w}" x;
in
lib.foldr f res res.config.warnings;
extendedLib = import ./lib/stdlib-extended.nix lib;
hmModules = import ./modules.nix {
inherit check pkgs minimal;
lib = extendedLib;
};
rawModule = extendedLib.evalModules {
modules = [ configuration ] ++ hmModules;
class = "homeManager";
specialArgs = {
modulesPath = toString ./.;
}
// extraSpecialArgs;
};
moduleChecks =
raw:
showWarnings (
let
failed = collectFailed raw.config;
failedStr = lib.concatStringsSep "\n" (map (x: "- ${x}") failed);
in
if failed == [ ] then
raw
else
throw ''
Failed assertions:
${failedStr}''
);
withExtraAttrs =
rawModule:
let
module = moduleChecks rawModule;
in
module
// {
inherit (module.config.home) activationPackage;
# For backwards compatibility. Please use activationPackage instead.
activation-script = module.config.home.activationPackage;
newsDisplay = rawModule.config.news.display;
newsEntries = lib.sort (a: b: a.time > b.time) (
lib.filter (a: a.condition) rawModule.config.news.entries
);
inherit (module._module.args) pkgs;
extendModules = args: withExtraAttrs (rawModule.extendModules args);
};
in
withExtraAttrs rawModule