From 41903a14b03614bc22d9726b854f54e1e1839c9e Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Sun, 18 Jul 2021 23:34:50 +0200 Subject: [PATCH] Remove a few format exceptions --- format | 10 - modules/misc/nixpkgs.nix | 63 ++--- modules/misc/xdg.nix | 14 +- modules/modules.nix | 17 +- modules/programs/firefox.nix | 210 +++++++-------- modules/services/sxhkd.nix | 51 ++-- modules/systemd.nix | 247 ++++++++---------- .../programs/zsh/session-variables.nix | 7 +- tests/modules/services/sxhkd/service.nix | 4 +- tests/modules/systemd/services.nix | 22 +- tests/modules/systemd/session-variables.nix | 12 +- 11 files changed, 283 insertions(+), 374 deletions(-) diff --git a/format b/format index 5682a1f2..bcdaf7b4 100755 --- a/format +++ b/format @@ -26,25 +26,15 @@ find . -name '*.nix' \ ! -path ./modules/lib/file-type.nix \ ! -path ./modules/manual.nix \ ! -path ./modules/misc/news.nix \ - ! -path ./modules/misc/nixpkgs.nix \ - ! -path ./modules/misc/xdg.nix \ - ! -path ./modules/modules.nix \ ! -path ./modules/programs/bash.nix \ - ! -path ./modules/programs/firefox.nix \ ! -path ./modules/programs/gpg.nix \ ! -path ./modules/programs/ssh.nix \ ! -path ./modules/programs/tmux.nix \ ! -path ./modules/programs/zsh.nix \ ! -path ./modules/services/gpg-agent.nix \ ! -path ./modules/services/mpd.nix \ - ! -path ./modules/services/sxhkd.nix \ - ! -path ./modules/systemd.nix \ ! -path ./nix-darwin/default.nix \ ! -path ./tests/default.nix \ ! -path ./tests/modules/home-environment/session-variables.nix \ ! -path ./tests/modules/programs/gpg/override-defaults.nix \ - ! -path ./tests/modules/programs/zsh/session-variables.nix \ - ! -path ./tests/modules/services/sxhkd/service.nix \ - ! -path ./tests/modules/systemd/services.nix \ - ! -path ./tests/modules/systemd/session-variables.nix \ -exec nixfmt $CHECK_ARG {} + diff --git a/modules/misc/nixpkgs.nix b/modules/misc/nixpkgs.nix index 511dbec1..4ad7e4cf 100644 --- a/modules/misc/nixpkgs.nix +++ b/modules/misc/nixpkgs.nix @@ -6,40 +6,31 @@ with lib; let - isConfig = x: - builtins.isAttrs x || builtins.isFunction x; + isConfig = x: builtins.isAttrs x || builtins.isFunction x; - optCall = f: x: - if builtins.isFunction f - then f x - else f; + optCall = f: x: if builtins.isFunction f then f x else f; mergeConfig = lhs_: rhs_: let lhs = optCall lhs_ { inherit pkgs; }; rhs = optCall rhs_ { inherit pkgs; }; - in - lhs // rhs // - optionalAttrs (lhs ? packageOverrides) { + in lhs // rhs // optionalAttrs (lhs ? packageOverrides) { packageOverrides = pkgs: - optCall lhs.packageOverrides pkgs // - optCall (attrByPath ["packageOverrides"] ({}) rhs) pkgs; - } // - optionalAttrs (lhs ? perlPackageOverrides) { + optCall lhs.packageOverrides pkgs + // optCall (attrByPath [ "packageOverrides" ] ({ }) rhs) pkgs; + } // optionalAttrs (lhs ? perlPackageOverrides) { perlPackageOverrides = pkgs: - optCall lhs.perlPackageOverrides pkgs // - optCall (attrByPath ["perlPackageOverrides"] ({}) rhs) pkgs; + optCall lhs.perlPackageOverrides pkgs + // optCall (attrByPath [ "perlPackageOverrides" ] ({ }) rhs) pkgs; }; configType = mkOptionType { name = "nixpkgs-config"; description = "nixpkgs config"; check = x: - let traceXIfNot = c: - if c x then true - else lib.traceSeqN 1 x false; + let traceXIfNot = c: if c x then true else lib.traceSeqN 1 x false; in traceXIfNot isConfig; - merge = args: fold (def: mergeConfig def.value) {}; + merge = args: fold (def: mergeConfig def.value) { }; }; overlayType = mkOptionType { @@ -49,13 +40,9 @@ let merge = lib.mergeOneOption; }; - _pkgs = import pkgsPath ( - filterAttrs (n: v: v != null) config.nixpkgs - ); + _pkgs = import pkgsPath (filterAttrs (n: v: v != null) config.nixpkgs); -in - -{ +in { options.nixpkgs = { config = mkOption { default = null; @@ -91,17 +78,16 @@ in overlays = mkOption { default = null; - example = literalExample - '' - [ (self: super: { - openssh = super.openssh.override { - hpnSupport = true; - withKerberos = true; - kerberos = self.libkrb5; - }; + example = literalExample '' + [ (self: super: { + openssh = super.openssh.override { + hpnSupport = true; + withKerberos = true; + kerberos = self.libkrb5; }; - ) ] - ''; + }; + ) ] + ''; type = types.nullOr (types.listOf overlayType); description = '' List of overlays to use with the Nix Packages collection. (For @@ -144,9 +130,10 @@ in _module.args = { pkgs = mkOverride modules.defaultPriority _pkgs; pkgs_i686 = - if _pkgs.stdenv.isLinux && _pkgs.stdenv.hostPlatform.isx86 - then _pkgs.pkgsi686Linux - else { }; + if _pkgs.stdenv.isLinux && _pkgs.stdenv.hostPlatform.isx86 then + _pkgs.pkgsi686Linux + else + { }; }; }; } diff --git a/modules/misc/xdg.nix b/modules/misc/xdg.nix index 6b2917d4..2b331dfa 100644 --- a/modules/misc/xdg.nix +++ b/modules/misc/xdg.nix @@ -16,14 +16,10 @@ let defaultDataHome = "${config.home.homeDirectory}/.local/share"; getXdgDir = name: fallback: - let - value = builtins.getEnv name; - in - if value != "" then value else fallback; + let value = builtins.getEnv name; + in if value != "" then value else fallback; -in - -{ +in { options.xdg = { enable = mkEnableOption "management of XDG base directories"; @@ -37,7 +33,7 @@ in configFile = mkOption { type = fileType "xdg.configHome" cfg.configHome; - default = {}; + default = { }; description = '' Attribute set of files to link into the user's XDG configuration home. @@ -54,7 +50,7 @@ in dataFile = mkOption { type = fileType "xdg.dataHome" cfg.dataHome; - default = {}; + default = { }; description = '' Attribute set of files to link into the user's XDG data home. diff --git a/modules/modules.nix b/modules/modules.nix index a82c3cb6..2f16ae80 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -1,14 +1,13 @@ { pkgs - # Note, this should be "the standard library" + HM extensions. +# Note, this should be "the standard library" + HM extensions. , lib - # Whether to enable module type checking. +# Whether to enable module type checking. , check ? true -# If disabled, the pkgs attribute passed to this function is used instead. -, useNixpkgsModule ? true -}: + # If disabled, the pkgs attribute passed to this function is used instead. +, useNixpkgsModule ? true }: with lib; @@ -237,8 +236,8 @@ let pkgsModule = { config, ... }: { config = { _module.args.baseModules = modules; - _module.args.pkgsPath = lib.mkDefault ( - if versionAtLeast config.home.stateVersion "20.09" then + _module.args.pkgsPath = lib.mkDefault + (if versionAtLeast config.home.stateVersion "20.09" then pkgs.path else ); @@ -250,6 +249,4 @@ let }; }; -in - - modules ++ [ pkgsModule ] +in modules ++ [ pkgsModule ] diff --git a/modules/programs/firefox.nix b/modules/programs/firefox.nix index d474f5b8..0d1af97c 100644 --- a/modules/programs/firefox.nix +++ b/modules/programs/firefox.nix @@ -9,19 +9,15 @@ let cfg = config.programs.firefox; mozillaConfigPath = - if isDarwin - then "Library/Application Support/Mozilla" - else ".mozilla"; + if isDarwin then "Library/Application Support/Mozilla" else ".mozilla"; - firefoxConfigPath = - if isDarwin - then "Library/Application Support/Firefox" - else "${mozillaConfigPath}/firefox"; + firefoxConfigPath = if isDarwin then + "Library/Application Support/Firefox" + else + "${mozillaConfigPath}/firefox"; profilesPath = - if isDarwin - then "${firefoxConfigPath}/Profiles" - else firefoxConfigPath; + if isDarwin then "${firefoxConfigPath}/Profiles" else firefoxConfigPath; # The extensions path shared by all profiles; will not be supported # by future Firefox versions. @@ -32,24 +28,17 @@ let paths = cfg.extensions; }; - profiles = - flip mapAttrs' cfg.profiles (_: profile: - nameValuePair "Profile${toString profile.id}" { - Name = profile.name; - Path = - if isDarwin - then "Profiles/${profile.path}" - else profile.path; - IsRelative = 1; - Default = if profile.isDefault then 1 else 0; - } - ) // { - General = { - StartWithLastProfile = 1; - }; + profiles = flip mapAttrs' cfg.profiles (_: profile: + nameValuePair "Profile${toString profile.id}" { + Name = profile.name; + Path = if isDarwin then "Profiles/${profile.path}" else profile.path; + IsRelative = 1; + Default = if profile.isDefault then 1 else 0; + }) // { + General = { StartWithLastProfile = 1; }; }; - profilesIni = generators.toINI {} profiles; + profilesIni = generators.toINI { } profiles; mkUserJs = prefs: extraPrefs: '' // Generated by Home Manager. @@ -61,17 +50,15 @@ let ${extraPrefs} ''; -in - -{ +in { meta.maintainers = [ maintainers.rycee ]; imports = [ - (mkRemovedOptionModule ["programs" "firefox" "enableAdobeFlash"] + (mkRemovedOptionModule [ "programs" "firefox" "enableAdobeFlash" ] "Support for this option has been removed.") - (mkRemovedOptionModule ["programs" "firefox" "enableGoogleTalk"] + (mkRemovedOptionModule [ "programs" "firefox" "enableGoogleTalk" ] "Support for this option has been removed.") - (mkRemovedOptionModule ["programs" "firefox" "enableIcedTea"] + (mkRemovedOptionModule [ "programs" "firefox" "enableIcedTea" ] "Support for this option has been removed.") ]; @@ -81,10 +68,10 @@ in package = mkOption { type = types.package; - default = - if versionAtLeast config.home.stateVersion "19.09" - then pkgs.firefox - else pkgs.firefox-unwrapped; + default = if versionAtLeast config.home.stateVersion "19.09" then + pkgs.firefox + else + pkgs.firefox-unwrapped; defaultText = literalExample "pkgs.firefox"; example = literalExample '' pkgs.firefox.override { @@ -106,7 +93,7 @@ in extensions = mkOption { type = types.listOf types.package; - default = []; + default = [ ]; example = literalExample '' with pkgs.nur.repos.rycee.firefox-addons; [ https-everywhere @@ -141,7 +128,7 @@ in }; profiles = mkOption { - type = types.attrsOf (types.submodule ({config, name, ...}: { + type = types.attrsOf (types.submodule ({ config, name, ... }: { options = { name = mkOption { type = types.str; @@ -159,7 +146,7 @@ in settings = mkOption { type = with types; attrsOf (either bool (either int str)); - default = {}; + default = { }; example = literalExample '' { "browser.startup.homepage" = "https://nixos.org"; @@ -224,7 +211,7 @@ in }; }; })); - default = {}; + default = { }; description = "Attribute set of Firefox profiles."; }; @@ -243,36 +230,27 @@ in config = mkIf cfg.enable { assertions = [ - ( - let - defaults = - catAttrs "name" (filter (a: a.isDefault) (attrValues cfg.profiles)); - in { - assertion = cfg.profiles == {} || length defaults == 1; - message = - "Must have exactly one default Firefox profile but found " - + toString (length defaults) - + optionalString (length defaults > 1) - (", namely " + concatStringsSep ", " defaults); - } - ) + (let + defaults = + catAttrs "name" (filter (a: a.isDefault) (attrValues cfg.profiles)); + in { + assertion = cfg.profiles == { } || length defaults == 1; + message = "Must have exactly one default Firefox profile but found " + + toString (length defaults) + optionalString (length defaults > 1) + (", namely " + concatStringsSep ", " defaults); + }) - ( - let - duplicates = - filterAttrs (_: v: length v != 1) - (zipAttrs - (mapAttrsToList (n: v: { "${toString v.id}" = n; }) - (cfg.profiles))); + (let + duplicates = filterAttrs (_: v: length v != 1) (zipAttrs + (mapAttrsToList (n: v: { "${toString v.id}" = n; }) (cfg.profiles))); - mkMsg = n: v: " - ID ${n} is used by ${concatStringsSep ", " v}"; - in { - assertion = duplicates == {}; - message = - "Must not have Firefox profiles with duplicate IDs but\n" - + concatStringsSep "\n" (mapAttrsToList mkMsg duplicates); - } - ) + mkMsg = n: v: " - ID ${n} is used by ${concatStringsSep ", " v}"; + in { + assertion = duplicates == { }; + message = '' + Must not have Firefox profiles with duplicate IDs but + '' + concatStringsSep "\n" (mapAttrsToList mkMsg duplicates); + }) ]; warnings = optional (cfg.enableGnomeExtensions or false) '' @@ -282,65 +260,53 @@ in its example for how to do this. ''; - home.packages = - let - # The configuration expected by the Firefox wrapper. - fcfg = { - enableGnomeExtensions = cfg.enableGnomeExtensions; + home.packages = let + # The configuration expected by the Firefox wrapper. + fcfg = { enableGnomeExtensions = cfg.enableGnomeExtensions; }; + + # A bit of hackery to force a config into the wrapper. + browserName = cfg.package.browserName or (builtins.parseDrvName + cfg.package.name).name; + + # The configuration expected by the Firefox wrapper builder. + bcfg = setAttrByPath [ browserName ] fcfg; + + package = if isDarwin then + cfg.package + else if versionAtLeast config.home.stateVersion "19.09" then + cfg.package.override (old: { cfg = old.cfg or { } // fcfg; }) + else + (pkgs.wrapFirefox.override { config = bcfg; }) cfg.package { }; + in [ package ]; + + home.file = mkMerge ([{ + "${mozillaConfigPath}/${extensionPath}" = mkIf (cfg.extensions != [ ]) { + source = "${extensionsEnvPkg}/share/mozilla/${extensionPath}"; + recursive = true; + }; + + "${firefoxConfigPath}/profiles.ini" = + mkIf (cfg.profiles != { }) { text = profilesIni; }; + }] ++ flip mapAttrsToList cfg.profiles (_: profile: { + "${profilesPath}/${profile.path}/.keep".text = ""; + + "${profilesPath}/${profile.path}/chrome/userChrome.css" = + mkIf (profile.userChrome != "") { text = profile.userChrome; }; + + "${profilesPath}/${profile.path}/chrome/userContent.css" = + mkIf (profile.userContent != "") { text = profile.userContent; }; + + "${profilesPath}/${profile.path}/user.js" = + mkIf (profile.settings != { } || profile.extraConfig != "") { + text = mkUserJs profile.settings profile.extraConfig; }; - # A bit of hackery to force a config into the wrapper. - browserName = cfg.package.browserName - or (builtins.parseDrvName cfg.package.name).name; - - # The configuration expected by the Firefox wrapper builder. - bcfg = setAttrByPath [browserName] fcfg; - - package = - if isDarwin then - cfg.package - else if versionAtLeast config.home.stateVersion "19.09" then - cfg.package.override (old: { cfg = old.cfg or {} // fcfg; }) - else - (pkgs.wrapFirefox.override { config = bcfg; }) cfg.package { }; - in - [ package ]; - - home.file = mkMerge ( - [{ - "${mozillaConfigPath}/${extensionPath}" = mkIf (cfg.extensions != []) { - source = "${extensionsEnvPkg}/share/mozilla/${extensionPath}"; - recursive = true; - }; - - "${firefoxConfigPath}/profiles.ini" = mkIf (cfg.profiles != {}) { - text = profilesIni; - }; - }] - ++ flip mapAttrsToList cfg.profiles (_: profile: { - "${profilesPath}/${profile.path}/.keep".text = ""; - - "${profilesPath}/${profile.path}/chrome/userChrome.css" = - mkIf (profile.userChrome != "") { - text = profile.userChrome; - }; - - "${profilesPath}/${profile.path}/chrome/userContent.css" = - mkIf (profile.userContent != "") { - text = profile.userContent; - }; - - "${profilesPath}/${profile.path}/user.js" = - mkIf (profile.settings != {} || profile.extraConfig != "") { - text = mkUserJs profile.settings profile.extraConfig; - }; - - "${profilesPath}/${profile.path}/extensions" = mkIf (cfg.extensions != []) { + "${profilesPath}/${profile.path}/extensions" = + mkIf (cfg.extensions != [ ]) { source = "${extensionsEnvPkg}/share/mozilla/${extensionPath}"; recursive = true; force = true; }; - }) - ); + })); }; } diff --git a/modules/services/sxhkd.nix b/modules/services/sxhkd.nix index 363c1fb2..486e4020 100644 --- a/modules/services/sxhkd.nix +++ b/modules/services/sxhkd.nix @@ -1,4 +1,4 @@ -{config, lib, pkgs, ...}: +{ config, lib, pkgs, ... }: with lib; @@ -6,22 +6,16 @@ let cfg = config.services.sxhkd; - keybindingsStr = concatStringsSep "\n" ( - mapAttrsToList (hotkey: command: - optionalString (command != null) '' - ${hotkey} - ${command} - '' - ) - cfg.keybindings - ); + keybindingsStr = concatStringsSep "\n" (mapAttrsToList (hotkey: command: + optionalString (command != null) '' + ${hotkey} + ${command} + '') cfg.keybindings); -in - -{ +in { imports = [ - (mkRemovedOptionModule ["services" "sxhkd" "extraPath"] - "This option is no longer needed and can be removed.") + (mkRemovedOptionModule [ "services" "sxhkd" "extraPath" ] + "This option is no longer needed and can be removed.") ]; options.services.sxhkd = { @@ -31,19 +25,21 @@ in type = types.package; default = pkgs.sxhkd; defaultText = "pkgs.sxhkd"; - description = "Package containing the sxhkd executable."; + description = + "Package containing the sxhkd executable."; }; extraOptions = mkOption { type = types.listOf types.str; default = [ ]; - description = "Command line arguments to invoke sxhkd with."; + description = + "Command line arguments to invoke sxhkd with."; example = literalExample ''[ "-m 1" ]''; }; keybindings = mkOption { type = types.attrsOf (types.nullOr types.str); - default = {}; + default = { }; description = "An attribute set that assigns hotkeys to commands."; example = literalExample '' { @@ -72,17 +68,14 @@ in home.packages = [ cfg.package ]; - xdg.configFile."sxhkd/sxhkdrc".text = concatStringsSep "\n" [ - keybindingsStr - cfg.extraConfig - ]; + xdg.configFile."sxhkd/sxhkdrc".text = + concatStringsSep "\n" [ keybindingsStr cfg.extraConfig ]; - xsession.initExtra = - let - sxhkdCommand = "${cfg.package}/bin/sxhkd ${toString cfg.extraOptions}"; - in '' - systemctl --user stop sxhkd.scope 2> /dev/null || true - systemd-cat -t sxhkd systemd-run --user --scope -u sxhkd ${sxhkdCommand} & - ''; + xsession.initExtra = let + sxhkdCommand = "${cfg.package}/bin/sxhkd ${toString cfg.extraOptions}"; + in '' + systemctl --user stop sxhkd.scope 2> /dev/null || true + systemd-cat -t sxhkd systemd-run --user --scope -u sxhkd ${sxhkdCommand} & + ''; }; } diff --git a/modules/systemd.nix b/modules/systemd.nix index a5a069c5..a2b1a96d 100644 --- a/modules/systemd.nix +++ b/modules/systemd.nix @@ -7,27 +7,28 @@ let inherit (lib) getAttr hm isBool literalExample mkIf mkMerge mkOption types; # From - mkPathSafeName = lib.replaceChars ["@" ":" "\\" "[" "]"] ["-" "-" "-" "" ""]; + mkPathSafeName = + lib.replaceChars [ "@" ":" "\\" "[" "]" ] [ "-" "-" "-" "" "" ]; - enabled = cfg.services != {} - || cfg.slices != {} - || cfg.sockets != {} - || cfg.targets != {} - || cfg.timers != {} - || cfg.paths != {} - || cfg.mounts != {} - || cfg.automounts != {} - || cfg.sessionVariables != {}; + enabled = cfg.services != { } # \ + || cfg.slices != { } # \ + || cfg.sockets != { } # \ + || cfg.targets != { } # \ + || cfg.timers != { } # \ + || cfg.paths != { } # \ + || cfg.mounts != { } # \ + || cfg.automounts != { } # \ + || cfg.sessionVariables != { }; toSystemdIni = lib.generators.toINI { listsAsDuplicateKeys = true; mkKeyValue = key: value: let - value' = - if isBool value then (if value then "true" else "false") - else toString value; - in - "${key}=${value'}"; + value' = if isBool value then + (if value then "true" else "false") + else + toString value; + in "${key}=${value'}"; }; buildService = style: name: serviceCfg: @@ -43,32 +44,26 @@ let destination = lib.escapeShellArg "/${filename}"; } + "/${filename}"; - wantedBy = target: - { - name = "systemd/user/${target}.wants/${filename}"; - value = { inherit source; }; - }; - in - lib.singleton { - name = "systemd/user/${filename}"; + wantedBy = target: { + name = "systemd/user/${target}.wants/${filename}"; value = { inherit source; }; - } - ++ - map wantedBy (serviceCfg.Install.WantedBy or []); + }; + in lib.singleton { + name = "systemd/user/${filename}"; + value = { inherit source; }; + } ++ map wantedBy (serviceCfg.Install.WantedBy or [ ]); buildServices = style: serviceCfgs: lib.concatLists (lib.mapAttrsToList (buildService style) serviceCfgs); servicesStartTimeoutMs = builtins.toString cfg.servicesStartTimeoutMs; - unitType = unitKind: with types; - let - primitive = either bool (either int str); - in - attrsOf (attrsOf (attrsOf (either primitive (listOf primitive)))) - // { - description = "systemd ${unitKind} unit configuration"; - }; + unitType = unitKind: + with types; + let primitive = either bool (either int str); + in attrsOf (attrsOf (attrsOf (either primitive (listOf primitive)))) // { + description = "systemd ${unitKind} unit configuration"; + }; unitDescription = type: '' Definition of systemd per-user ${type} units. Attributes are @@ -82,31 +77,29 @@ let . ''; - unitExample = type: literalExample '' - { - ${lib.toLower type}-name = { - Unit = { - Description = "Example description"; - Documentation = [ "man:example(1)" "man:example(5)" ]; - }; + unitExample = type: + literalExample '' + { + ${lib.toLower type}-name = { + Unit = { + Description = "Example description"; + Documentation = [ "man:example(1)" "man:example(5)" ]; + }; - ${type} = { - … + ${type} = { + … + }; }; }; - }; - ''; + ''; - sessionVariables = mkIf (cfg.sessionVariables != {}) { - "environment.d/10-home-manager.conf".text = - lib.concatStringsSep "\n" ( - lib.mapAttrsToList (n: v: "${n}=${toString v}") cfg.sessionVariables - ) + "\n"; - }; + sessionVariables = mkIf (cfg.sessionVariables != { }) { + "environment.d/10-home-manager.conf".text = lib.concatStringsSep "\n" + (lib.mapAttrsToList (n: v: "${n}=${toString v}") cfg.sessionVariables) + + "\n"; + }; -in - -{ +in { meta.maintainers = [ lib.maintainers.rycee ]; options = { @@ -123,56 +116,56 @@ in }; services = mkOption { - default = {}; + default = { }; type = unitType "service"; description = unitDescription "service"; example = unitExample "Service"; }; slices = mkOption { - default = {}; + default = { }; type = unitType "slices"; description = unitDescription "slices"; example = unitExample "Slices"; }; sockets = mkOption { - default = {}; + default = { }; type = unitType "socket"; description = unitDescription "socket"; example = unitExample "Socket"; }; targets = mkOption { - default = {}; + default = { }; type = unitType "target"; description = unitDescription "target"; example = unitExample "Target"; }; timers = mkOption { - default = {}; + default = { }; type = unitType "timer"; description = unitDescription "timer"; example = unitExample "Timer"; }; paths = mkOption { - default = {}; + default = { }; type = unitType "path"; description = unitDescription "path"; example = unitExample "Path"; }; mounts = mkOption { - default = {}; + default = { }; type = unitType "mount"; description = unitDescription "mount"; example = unitExample "Mount"; }; automounts = mkOption { - default = {}; + default = { }; type = unitType "automount"; description = unitDescription "automount"; example = unitExample "Automount"; @@ -180,10 +173,9 @@ in startServices = mkOption { default = "suggest"; - type = with types; either bool (enum ["suggest" "legacy" "sd-switch"]); - apply = p: - if isBool p then if p then "legacy" else "suggest" - else p; + type = with types; + either bool (enum [ "suggest" "legacy" "sd-switch" ]); + apply = p: if isBool p then if p then "legacy" else "suggest" else p; description = '' Whether new or changed services that are wanted by active targets should be started. Additionally, stop obsolete services from the @@ -231,7 +223,7 @@ in }; sessionVariables = mkOption { - default = {}; + default = { }; type = with types; attrsOf (either int str); example = { EDITOR = "vim"; }; description = '' @@ -248,54 +240,44 @@ in config = mkMerge [ { - assertions = [ - { - assertion = enabled -> pkgs.stdenv.isLinux; - message = - let - names = lib.concatStringsSep ", " ( - lib.attrNames ( - cfg.services // cfg.slices // cfg.sockets // cfg.targets - // cfg.timers // cfg.paths // cfg.mounts // cfg.sessionVariables - ) - ); - in - "Must use Linux for modules that require systemd: " + names; - } - ]; + assertions = [{ + assertion = enabled -> pkgs.stdenv.isLinux; + message = let + names = lib.concatStringsSep ", " (lib.attrNames ( # \ + cfg.services # \ + // cfg.slices # \ + // cfg.sockets # \ + // cfg.targets # \ + // cfg.timers # \ + // cfg.paths # \ + // cfg.mounts # \ + // cfg.sessionVariables)); + in "Must use Linux for modules that require systemd: " + names; + }]; } # If we run under a Linux system we assume that systemd is # available, in particular we assume that systemctl is in PATH. (mkIf pkgs.stdenv.isLinux { xdg.configFile = mkMerge [ - (lib.listToAttrs ( - (buildServices "service" cfg.services) - ++ - (buildServices "slices" cfg.slices) - ++ - (buildServices "socket" cfg.sockets) - ++ - (buildServices "target" cfg.targets) - ++ - (buildServices "timer" cfg.timers) - ++ - (buildServices "path" cfg.paths) - ++ - (buildServices "mount" cfg.mounts) - ++ - (buildServices "automount" cfg.automounts) - )) + (lib.listToAttrs ((buildServices "service" cfg.services) + ++ (buildServices "slices" cfg.slices) + ++ (buildServices "socket" cfg.sockets) + ++ (buildServices "target" cfg.targets) + ++ (buildServices "timer" cfg.timers) + ++ (buildServices "path" cfg.paths) + ++ (buildServices "mount" cfg.mounts) + ++ (buildServices "automount" cfg.automounts))) - sessionVariables - ]; + sessionVariables + ]; # Run systemd service reload if user is logged in. If we're # running this from the NixOS module then XDG_RUNTIME_DIR is not # set and systemd commands will fail. We'll therefore have to # set it ourselves in that case. - home.activation.reloadSystemd = hm.dag.entryAfter ["linkGeneration"] ( - let + home.activation.reloadSystemd = hm.dag.entryAfter [ "linkGeneration" ] + (let cmd = { suggest = '' PATH=${dirOf cfg.systemctlPath}:$PATH \ @@ -306,44 +288,41 @@ in ${pkgs.ruby}/bin/ruby ${./systemd-activate.rb} \ "''${oldGenPath=}" "$newGenPath" "${servicesStartTimeoutMs}" ''; - sd-switch = - let - timeoutArg = - if cfg.servicesStartTimeoutMs != 0 then - "--timeout " + servicesStartTimeoutMs - else - ""; - in '' - ${pkgs.sd-switch}/bin/sd-switch \ - ''${DRY_RUN:+--dry-run} $VERBOSE_ARG ${timeoutArg} \ - ''${oldGenPath:+--old-units $oldGenPath/home-files/.config/systemd/user} \ - --new-units $newGenPath/home-files/.config/systemd/user - ''; + sd-switch = let + timeoutArg = if cfg.servicesStartTimeoutMs != 0 then + "--timeout " + servicesStartTimeoutMs + else + ""; + in '' + ${pkgs.sd-switch}/bin/sd-switch \ + ''${DRY_RUN:+--dry-run} $VERBOSE_ARG ${timeoutArg} \ + ''${oldGenPath:+--old-units $oldGenPath/home-files/.config/systemd/user} \ + --new-units $newGenPath/home-files/.config/systemd/user + ''; }; - ensureRuntimeDir = "XDG_RUNTIME_DIR=\${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"; + ensureRuntimeDir = + "XDG_RUNTIME_DIR=\${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"; systemctl = "${ensureRuntimeDir} ${cfg.systemctlPath}"; - in - '' - systemdStatus=$(${systemctl} --user is-system-running 2>&1 || true) + in '' + systemdStatus=$(${systemctl} --user is-system-running 2>&1 || true) - if [[ $systemdStatus == 'running' || $systemdStatus == 'degraded' ]]; then - if [[ $systemdStatus == 'degraded' ]]; then - warnEcho "The user systemd session is degraded:" - ${systemctl} --user --no-pager --state=failed - warnEcho "Attempting to reload services anyway..." - fi - - ${ensureRuntimeDir} \ - ${getAttr cfg.startServices cmd} - else - echo "User systemd daemon not running. Skipping reload." + if [[ $systemdStatus == 'running' || $systemdStatus == 'degraded' ]]; then + if [[ $systemdStatus == 'degraded' ]]; then + warnEcho "The user systemd session is degraded:" + ${systemctl} --user --no-pager --state=failed + warnEcho "Attempting to reload services anyway..." fi - unset systemdStatus - '' - ); + ${ensureRuntimeDir} \ + ${getAttr cfg.startServices cmd} + else + echo "User systemd daemon not running. Skipping reload." + fi + + unset systemdStatus + ''); }) ]; } diff --git a/tests/modules/programs/zsh/session-variables.nix b/tests/modules/programs/zsh/session-variables.nix index ca903619..5c322be1 100644 --- a/tests/modules/programs/zsh/session-variables.nix +++ b/tests/modules/programs/zsh/session-variables.nix @@ -13,11 +13,8 @@ with lib; }; }; - nixpkgs.overlays = [ - (self: super: { - zsh = pkgs.writeScriptBin "dummy-zsh" ""; - }) - ]; + nixpkgs.overlays = + [ (self: super: { zsh = pkgs.writeScriptBin "dummy-zsh" ""; }) ]; nmt.script = '' assertFileExists home-files/.zshrc diff --git a/tests/modules/services/sxhkd/service.nix b/tests/modules/services/sxhkd/service.nix index be51f544..44bed425 100644 --- a/tests/modules/services/sxhkd/service.nix +++ b/tests/modules/services/sxhkd/service.nix @@ -9,7 +9,9 @@ services.sxhkd = { enable = true; - package = pkgs.runCommandLocal "dummy-package" { } "mkdir $out" // { outPath = "@sxhkd@"; }; + package = pkgs.runCommandLocal "dummy-package" { } "mkdir $out" // { + outPath = "@sxhkd@"; + }; extraOptions = [ "-m 1" ]; }; diff --git a/tests/modules/systemd/services.nix b/tests/modules/systemd/services.nix index 4f73c556..fbef7b9c 100644 --- a/tests/modules/systemd/services.nix +++ b/tests/modules/systemd/services.nix @@ -5,9 +5,7 @@ with lib; { config = { systemd.user.services."test-service@" = { - Unit = { - Description = "A basic test service"; - }; + Unit = { Description = "A basic test service"; }; Service = { Environment = [ "VAR1=1" "VAR2=2" ]; @@ -19,15 +17,17 @@ with lib; serviceFile=home-files/.config/systemd/user/test-service@.service assertFileExists $serviceFile assertFileContent $serviceFile \ - ${builtins.toFile "services-expected.conf" '' - [Service] - Environment=VAR1=1 - Environment=VAR2=2 - ExecStart=/some/exec/start/command --with-arguments "%i" + ${ + builtins.toFile "services-expected.conf" '' + [Service] + Environment=VAR1=1 + Environment=VAR2=2 + ExecStart=/some/exec/start/command --with-arguments "%i" - [Unit] - Description=A basic test service - ''} + [Unit] + Description=A basic test service + '' + } ''; }; } diff --git a/tests/modules/systemd/session-variables.nix b/tests/modules/systemd/session-variables.nix index 59d1a4d3..8722a9ab 100644 --- a/tests/modules/systemd/session-variables.nix +++ b/tests/modules/systemd/session-variables.nix @@ -10,11 +10,13 @@ nmt.script = '' envFile=home-files/.config/environment.d/10-home-manager.conf assertFileExists $envFile - assertFileContent $envFile ${pkgs.writeText "expected" '' - LOCALE_ARCHIVE_2_27=${pkgs.glibcLocales}/lib/locale/locale-archive - V_int=1 - V_str=2 - ''} + assertFileContent $envFile ${ + pkgs.writeText "expected" '' + LOCALE_ARCHIVE_2_27=${pkgs.glibcLocales}/lib/locale/locale-archive + V_int=1 + V_str=2 + '' + } ''; }; }