From 4959eee3f3b025333957e1162bced7ddd2746347 Mon Sep 17 00:00:00 2001 From: Jamie Magee Date: Sun, 3 May 2026 20:28:07 -0700 Subject: [PATCH] nixos/systemd/user: drop `with lib;` Drop the `with utils;`, `with systemdUtils.unitOptions;` and `with lib;` blocks and qualify all references with `lib.`, `utils.systemdUtils.lib.` and `utils.systemdUtils.types.` instead. No behavioural change. --- nixos/modules/system/boot/systemd/user.nix | 91 +++++++++++----------- 1 file changed, 44 insertions(+), 47 deletions(-) diff --git a/nixos/modules/system/boot/systemd/user.nix b/nixos/modules/system/boot/systemd/user.nix index 5161a5a2c2ff..baddfb1219ee 100644 --- a/nixos/modules/system/boot/systemd/user.nix +++ b/nixos/modules/system/boot/systemd/user.nix @@ -5,16 +5,13 @@ utils, ... }: -with utils; -with systemdUtils.unitOptions; -with lib; let cfg = config.systemd.user; systemd = config.systemd.package; - inherit (systemdUtils.lib) + inherit (utils.systemdUtils.lib) generateUnits targetToUnit serviceToUnit @@ -53,7 +50,7 @@ let user ? null, }: let - suffix = optionalString (user != null) "-${user}"; + suffix = lib.optionalString (user != null) "-${user}"; in pkgs.writeTextFile { name = "nixos-user-tmpfiles.d${suffix}"; @@ -61,15 +58,15 @@ let text = '' # This file is created automatically and should not be modified. # Please change the options ‘systemd.user.tmpfiles’ instead. - ${concatStringsSep "\n" rules} + ${lib.concatStringsSep "\n" rules} ''; }; in { options = { - systemd.user.extraConfig = mkOption { + systemd.user.extraConfig = lib.mkOption { default = ""; - type = types.lines; + type = lib.types.lines; example = "DefaultTimeoutStartSec=60"; description = '' Extra config options for systemd user instances. See {manpage}`systemd-user.conf(5)` for @@ -77,58 +74,58 @@ in ''; }; - systemd.user.units = mkOption { + systemd.user.units = lib.mkOption { description = "Definition of systemd per-user units."; default = { }; - type = systemdUtils.types.units; + type = utils.systemdUtils.types.units; }; - systemd.user.paths = mkOption { + systemd.user.paths = lib.mkOption { default = { }; - type = systemdUtils.types.paths; + type = utils.systemdUtils.types.paths; description = "Definition of systemd per-user path units."; }; - systemd.user.services = mkOption { + systemd.user.services = lib.mkOption { default = { }; - type = systemdUtils.types.services; + type = utils.systemdUtils.types.services; description = "Definition of systemd per-user service units."; }; - systemd.user.slices = mkOption { + systemd.user.slices = lib.mkOption { default = { }; - type = systemdUtils.types.slices; + type = utils.systemdUtils.types.slices; description = "Definition of systemd per-user slice units."; }; - systemd.user.sockets = mkOption { + systemd.user.sockets = lib.mkOption { default = { }; - type = systemdUtils.types.sockets; + type = utils.systemdUtils.types.sockets; description = "Definition of systemd per-user socket units."; }; - systemd.user.targets = mkOption { + systemd.user.targets = lib.mkOption { default = { }; - type = systemdUtils.types.targets; + type = utils.systemdUtils.types.targets; description = "Definition of systemd per-user target units."; }; - systemd.user.timers = mkOption { + systemd.user.timers = lib.mkOption { default = { }; - type = systemdUtils.types.timers; + type = utils.systemdUtils.types.timers; description = "Definition of systemd per-user timer units."; }; systemd.user.tmpfiles = { enable = - (mkEnableOption "systemd user units systemd-tmpfiles-setup.service and systemd-tmpfiles-clean.timer") + (lib.mkEnableOption "systemd user units systemd-tmpfiles-setup.service and systemd-tmpfiles-clean.timer") // { default = true; example = false; }; - rules = mkOption { - type = types.listOf types.str; + rules = lib.mkOption { + type = lib.types.listOf lib.types.str; default = [ ]; example = [ "D %C - - - 7d" ]; description = '' @@ -139,17 +136,17 @@ in ''; }; - users = mkOption { + users = lib.mkOption { description = '' Per-user rules for creation, deletion and cleaning of volatile and temporary files automatically. ''; default = { }; - type = types.attrsOf ( - types.submodule { + type = lib.types.attrsOf ( + lib.types.submodule { options = { - rules = mkOption { - type = types.listOf types.str; + rules = lib.mkOption { + type = lib.types.listOf lib.types.str; default = [ ]; example = [ "D %C - - - 7d" ]; description = '' @@ -165,8 +162,8 @@ in }; }; - systemd.user.generators = mkOption { - type = types.attrsOf types.path; + systemd.user.generators = lib.mkOption { + type = lib.types.attrsOf lib.types.path; default = { }; example = { systemd-gpt-auto-generator = "/dev/null"; @@ -179,9 +176,9 @@ in ''; }; - systemd.additionalUpstreamUserUnits = mkOption { + systemd.additionalUpstreamUserUnits = lib.mkOption { default = [ ]; - type = types.listOf types.str; + type = lib.types.listOf lib.types.str; example = [ ]; description = '' Additional units shipped with systemd that should be enabled for per-user systemd instances. @@ -210,22 +207,22 @@ in }; systemd.user.units = - mapAttrs' (n: v: nameValuePair "${n}.path" (pathToUnit v)) cfg.paths - // mapAttrs' (n: v: nameValuePair "${n}.service" (serviceToUnit v)) cfg.services - // mapAttrs' (n: v: nameValuePair "${n}.slice" (sliceToUnit v)) cfg.slices - // mapAttrs' (n: v: nameValuePair "${n}.socket" (socketToUnit v)) cfg.sockets - // mapAttrs' (n: v: nameValuePair "${n}.target" (targetToUnit v)) cfg.targets - // mapAttrs' (n: v: nameValuePair "${n}.timer" (timerToUnit v)) cfg.timers; + lib.mapAttrs' (n: v: lib.nameValuePair "${n}.path" (pathToUnit v)) cfg.paths + // lib.mapAttrs' (n: v: lib.nameValuePair "${n}.service" (serviceToUnit v)) cfg.services + // lib.mapAttrs' (n: v: lib.nameValuePair "${n}.slice" (sliceToUnit v)) cfg.slices + // lib.mapAttrs' (n: v: lib.nameValuePair "${n}.socket" (socketToUnit v)) cfg.sockets + // lib.mapAttrs' (n: v: lib.nameValuePair "${n}.target" (targetToUnit v)) cfg.targets + // lib.mapAttrs' (n: v: lib.nameValuePair "${n}.timer" (timerToUnit v)) cfg.timers; systemd.user.timers = { # enable systemd user tmpfiles - systemd-tmpfiles-clean.wantedBy = optional cfg.tmpfiles.enable "timers.target"; + systemd-tmpfiles-clean.wantedBy = lib.optional cfg.tmpfiles.enable "timers.target"; } # Generate timer units for all services that have a ‘startAt’ value. - // (mapAttrs (name: service: { + // (lib.mapAttrs (name: service: { wantedBy = [ "timers.target" ]; timerConfig.OnCalendar = service.startAt; - }) (filterAttrs (name: service: service.startAt != [ ]) cfg.services)); + }) (lib.filterAttrs (name: service: service.startAt != [ ]) cfg.services)); # Provide the systemd-user PAM service, required to run systemd # user instances. @@ -244,18 +241,18 @@ in systemd.services.systemd-user-sessions.restartIfChanged = false; # Restart kills all active sessions. # enable systemd user tmpfiles - systemd.user.services.systemd-tmpfiles-setup.wantedBy = optional cfg.tmpfiles.enable "basic.target"; + systemd.user.services.systemd-tmpfiles-setup.wantedBy = lib.optional cfg.tmpfiles.enable "basic.target"; # /run/current-system/sw/etc/xdg is in systemd's $XDG_CONFIG_DIRS so we can # write the tmpfiles.d rules for everyone there - environment.systemPackages = optional (cfg.tmpfiles.rules != [ ]) (writeTmpfiles { + environment.systemPackages = lib.optional (cfg.tmpfiles.rules != [ ]) (writeTmpfiles { inherit (cfg.tmpfiles) rules; }); # /etc/profiles/per-user/$USER/etc/xdg is in systemd's $XDG_CONFIG_DIRS so # we can write a single user's tmpfiles.d rules there - users.users = mapAttrs (user: cfg': { - packages = optional (cfg'.rules != [ ]) (writeTmpfiles { + users.users = lib.mapAttrs (user: cfg': { + packages = lib.optional (cfg'.rules != [ ]) (writeTmpfiles { inherit (cfg') rules; inherit user; });