diff --git a/modules/services/autorandr.nix b/modules/services/autorandr.nix index 78a2ac27f..80ecec776 100644 --- a/modules/services/autorandr.nix +++ b/modules/services/autorandr.nix @@ -4,20 +4,15 @@ pkgs, ... }: - -with lib; - let cfg = config.services.autorandr; - in { - - meta.maintainers = [ maintainers.GaetanLepage ]; + meta.maintainers = [ lib.maintainers.GaetanLepage ]; options = { services.autorandr = { - enable = mkEnableOption "" // { + enable = lib.mkEnableOption "" // { description = '' Whether to enable the Autorandr systemd service. This module is complementary to {option}`programs.autorandr` @@ -25,15 +20,15 @@ in ''; }; - ignoreLid = mkOption { + ignoreLid = lib.mkOption { default = false; - type = types.bool; + type = lib.types.bool; description = "Treat outputs as connected even if their lids are closed."; }; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.autorandr" pkgs lib.platforms.linux) ]; @@ -47,7 +42,7 @@ in Service = { Type = "oneshot"; - ExecStart = "${pkgs.autorandr}/bin/autorandr --change ${optionalString cfg.ignoreLid "--ignore-lid"}"; + ExecStart = "${pkgs.autorandr}/bin/autorandr --change ${lib.optionalString cfg.ignoreLid "--ignore-lid"}"; }; Install.WantedBy = [ "graphical-session.target" ]; diff --git a/modules/services/avizo.nix b/modules/services/avizo.nix index 88780a817..b4e46cb9c 100644 --- a/modules/services/avizo.nix +++ b/modules/services/avizo.nix @@ -4,23 +4,20 @@ pkgs, ... }: - -with lib; - let cfg = config.services.avizo; settingsFormat = pkgs.formats.ini { }; in { - meta.maintainers = [ hm.maintainers.pltanton ]; + meta.maintainers = [ lib.hm.maintainers.pltanton ]; options.services.avizo = { - enable = mkEnableOption "avizo, a simple notification daemon"; + enable = lib.mkEnableOption "avizo, a simple notification daemon"; - settings = mkOption { + settings = lib.mkOption { type = (pkgs.formats.ini { }).type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { default = { time = 1.0; @@ -36,11 +33,11 @@ in ''; }; - package = mkOption { - type = types.package; + package = lib.mkOption { + type = lib.types.package; default = pkgs.avizo; - defaultText = literalExpression "pkgs.avizo"; - example = literalExpression '' + defaultText = lib.literalExpression "pkgs.avizo"; + example = lib.literalExpression '' pkgs.avizo.overrideAttrs (final: prev: { patchPhase = "cp ''${./images}/*.png data/images/"; }) @@ -49,10 +46,12 @@ in }; }; - config = mkIf cfg.enable { - assertions = [ (hm.assertions.assertPlatform "services.avizo" pkgs platforms.linux) ]; + config = lib.mkIf cfg.enable { + assertions = [ + (lib.hm.assertions.assertPlatform "services.avizo" pkgs lib.platforms.linux) + ]; - xdg.configFile."avizo/config.ini" = mkIf (cfg.settings != { }) { + xdg.configFile."avizo/config.ini" = lib.mkIf (cfg.settings != { }) { source = settingsFormat.generate "avizo-config.ini" cfg.settings; }; diff --git a/modules/services/barrier.nix b/modules/services/barrier.nix index c182e4e90..582c33b0c 100644 --- a/modules/services/barrier.nix +++ b/modules/services/barrier.nix @@ -4,17 +4,22 @@ pkgs, ... }: - -with lib; let + inherit (lib) + mkEnableOption + mkOption + optional + types + ; + cfg = config.services.barrier; in { - meta.maintainers = with maintainers; [ kritnich ]; + meta.maintainers = with lib.maintainers; [ kritnich ]; imports = [ - (mkRemovedOptionModule [ "services" "barrier" "client" "tray" ] '' + (lib.mkRemovedOptionModule [ "services" "barrier" "client" "tray" ] '' The tray option is non-functional and has been removed. '') ]; @@ -51,7 +56,7 @@ in extraFlags = mkOption { type = types.listOf types.str; default = [ "-f" ]; - defaultText = literalExpression ''[ "-f" ]''; + defaultText = lib.literalExpression ''[ "-f" ]''; description = '' Additional flags to pass to {command}`barrierc`. See {command}`barrierc --help`. @@ -61,7 +66,7 @@ in }; }; - config = mkIf cfg.client.enable { + config = lib.mkIf cfg.client.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.barrier" pkgs lib.platforms.linux) ]; @@ -85,5 +90,4 @@ in ); }; }; - } diff --git a/modules/services/betterlockscreen.nix b/modules/services/betterlockscreen.nix index d3e7c28a8..0afe6eb6c 100644 --- a/modules/services/betterlockscreen.nix +++ b/modules/services/betterlockscreen.nix @@ -4,45 +4,40 @@ pkgs, ... }: - -with lib; - let cfg = config.services.betterlockscreen; - in { - meta.maintainers = with maintainers; [ sebtm ]; + meta.maintainers = with lib.maintainers; [ sebtm ]; options = { services.betterlockscreen = { - enable = mkEnableOption "betterlockscreen, a screen-locker module"; + enable = lib.mkEnableOption "betterlockscreen, a screen-locker module"; - package = mkOption { - type = types.package; + package = lib.mkOption { + type = lib.types.package; default = pkgs.betterlockscreen; - defaultText = literalExpression "pkgs.betterlockscreen"; + defaultText = lib.literalExpression "pkgs.betterlockscreen"; description = "Package providing {command}`betterlockscreen`."; }; - arguments = mkOption { - type = types.listOf types.str; + arguments = lib.mkOption { + type = lib.types.listOf lib.types.str; default = [ ]; description = "List of arguments appended to `./betterlockscreen --lock [args]`"; }; - inactiveInterval = mkOption { - type = types.int; + inactiveInterval = lib.mkOption { + type = lib.types.int; default = 10; description = '' Value used for {option}`services.screen-locker.inactiveInterval`. ''; }; - }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.betterlockscreen" pkgs lib.platforms.linux) ]; @@ -52,7 +47,7 @@ in services.screen-locker = { enable = true; inactiveInterval = cfg.inactiveInterval; - lockCmd = "${cfg.package}/bin/betterlockscreen --lock ${concatStringsSep " " cfg.arguments}"; + lockCmd = "${cfg.package}/bin/betterlockscreen --lock ${lib.concatStringsSep " " cfg.arguments}"; }; }; } diff --git a/modules/services/blueman-applet.nix b/modules/services/blueman-applet.nix index dd506c928..b6843d9cd 100644 --- a/modules/services/blueman-applet.nix +++ b/modules/services/blueman-applet.nix @@ -4,13 +4,10 @@ pkgs, ... }: - -with lib; - { options = { services.blueman-applet = { - enable = mkEnableOption "" // { + enable = lib.mkEnableOption "" // { description = '' Whether to enable the Blueman applet. @@ -25,9 +22,9 @@ with lib; }; }; - config = mkIf config.services.blueman-applet.enable { + config = lib.mkIf config.services.blueman-applet.enable { assertions = [ - (hm.assertions.assertPlatform "services.blueman-applet" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "services.blueman-applet" pkgs lib.platforms.linux) ]; systemd.user.services.blueman-applet = { diff --git a/modules/services/borgmatic.nix b/modules/services/borgmatic.nix index b074e392b..17dcf8cf3 100644 --- a/modules/services/borgmatic.nix +++ b/modules/services/borgmatic.nix @@ -4,22 +4,19 @@ pkgs, ... }: - -with lib; - let serviceConfig = config.services.borgmatic; programConfig = config.programs.borgmatic; in { - meta.maintainers = [ maintainers.DamienCassou ]; + meta.maintainers = [ lib.maintainers.DamienCassou ]; options = { services.borgmatic = { - enable = mkEnableOption "Borgmatic service"; + enable = lib.mkEnableOption "Borgmatic service"; - frequency = mkOption { - type = types.str; + frequency = lib.mkOption { + type = lib.types.str; default = "hourly"; description = '' How often to run borgmatic when @@ -33,7 +30,7 @@ in }; }; - config = mkIf serviceConfig.enable { + config = lib.mkIf serviceConfig.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.borgmatic" pkgs lib.platforms.linux) ]; diff --git a/modules/services/cachix-agent.nix b/modules/services/cachix-agent.nix index 98ff7d7f4..a97a57543 100644 --- a/modules/services/cachix-agent.nix +++ b/modules/services/cachix-agent.nix @@ -4,26 +4,24 @@ lib, ... }: - -with lib; - let + inherit (lib) mkOption optional types; cfg = config.services.cachix-agent; in { - meta.maintainers = [ maintainers.rycee ]; + meta.maintainers = [ lib.maintainers.rycee ]; options.services.cachix-agent = { - enable = mkEnableOption "Cachix Deploy Agent: "; + enable = lib.mkEnableOption "Cachix Deploy Agent: "; name = mkOption { type = types.str; description = "The unique agent name."; }; - verbose = mkEnableOption "verbose output"; + verbose = lib.mkEnableOption "verbose output"; profile = mkOption { type = types.str; @@ -39,12 +37,12 @@ in description = "Cachix URI to use."; }; - package = mkPackageOption pkgs "cachix" { }; + package = lib.mkPackageOption pkgs "cachix" { }; credentialsFile = mkOption { type = types.path; default = "${config.xdg.configHome}/cachix-agent.token"; - defaultText = literalExpression ''"''${config.xdg.configHome}/cachix-agent.token"''; + defaultText = lib.literalExpression ''"''${config.xdg.configHome}/cachix-agent.token"''; description = '' Required file that needs to contain `CACHIX_AGENT_TOKEN=...`. @@ -52,7 +50,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.cachix-agent" pkgs lib.platforms.linux) ]; @@ -71,7 +69,7 @@ in # We don't want to kill children processes as those are deployments. KillMode = "process"; Restart = "on-failure"; - ExecStart = escapeShellArgs ( + ExecStart = lib.escapeShellArgs ( [ "${cfg.package}/bin/cachix" ] ++ optional cfg.verbose "--verbose" ++ optional (cfg.host != null) "--host ${cfg.host}" diff --git a/modules/services/caffeine.nix b/modules/services/caffeine.nix index a90585569..b791ccc71 100644 --- a/modules/services/caffeine.nix +++ b/modules/services/caffeine.nix @@ -4,24 +4,19 @@ pkgs, ... }: - -with lib; - let - cfg = config.services.caffeine; - in { - meta.maintainers = [ maintainers.uvnikita ]; + meta.maintainers = [ lib.maintainers.uvnikita ]; options = { services.caffeine = { - enable = mkEnableOption "Caffeine service"; + enable = lib.mkEnableOption "Caffeine service"; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.caffeine" pkgs lib.platforms.linux) ]; diff --git a/modules/services/cbatticon.nix b/modules/services/cbatticon.nix index ab06b53a6..2f0a8d94e 100644 --- a/modules/services/cbatticon.nix +++ b/modules/services/cbatticon.nix @@ -4,10 +4,8 @@ pkgs, ... }: - -with lib; - let + inherit (lib) mkOption optional types; cfg = config.services.cbatticon; @@ -22,7 +20,7 @@ let "--${commandName} ${cmd}" ); - commandLine = concatStringsSep " " ( + commandLine = lib.concatStringsSep " " ( [ "${package}/bin/cbatticon" ] ++ makeCommand "command-critical-level" cfg.commandCriticalLevel ++ makeCommand "command-left-click" cfg.commandLeftClick @@ -40,11 +38,11 @@ let in { - meta.maintainers = [ maintainers.pmiddend ]; + meta.maintainers = [ lib.maintainers.pmiddend ]; options = { services.cbatticon = { - enable = mkEnableOption "cbatticon"; + enable = lib.mkEnableOption "cbatticon"; commandCriticalLevel = mkOption { type = types.nullOr types.lines; @@ -124,7 +122,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.cbatticon" pkgs lib.platforms.linux) ]; diff --git a/modules/services/clipman.nix b/modules/services/clipman.nix index faaa735ba..d61605b88 100644 --- a/modules/services/clipman.nix +++ b/modules/services/clipman.nix @@ -4,22 +4,21 @@ pkgs, ... }: -with lib; let cfg = config.services.clipman; in { - meta.maintainers = [ maintainers.jwygoda ]; + meta.maintainers = [ lib.maintainers.jwygoda ]; options.services.clipman = { - enable = mkEnableOption "clipman, a simple clipboard manager for Wayland"; + enable = lib.mkEnableOption "clipman, a simple clipboard manager for Wayland"; - package = mkPackageOption pkgs "clipman" { }; + package = lib.mkPackageOption pkgs "clipman" { }; - systemdTarget = mkOption { - type = types.str; + systemdTarget = lib.mkOption { + type = lib.types.str; default = config.wayland.systemd.target; - defaultText = literalExpression "config.wayland.systemd.target"; + defaultText = lib.literalExpression "config.wayland.systemd.target"; example = "sway-session.target"; description = '' The systemd target that will automatically start the clipman service. @@ -31,7 +30,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.clipman" pkgs lib.platforms.linux) ]; diff --git a/modules/services/clipmenu.nix b/modules/services/clipmenu.nix index 64604ab31..b786fc728 100644 --- a/modules/services/clipmenu.nix +++ b/modules/services/clipmenu.nix @@ -4,19 +4,16 @@ pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; cfg = config.services.clipmenu; - in { - meta.maintainers = [ maintainers.DamienCassou ]; + meta.maintainers = [ lib.maintainers.DamienCassou ]; options.services.clipmenu = { - enable = mkEnableOption "clipmenu, the clipboard management daemon"; + enable = lib.mkEnableOption "clipmenu, the clipboard management daemon"; package = mkOption { type = types.package; @@ -36,14 +33,14 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.clipmenu" pkgs lib.platforms.linux) ]; home.packages = [ cfg.package ]; - home.sessionVariables = mkIf (cfg.launcher != null) { CM_LAUNCHER = cfg.launcher; }; + home.sessionVariables = lib.mkIf (cfg.launcher != null) { CM_LAUNCHER = cfg.launcher; }; systemd.user.services.clipmenu = { Unit = { @@ -55,7 +52,7 @@ in ExecStart = "${cfg.package}/bin/clipmenud"; Environment = [ "PATH=${ - makeBinPath ( + lib.makeBinPath ( with pkgs; [ coreutils diff --git a/modules/services/conky.nix b/modules/services/conky.nix index 7eb83194b..a4066e486 100644 --- a/modules/services/conky.nix +++ b/modules/services/conky.nix @@ -10,18 +10,17 @@ let cfg = config.services.conky; in -with lib; { - meta.maintainers = [ hm.maintainers.kaleo ]; + meta.maintainers = [ lib.hm.maintainers.kaleo ]; options = { services.conky = { - enable = mkEnableOption "Conky, a light-weight system monitor"; + enable = lib.mkEnableOption "Conky, a light-weight system monitor"; - package = mkPackageOption pkgs "conky" { }; + package = lib.mkPackageOption pkgs "conky" { }; extraConfig = lib.mkOption { - type = types.lines; + type = lib.types.lines; default = ""; description = '' Configuration used by the Conky daemon. Check @@ -33,8 +32,8 @@ with lib; }; }; - config = mkIf cfg.enable { - assertions = [ (hm.assertions.assertPlatform "services.conky" pkgs platforms.linux) ]; + config = lib.mkIf cfg.enable { + assertions = [ (lib.hm.assertions.assertPlatform "services.conky" pkgs lib.platforms.linux) ]; home.packages = [ cfg.package ]; @@ -49,7 +48,7 @@ with lib; RestartSec = "3"; ExecStart = toString ( [ "${cfg.package}/bin/conky" ] - ++ optional (cfg.extraConfig != "") "--config ${pkgs.writeText "conky.conf" cfg.extraConfig}" + ++ lib.optional (cfg.extraConfig != "") "--config ${pkgs.writeText "conky.conf" cfg.extraConfig}" ); }; diff --git a/modules/services/darkman.nix b/modules/services/darkman.nix index ae37b0661..841dc4ed4 100644 --- a/modules/services/darkman.nix +++ b/modules/services/darkman.nix @@ -4,17 +4,16 @@ pkgs, ... }: - -with lib; - let + inherit (lib) mkIf types; + cfg = config.services.darkman; yamlFormat = pkgs.formats.yaml { }; scriptsOptionType = kind: - mkOption { + lib.mkOption { type = types.attrsOf ( types.oneOf [ types.path @@ -22,7 +21,7 @@ let ] ); default = { }; - example = literalExpression '' + example = lib.literalExpression '' { gtk-theme = ''' ''${pkgs.dconf}/bin/dconf write \ @@ -43,33 +42,33 @@ let generateScripts = folder: - mapAttrs' ( + lib.mapAttrs' ( k: v: { name = "${folder}/${k}"; value = { source = - if builtins.isPath v || isDerivation v then + if builtins.isPath v || lib.isDerivation v then v else - pkgs.writeShellScript (hm.strings.storeFileName k) v; + pkgs.writeShellScript (lib.hm.strings.storeFileName k) v; }; } ); in { - meta.maintainers = [ maintainers.xlambein ]; + meta.maintainers = [ lib.maintainers.xlambein ]; options.services.darkman = { - enable = mkEnableOption '' + enable = lib.mkEnableOption '' darkman, a tool that automatically switches dark-mode on and off based on the time of the day''; - package = mkPackageOption pkgs "darkman" { nullable = true; }; + package = lib.mkPackageOption pkgs "darkman" { nullable = true; }; - settings = mkOption { + settings = lib.mkOption { type = types.submodule { freeformType = yamlFormat.type; }; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { lat = 52.3; lng = 4.8; @@ -89,7 +88,7 @@ in config = mkIf cfg.enable { assertions = [ - (hm.assertions.assertPlatform "services.darkman" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "services.darkman" pkgs lib.platforms.linux) ]; home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; @@ -100,7 +99,7 @@ in }; }; - xdg.dataFile = mkMerge [ + xdg.dataFile = lib.mkMerge [ (mkIf (cfg.darkModeScripts != { }) (generateScripts "dark-mode.d" cfg.darkModeScripts)) (mkIf (cfg.lightModeScripts != { }) (generateScripts "light-mode.d" cfg.lightModeScripts)) ]; @@ -119,13 +118,13 @@ in Service = { Type = "dbus"; BusName = "nl.whynothugo.darkman"; - ExecStart = "${getExe cfg.package} run"; + ExecStart = "${lib.getExe cfg.package} run"; Restart = "on-failure"; TimeoutStopSec = 15; Slice = "background.slice"; }; - Install.WantedBy = mkDefault [ "graphical-session.target" ]; + Install.WantedBy = lib.mkDefault [ "graphical-session.target" ]; }; }; } diff --git a/modules/services/devilspie2.nix b/modules/services/devilspie2.nix index 66820733c..8c0a20604 100644 --- a/modules/services/devilspie2.nix +++ b/modules/services/devilspie2.nix @@ -4,22 +4,20 @@ pkgs, ... }: - -with lib; let cfg = config.services.devilspie2; in { - meta.maintainers = [ maintainers.dawidsowa ]; + meta.maintainers = [ lib.maintainers.dawidsowa ]; options = { services.devilspie2 = { - enable = mkEnableOption '' + enable = lib.mkEnableOption '' Devilspie2, a window matching utility, allowing the user to perform scripted actions on windows as they are created''; - config = mkOption { - type = types.lines; + config = lib.mkOption { + type = lib.types.lines; default = ""; description = '' Content of file placed in the devilspie2 config directory. @@ -33,7 +31,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.devilspie2" pkgs lib.platforms.linux) ]; diff --git a/modules/services/dropbox.nix b/modules/services/dropbox.nix index 063f5847b..d4891c90e 100644 --- a/modules/services/dropbox.nix +++ b/modules/services/dropbox.nix @@ -4,9 +4,6 @@ pkgs, ... }: - -with lib; - let cfg = config.services.dropbox; @@ -16,23 +13,23 @@ let in { - meta.maintainers = [ maintainers.eyjhb ]; + meta.maintainers = [ lib.maintainers.eyjhb ]; options = { services.dropbox = { - enable = mkEnableOption "Dropbox daemon"; + enable = lib.mkEnableOption "Dropbox daemon"; - path = mkOption { - type = types.path; + path = lib.mkOption { + type = lib.types.path; default = "${config.home.homeDirectory}/Dropbox"; - defaultText = literalExpression ''"''${config.home.homeDirectory}/Dropbox"''; + defaultText = lib.literalExpression ''"''${config.home.homeDirectory}/Dropbox"''; apply = toString; # Prevent copies to Nix store. description = "Where to put the Dropbox directory."; }; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.dropbox" pkgs lib.platforms.linux) ]; @@ -76,9 +73,9 @@ in ${homeBaseDir}/.dropbox ${config.home.homeDirectory}/.dropbox fi - if [[ ! -d ${escapeShellArg cfg.path} ]]; then + if [[ ! -d ${lib.escapeShellArg cfg.path} ]]; then run ${pkgs.coreutils}/bin/ln $VERBOSE_ARG -s \ - ${homeBaseDir}/Dropbox ${escapeShellArg cfg.path} + ${homeBaseDir}/Dropbox ${lib.escapeShellArg cfg.path} fi # get the dropbox bins if needed diff --git a/modules/services/dunst.nix b/modules/services/dunst.nix index e14e75188..8b37148aa 100644 --- a/modules/services/dunst.nix +++ b/modules/services/dunst.nix @@ -4,23 +4,26 @@ pkgs, ... }: - -with lib; - let + inherit (lib) + literalExpression + mkOption + optional + types + ; cfg = config.services.dunst; eitherStrBoolIntList = with types; either str (either bool (either int (listOf str))); - toDunstIni = generators.toINI { + toDunstIni = lib.generators.toINI { mkKeyValue = key: value: let value' = - if isBool value then + if lib.isBool value then (lib.hm.booleans.yesNo value) - else if isString value then + else if lib.isString value then ''"${value}"'' else toString value; @@ -59,11 +62,11 @@ let in { - meta.maintainers = [ maintainers.rycee ]; + meta.maintainers = [ lib.maintainers.rycee ]; options = { services.dunst = { - enable = mkEnableOption "the dunst notification daemon"; + enable = lib.mkEnableOption "the dunst notification daemon"; package = mkOption { type = types.package; @@ -133,96 +136,100 @@ in }; }; - config = mkIf cfg.enable (mkMerge [ - { - assertions = [ - (hm.assertions.assertPlatform "services.dunst" pkgs platforms.linux) - ]; + config = lib.mkIf cfg.enable ( + lib.mkMerge [ + { + assertions = [ + (lib.hm.assertions.assertPlatform "services.dunst" pkgs lib.platforms.linux) + ]; - home.packages = [ cfg.package ]; + home.packages = [ cfg.package ]; - xdg.dataFile."dbus-1/services/org.knopwob.dunst.service".source = - "${pkgs.dunst}/share/dbus-1/services/org.knopwob.dunst.service"; + xdg.dataFile."dbus-1/services/org.knopwob.dunst.service".source = + "${pkgs.dunst}/share/dbus-1/services/org.knopwob.dunst.service"; - services.dunst.settings.global.icon_path = - let - useCustomTheme = - cfg.iconTheme.package != hicolorTheme.package - || cfg.iconTheme.name != hicolorTheme.name - || cfg.iconTheme.size != hicolorTheme.size; + services.dunst.settings.global.icon_path = + let + useCustomTheme = + cfg.iconTheme.package != hicolorTheme.package + || cfg.iconTheme.name != hicolorTheme.name + || cfg.iconTheme.size != hicolorTheme.size; - basePaths = [ - "/run/current-system/sw" - config.home.profileDirectory - cfg.iconTheme.package - ] ++ optional useCustomTheme hicolorTheme.package; + basePaths = [ + "/run/current-system/sw" + config.home.profileDirectory + cfg.iconTheme.package + ] ++ optional useCustomTheme hicolorTheme.package; - themes = [ - cfg.iconTheme - ] ++ optional useCustomTheme (hicolorTheme // { size = cfg.iconTheme.size; }); + themes = [ + cfg.iconTheme + ] ++ optional useCustomTheme (hicolorTheme // { size = cfg.iconTheme.size; }); - categories = [ - "actions" - "animations" - "apps" - "categories" - "devices" - "emblems" - "emotes" - "filesystem" - "intl" - "legacy" - "mimetypes" - "places" - "status" - "stock" - ]; + categories = [ + "actions" + "animations" + "apps" + "categories" + "devices" + "emblems" + "emotes" + "filesystem" + "intl" + "legacy" + "mimetypes" + "places" + "status" + "stock" + ]; - mkPath = - { - basePath, - theme, - category, - }: - "${basePath}/share/icons/${theme.name}/${theme.size}/${category}"; - in - concatMapStringsSep ":" mkPath (cartesianProduct { - basePath = basePaths; - theme = themes; - category = categories; - }); - - systemd.user.services.dunst = { - Unit = { - Description = "Dunst notification daemon"; - After = [ config.wayland.systemd.target ]; - PartOf = [ config.wayland.systemd.target ]; - }; - - Service = { - Type = "dbus"; - BusName = "org.freedesktop.Notifications"; - ExecStart = escapeShellArgs ( - [ "${cfg.package}/bin/dunst" ] - ++ - # Using `-config` breaks dunst's drop-ins, so only use it when an alternative path is set - optionals (cfg.configFile != null) [ - "-config" - cfg.configFile - ] + mkPath = + { + basePath, + theme, + category, + }: + "${basePath}/share/icons/${theme.name}/${theme.size}/${category}"; + in + lib.concatMapStringsSep ":" mkPath ( + lib.cartesianProduct { + basePath = basePaths; + theme = themes; + category = categories; + } ); - Environment = optionalString (cfg.waylandDisplay != "") "WAYLAND_DISPLAY=${cfg.waylandDisplay}"; - }; - }; - } - (mkIf (cfg.settings != { }) { - xdg.configFile."dunst/dunstrc" = { - text = toDunstIni cfg.settings; - onChange = '' - ${pkgs.procps}/bin/pkill -u "$USER" ''${VERBOSE+-e} dunst || true - ''; - }; - }) - ]); + systemd.user.services.dunst = { + Unit = { + Description = "Dunst notification daemon"; + After = [ config.wayland.systemd.target ]; + PartOf = [ config.wayland.systemd.target ]; + }; + + Service = { + Type = "dbus"; + BusName = "org.freedesktop.Notifications"; + ExecStart = lib.escapeShellArgs ( + [ "${cfg.package}/bin/dunst" ] + ++ + # Using `-config` breaks dunst's drop-ins, so only use it when an alternative path is set + lib.optionals (cfg.configFile != null) [ + "-config" + cfg.configFile + ] + ); + Environment = lib.optionalString (cfg.waylandDisplay != "") "WAYLAND_DISPLAY=${cfg.waylandDisplay}"; + }; + }; + } + + (lib.mkIf (cfg.settings != { }) { + xdg.configFile."dunst/dunstrc" = { + text = toDunstIni cfg.settings; + onChange = '' + ${pkgs.procps}/bin/pkill -u "$USER" ''${VERBOSE+-e} dunst || true + ''; + }; + }) + ] + ); } diff --git a/modules/services/dwm-status.nix b/modules/services/dwm-status.nix index 7d92b77d6..b2b34936a 100644 --- a/modules/services/dwm-status.nix +++ b/modules/services/dwm-status.nix @@ -4,10 +4,9 @@ pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; + cfg = config.services.dwm-status; jsonFormat = pkgs.formats.json { }; @@ -31,12 +30,12 @@ in { options = { services.dwm-status = { - enable = mkEnableOption "dwm-status user service"; + enable = lib.mkEnableOption "dwm-status user service"; package = mkOption { type = types.package; default = pkgs.dwm-status; - defaultText = literalExpression "pkgs.dwm-status"; + defaultText = lib.literalExpression "pkgs.dwm-status"; example = "pkgs.dwm-status.override { enableAlsaUtils = false; }"; description = "Which dwm-status package to use."; }; @@ -49,7 +48,7 @@ in extraConfig = mkOption { type = jsonFormat.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { separator = "#"; @@ -67,7 +66,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.dwm-status" pkgs lib.platforms.linux) ]; diff --git a/modules/services/emacs.nix b/modules/services/emacs.nix index 3e6de937d..ec9258d1b 100644 --- a/modules/services/emacs.nix +++ b/modules/services/emacs.nix @@ -4,27 +4,31 @@ pkgs, ... }: - -with lib; - let + inherit (lib) + mkIf + mkOption + optional + optionalAttrs + types + ; cfg = config.services.emacs; emacsCfg = config.programs.emacs; emacsBinPath = "${cfg.package}/bin"; - emacsVersion = getVersion cfg.package; + emacsVersion = lib.getVersion cfg.package; - clientWMClass = if versionAtLeast emacsVersion "28" then "Emacsd" else "Emacs"; + clientWMClass = if lib.versionAtLeast emacsVersion "28" then "Emacsd" else "Emacs"; # Workaround for https://debbugs.gnu.org/47511 - needsSocketWorkaround = versionOlder emacsVersion "28" && cfg.socketActivation.enable; + needsSocketWorkaround = lib.versionOlder emacsVersion "28" && cfg.socketActivation.enable; # Adapted from upstream emacs.desktop clientDesktopItem = pkgs.writeTextDir "share/applications/emacsclient.desktop" ( - generators.toINI { } { + lib.generators.toINI { } { "Desktop Entry" = { Type = "Application"; - Exec = "${emacsBinPath}/emacsclient ${concatStringsSep " " cfg.client.arguments} %F"; + Exec = "${emacsBinPath}/emacsclient ${lib.concatStringsSep " " cfg.client.arguments} %F"; Terminal = false; Name = "Emacs Client"; Icon = "emacs"; @@ -44,15 +48,15 @@ let socketPath = "${socketDir}/server"; in { - meta.maintainers = [ maintainers.tadfisher ]; + meta.maintainers = [ lib.maintainers.tadfisher ]; options.services.emacs = { - enable = mkEnableOption "the Emacs daemon"; + enable = lib.mkEnableOption "the Emacs daemon"; package = mkOption { type = types.package; default = if emacsCfg.enable then emacsCfg.finalPackage else pkgs.emacs; - defaultText = literalExpression '' + defaultText = lib.literalExpression '' if config.programs.emacs.enable then config.programs.emacs.finalPackage else pkgs.emacs ''; @@ -72,7 +76,7 @@ in }; client = { - enable = mkEnableOption "generation of Emacs client desktop file"; + enable = lib.mkEnableOption "generation of Emacs client desktop file"; arguments = mkOption { type = with types; listOf str; default = [ "-c" ]; @@ -86,13 +90,13 @@ in # socket path, though allowing for such is not easy to do as systemd socket # units don't perform variable expansion for 'ListenStream'. socketActivation = { - enable = mkEnableOption "systemd socket activation for the Emacs service"; + enable = lib.mkEnableOption "systemd socket activation for the Emacs service"; }; startWithUserSession = mkOption { type = with types; either bool (enum [ "graphical" ]); default = !cfg.socketActivation.enable; - defaultText = literalExpression "!config.services.emacs.socketActivation.enable"; + defaultText = lib.literalExpression "!config.services.emacs.socketActivation.enable"; example = "graphical"; description = '' Whether to launch Emacs service with the systemd user session. If it is @@ -114,122 +118,124 @@ in }; }; - config = mkIf cfg.enable (mkMerge [ - (mkIf pkgs.stdenv.isLinux { - systemd.user.services.emacs = - { - Unit = - { - Description = "Emacs text editor"; - Documentation = "info:emacs man:emacs(1) https://gnu.org/software/emacs/"; + config = mkIf cfg.enable ( + lib.mkMerge [ + (mkIf pkgs.stdenv.isLinux { + systemd.user.services.emacs = + { + Unit = + { + Description = "Emacs text editor"; + Documentation = "info:emacs man:emacs(1) https://gnu.org/software/emacs/"; - After = optional (cfg.startWithUserSession == "graphical") "graphical-session.target"; - PartOf = optional (cfg.startWithUserSession == "graphical") "graphical-session.target"; + After = optional (cfg.startWithUserSession == "graphical") "graphical-session.target"; + PartOf = optional (cfg.startWithUserSession == "graphical") "graphical-session.target"; - # Avoid killing the Emacs session, which may be full of - # unsaved buffers. - X-RestartIfChanged = false; - } - // optionalAttrs needsSocketWorkaround { - # Emacs deletes its socket when shutting down, which systemd doesn't - # handle, resulting in a server without a socket. - # See https://github.com/nix-community/home-manager/issues/2018 - RefuseManualStart = true; + # Avoid killing the Emacs session, which may be full of + # unsaved buffers. + X-RestartIfChanged = false; + } + // optionalAttrs needsSocketWorkaround { + # Emacs deletes its socket when shutting down, which systemd doesn't + # handle, resulting in a server without a socket. + # See https://github.com/nix-community/home-manager/issues/2018 + RefuseManualStart = true; + }; + + Service = + { + Type = "notify"; + + # We wrap ExecStart in a login shell so Emacs starts with the user's + # environment, most importantly $PATH and $NIX_PROFILES. It may be + # worth investigating a more targeted approach for user services to + # import the user environment. + ExecStart = ''${pkgs.runtimeShell} -l -c "${emacsBinPath}/emacs --fg-daemon${ + # In case the user sets 'server-directory' or 'server-name' in + # their Emacs config, we want to specify the socket path explicitly + # so launching 'emacs.service' manually doesn't break emacsclient + # when using socket activation. + lib.optionalString cfg.socketActivation.enable "=${lib.escapeShellArg socketPath}" + } ${lib.escapeShellArgs cfg.extraOptions}"''; + + # Emacs will exit with status 15 after having received SIGTERM, which + # is the default "KillSignal" value systemd uses to stop services. + SuccessExitStatus = 15; + + Restart = "on-failure"; + } + // optionalAttrs needsSocketWorkaround { + # Use read-only directory permissions to prevent emacs from + # deleting systemd's socket file before exiting. + ExecStartPost = "${pkgs.coreutils}/bin/chmod --changes -w ${socketDir}"; + ExecStopPost = "${pkgs.coreutils}/bin/chmod --changes +w ${socketDir}"; + }; + } + // optionalAttrs (cfg.startWithUserSession != false) { + Install = { + WantedBy = [ + (if cfg.startWithUserSession == true then "default.target" else "graphical-session.target") + ]; }; + }; - Service = - { - Type = "notify"; + home = { + packages = optional cfg.client.enable (lib.hiPrio clientDesktopItem); - # We wrap ExecStart in a login shell so Emacs starts with the user's - # environment, most importantly $PATH and $NIX_PROFILES. It may be - # worth investigating a more targeted approach for user services to - # import the user environment. - ExecStart = ''${pkgs.runtimeShell} -l -c "${emacsBinPath}/emacs --fg-daemon${ - # In case the user sets 'server-directory' or 'server-name' in - # their Emacs config, we want to specify the socket path explicitly - # so launching 'emacs.service' manually doesn't break emacsclient - # when using socket activation. - optionalString cfg.socketActivation.enable "=${escapeShellArg socketPath}" - } ${escapeShellArgs cfg.extraOptions}"''; + sessionVariables = mkIf cfg.defaultEditor { + EDITOR = lib.getBin ( + pkgs.writeShellScript "editor" ''exec ${lib.getBin cfg.package}/bin/emacsclient "''${@:---create-frame}"'' + ); + }; + }; + }) - # Emacs will exit with status 15 after having received SIGTERM, which - # is the default "KillSignal" value systemd uses to stop services. - SuccessExitStatus = 15; + (mkIf (cfg.socketActivation.enable && pkgs.stdenv.isLinux) { + systemd.user.sockets.emacs = { + Unit = { + Description = "Emacs text editor"; + Documentation = "info:emacs man:emacs(1) https://gnu.org/software/emacs/"; + }; + + Socket = { + ListenStream = socketPath; + FileDescriptorName = "server"; + SocketMode = "0600"; + DirectoryMode = "0700"; + # This prevents the service from immediately starting again + # after being stopped, due to the function + # `server-force-stop' present in `kill-emacs-hook', which + # calls `server-running-p', which opens the socket file. + FlushPending = true; + }; - Restart = "on-failure"; - } - // optionalAttrs needsSocketWorkaround { - # Use read-only directory permissions to prevent emacs from - # deleting systemd's socket file before exiting. - ExecStartPost = "${pkgs.coreutils}/bin/chmod --changes -w ${socketDir}"; - ExecStopPost = "${pkgs.coreutils}/bin/chmod --changes +w ${socketDir}"; - }; - } - // optionalAttrs (cfg.startWithUserSession != false) { Install = { - WantedBy = [ - (if cfg.startWithUserSession == true then "default.target" else "graphical-session.target") - ]; + WantedBy = [ "sockets.target" ]; + # Adding this Requires= dependency ensures that systemd + # manages the socket file, in the case where the service is + # started when the socket is stopped. + # The socket unit is implicitly ordered before the service. + RequiredBy = [ "emacs.service" ]; }; }; + }) - home = { - packages = optional cfg.client.enable (hiPrio clientDesktopItem); - - sessionVariables = mkIf cfg.defaultEditor { - EDITOR = getBin ( - pkgs.writeShellScript "editor" ''exec ${getBin cfg.package}/bin/emacsclient "''${@:---create-frame}"'' - ); - }; - }; - }) - - (mkIf (cfg.socketActivation.enable && pkgs.stdenv.isLinux) { - systemd.user.sockets.emacs = { - Unit = { - Description = "Emacs text editor"; - Documentation = "info:emacs man:emacs(1) https://gnu.org/software/emacs/"; - }; - - Socket = { - ListenStream = socketPath; - FileDescriptorName = "server"; - SocketMode = "0600"; - DirectoryMode = "0700"; - # This prevents the service from immediately starting again - # after being stopped, due to the function - # `server-force-stop' present in `kill-emacs-hook', which - # calls `server-running-p', which opens the socket file. - FlushPending = true; - }; - - Install = { - WantedBy = [ "sockets.target" ]; - # Adding this Requires= dependency ensures that systemd - # manages the socket file, in the case where the service is - # started when the socket is stopped. - # The socket unit is implicitly ordered before the service. - RequiredBy = [ "emacs.service" ]; - }; - }; - }) - - (mkIf pkgs.stdenv.isDarwin { - launchd.agents.emacs = { - enable = true; - config = { - ProgramArguments = [ - "${cfg.package}/bin/emacs" - "--fg-daemon" - ] ++ cfg.extraOptions; - RunAtLoad = true; - KeepAlive = { - Crashed = true; - SuccessfulExit = false; + (mkIf pkgs.stdenv.isDarwin { + launchd.agents.emacs = { + enable = true; + config = { + ProgramArguments = [ + "${cfg.package}/bin/emacs" + "--fg-daemon" + ] ++ cfg.extraOptions; + RunAtLoad = true; + KeepAlive = { + Crashed = true; + SuccessfulExit = false; + }; }; }; - }; - }) - ]); + }) + ] + ); } diff --git a/modules/services/etesync-dav.nix b/modules/services/etesync-dav.nix index 6002e8482..0ef2565b5 100644 --- a/modules/services/etesync-dav.nix +++ b/modules/services/etesync-dav.nix @@ -4,22 +4,20 @@ pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; cfg = config.services.etesync-dav; toEnvironmentCfg = - vars: (concatStringsSep " " (mapAttrsToList (k: v: "${k}=${escapeShellArg v}") vars)); + vars: (lib.concatStringsSep " " (lib.mapAttrsToList (k: v: "${k}=${lib.escapeShellArg v}") vars)); in { - meta.maintainers = [ maintainers.valodim ]; + meta.maintainers = [ lib.maintainers.valodim ]; options.services.etesync-dav = { - enable = mkEnableOption "etesync-dav"; + enable = lib.mkEnableOption "etesync-dav"; package = mkOption { type = types.package; @@ -42,7 +40,7 @@ in ] ); default = { }; - example = literalExpression '' + example = lib.literalExpression '' { ETESYNC_LISTEN_ADDRESS = "localhost"; ETESYNC_LISTEN_PORT = 37358; @@ -54,7 +52,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.etesync-dav" pkgs lib.platforms.linux) ]; diff --git a/modules/services/flameshot.nix b/modules/services/flameshot.nix index 0c62a7c89..be4360445 100644 --- a/modules/services/flameshot.nix +++ b/modules/services/flameshot.nix @@ -4,9 +4,6 @@ pkgs, ... }: - -with lib; - let cfg = config.services.flameshot; @@ -17,19 +14,19 @@ let in { - meta.maintainers = [ maintainers.hamhut1066 ]; + meta.maintainers = [ lib.maintainers.hamhut1066 ]; options.services.flameshot = { - enable = mkEnableOption "Flameshot"; + enable = lib.mkEnableOption "Flameshot"; - package = mkOption { - type = types.package; + package = lib.mkOption { + type = lib.types.package; default = pkgs.flameshot; - defaultText = literalExpression "pkgs.flameshot"; + defaultText = lib.literalExpression "pkgs.flameshot"; description = "Package providing {command}`flameshot`."; }; - settings = mkOption { + settings = lib.mkOption { inherit (iniFormat) type; default = { }; example = { @@ -46,14 +43,14 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.flameshot" pkgs lib.platforms.linux) ]; home.packages = [ cfg.package ]; - xdg.configFile = mkIf (cfg.settings != { }) { + xdg.configFile = lib.mkIf (cfg.settings != { }) { "flameshot/flameshot.ini".source = iniFile; }; @@ -66,7 +63,7 @@ in "tray.target" ]; PartOf = [ "graphical-session.target" ]; - X-Restart-Triggers = mkIf (cfg.settings != { }) [ "${iniFile}" ]; + X-Restart-Triggers = lib.mkIf (cfg.settings != { }) [ "${iniFile}" ]; }; Install = { diff --git a/modules/services/fluidsynth.nix b/modules/services/fluidsynth.nix index 4594e60b3..2fe699c62 100644 --- a/modules/services/fluidsynth.nix +++ b/modules/services/fluidsynth.nix @@ -4,20 +4,18 @@ pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; cfg = config.services.fluidsynth; in { - meta.maintainers = [ maintainers.valodim ]; + meta.maintainers = [ lib.maintainers.valodim ]; options = { services.fluidsynth = { - enable = mkEnableOption "fluidsynth midi synthesizer"; + enable = lib.mkEnableOption "fluidsynth midi synthesizer"; soundFont = mkOption { type = types.path; @@ -52,7 +50,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.fluidsynth" pkgs lib.platforms.linux) ]; diff --git a/modules/services/fnott.nix b/modules/services/fnott.nix index 689a23b6a..91d1daf47 100644 --- a/modules/services/fnott.nix +++ b/modules/services/fnott.nix @@ -4,13 +4,12 @@ pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; + cfg = config.services.fnott; - concatStringsSep' = sep: list: concatStringsSep sep (remove "" list); + concatStringsSep' = sep: list: lib.concatStringsSep sep (lib.remove "" list); iniFormat = pkgs.formats.ini { }; in @@ -19,14 +18,14 @@ in options = { services.fnott = { - enable = mkEnableOption '' + enable = lib.mkEnableOption '' fnott, a lightweight Wayland notification daemon for wlroots-based compositors ''; package = mkOption { type = types.package; default = pkgs.fnott; - defaultText = literalExpression "pkgs.fnott"; + defaultText = lib.literalExpression "pkgs.fnott"; description = "Package providing {command}`fnott`."; }; @@ -67,7 +66,7 @@ in {manpage}`fnott.ini(5)` for a list of available options and for an example configuration. ''; - example = literalExpression '' + example = lib.literalExpression '' { main = { notification-margin = 5; @@ -84,8 +83,10 @@ in }; }; - config = mkIf cfg.enable { - assertions = [ (hm.assertions.assertPlatform "services.fnott" pkgs platforms.linux) ]; + config = lib.mkIf cfg.enable { + assertions = [ + (lib.hm.assertions.assertPlatform "services.fnott" pkgs lib.platforms.linux) + ]; home.packages = [ cfg.package ]; @@ -103,8 +104,8 @@ in BusName = "org.freedesktop.Notifications"; ExecStart = concatStringsSep' " " [ "${cfg.package}/bin/fnott" - "-c ${escapeShellArg cfg.configFile}" - (escapeShellArgs cfg.extraFlags) + "-c ${lib.escapeShellArg cfg.configFile}" + (lib.escapeShellArgs cfg.extraFlags) ]; }; }; diff --git a/modules/services/fusuma.nix b/modules/services/fusuma.nix index 917fa3570..435463018 100644 --- a/modules/services/fusuma.nix +++ b/modules/services/fusuma.nix @@ -4,10 +4,8 @@ pkgs, ... }: - -with lib; - let + inherit (lib) literalExpression mkOption types; cfg = config.services.fusuma; @@ -60,14 +58,15 @@ let }; makeBinPath = - packages: foldl (a: b: if a == "" then b else "${a}:${b}") "" (map (pkg: "${pkg}/bin") packages); + packages: + lib.foldl (a: b: if a == "" then b else "${a}:${b}") "" (map (pkg: "${pkg}/bin") packages); in { - meta.maintainers = [ hm.maintainers.iosmanthus ]; + meta.maintainers = [ lib.hm.maintainers.iosmanthus ]; options.services.fusuma = { - enable = mkEnableOption "the fusuma systemd service to automatically enable touchpad gesture"; + enable = lib.mkEnableOption "the fusuma systemd service to automatically enable touchpad gesture"; package = mkOption { type = types.package; @@ -118,7 +117,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.fusuma" pkgs lib.platforms.linux) ]; diff --git a/modules/services/getmail.nix b/modules/services/getmail.nix index 66f0825cf..880252bc3 100644 --- a/modules/services/getmail.nix +++ b/modules/services/getmail.nix @@ -4,26 +4,23 @@ pkgs, ... }: - -with lib; - let cfg = config.services.getmail; - accounts = filter (a: a.getmail.enable) (attrValues config.accounts.email.accounts); + accounts = lib.filter (a: a.getmail.enable) (lib.attrValues config.accounts.email.accounts); # Note: The getmail service does not expect a path, but just the filename! renderConfigFilepath = a: if a.primary then "getmailrc" else "getmail${a.name}"; - configFiles = concatMapStringsSep " " (a: " --rcfile ${renderConfigFilepath a}") accounts; + configFiles = lib.concatMapStringsSep " " (a: " --rcfile ${renderConfigFilepath a}") accounts; in { options = { services.getmail = { - enable = mkEnableOption "the getmail systemd service to automatically retrieve mail"; + enable = lib.mkEnableOption "the getmail systemd service to automatically retrieve mail"; - frequency = mkOption { - type = types.str; + frequency = lib.mkOption { + type = lib.types.str; default = "*:0/5"; example = "hourly"; description = '' @@ -38,7 +35,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.getmail" pkgs lib.platforms.linux) ]; diff --git a/modules/services/git-sync.nix b/modules/services/git-sync.nix index 321976a8f..860dda722 100644 --- a/modules/services/git-sync.nix +++ b/modules/services/git-sync.nix @@ -4,10 +4,14 @@ pkgs, ... }: - -with lib; - let + inherit (lib) + literalExpression + maintainers + mkIf + mkOption + types + ; cfg = config.services.git-sync; @@ -28,9 +32,9 @@ let ++ repo.extraPackages ) }" - "GIT_SYNC_DIRECTORY=${strings.escapeShellArg repo.path}" + "GIT_SYNC_DIRECTORY=${lib.strings.escapeShellArg repo.path}" "GIT_SYNC_COMMAND=${cfg.package}/bin/git-sync" - "GIT_SYNC_REPOSITORY=${strings.escapeShellArg repo.uri}" + "GIT_SYNC_REPOSITORY=${lib.strings.escapeShellArg repo.uri}" "GIT_SYNC_INTERVAL=${toString repo.interval}" ]; ExecStart = "${cfg.package}/bin/git-sync-on-inotify"; @@ -50,7 +54,7 @@ let }; mkService = if pkgs.stdenv.isLinux then mkUnit else mkAgent; - services = mapAttrs' (name: repo: { + services = lib.mapAttrs' (name: repo: { name = "git-sync-${name}"; value = mkService name repo; }) cfg.repositories; @@ -115,7 +119,7 @@ in options = { services.git-sync = { - enable = mkEnableOption "git-sync services"; + enable = lib.mkEnableOption "git-sync services"; package = mkOption { type = types.package; @@ -144,9 +148,11 @@ in }; }; - config = mkIf cfg.enable (mkMerge [ - (mkIf pkgs.stdenv.isLinux { systemd.user.services = services; }) - (mkIf pkgs.stdenv.isDarwin { launchd.agents = services; }) - ]); + config = mkIf cfg.enable ( + lib.mkMerge [ + (mkIf pkgs.stdenv.isLinux { systemd.user.services = services; }) + (mkIf pkgs.stdenv.isDarwin { launchd.agents = services; }) + ] + ); } diff --git a/modules/services/gnome-keyring.nix b/modules/services/gnome-keyring.nix index 2fe0cb8f0..55e813f0b 100644 --- a/modules/services/gnome-keyring.nix +++ b/modules/services/gnome-keyring.nix @@ -4,24 +4,21 @@ pkgs, ... }: - -with lib; - let cfg = config.services.gnome-keyring; in { - meta.maintainers = [ maintainers.rycee ]; + meta.maintainers = [ lib.maintainers.rycee ]; options = { services.gnome-keyring = { - enable = mkEnableOption "GNOME Keyring"; + enable = lib.mkEnableOption "GNOME Keyring"; - components = mkOption { - type = types.listOf ( - types.enum [ + components = lib.mkOption { + type = lib.types.listOf ( + lib.types.enum [ "pkcs11" "secrets" "ssh" @@ -36,7 +33,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.gnome-keyring" pkgs lib.platforms.linux) { @@ -58,12 +55,12 @@ in Service = { ExecStart = let - args = concatStringsSep " " ( + args = lib.concatStringsSep " " ( [ "--start" "--foreground" ] - ++ optional (cfg.components != [ ]) ("--components=" + concatStringsSep "," cfg.components) + ++ lib.optional (cfg.components != [ ]) ("--components=" + lib.concatStringsSep "," cfg.components) ); in "${pkgs.gnome-keyring}/bin/gnome-keyring-daemon ${args}"; diff --git a/modules/services/gpg-agent.nix b/modules/services/gpg-agent.nix index 1c68f7ca9..a703ad141 100644 --- a/modules/services/gpg-agent.nix +++ b/modules/services/gpg-agent.nix @@ -5,10 +5,14 @@ pkgs, ... }: - -with lib; - let + inherit (lib) + mkIf + mkOption + optional + optionalString + types + ; cfg = config.services.gpg-agent; gpgPkg = config.programs.gpg.package; @@ -55,7 +59,7 @@ let gpgconf = dir: let - hash = substring 0 24 (hexStringToBase32 (builtins.hashString "sha1" homedir)); + hash = lib.substring 0 24 (hexStringToBase32 (builtins.hashString "sha1" homedir)); subdir = if homedir == options.programs.gpg.homedir.default then "${dir}" else "d.${hash}/${dir}"; in if pkgs.stdenv.isDarwin then @@ -68,7 +72,7 @@ let hexStringToBase32 = let mod = a: b: a - a / b * b; - pow2 = elemAt [ + pow2 = lib.elemAt [ 1 2 4 @@ -80,10 +84,10 @@ let 256 ]; - base32Alphabet = stringToCharacters "ybndrfg8ejkmcpqxot1uwisza345h769"; - hexToIntTable = listToAttrs ( - genList (x: { - name = toLower (toHexString x); + base32Alphabet = lib.stringToCharacters "ybndrfg8ejkmcpqxot1uwisza345h769"; + hexToIntTable = lib.listToAttrs ( + lib.genList (x: { + name = lib.toLower (lib.toHexString x); value = x; }) 16 ); @@ -107,7 +111,7 @@ let in if bufBits >= 5 then { - ret = ret + elemAt base32Alphabet (buf' / pow2 extraBits); + ret = ret + lib.elemAt base32Alphabet (buf' / pow2 extraBits); buf = mod buf' (pow2 extraBits); bufBits = bufBits' - 5; } @@ -118,7 +122,7 @@ let bufBits = bufBits'; }; in - hexString: (foldl' go initState (stringToCharacters hexString)).ret; + hexString: (lib.foldl' go initState (lib.stringToCharacters hexString)).ret; # Systemd socket unit generator. mkSocket = @@ -156,10 +160,10 @@ let in { - meta.maintainers = [ maintainers.rycee ]; + meta.maintainers = [ lib.maintainers.rycee ]; imports = [ - (mkRemovedOptionModule [ + (lib.mkRemovedOptionModule [ "services" "gpg-agent" "pinentryFlavor" @@ -168,7 +172,7 @@ in options = { services.gpg-agent = { - enable = mkEnableOption "GnuPG private key agent"; + enable = lib.mkEnableOption "GnuPG private key agent"; defaultCacheTtl = mkOption { type = types.nullOr types.int; @@ -294,7 +298,7 @@ in }; pinentryPackage = mkOption { type = types.nullOr types.package; - example = literalExpression "pkgs.pinentry-gnome3"; + example = lib.literalExpression "pkgs.pinentry-gnome3"; default = null; description = '' Which pinentry interface to use. If not `null`, it sets @@ -317,109 +321,111 @@ in }; }; - config = mkIf cfg.enable (mkMerge [ - { - home.file."${homedir}/gpg-agent.conf".text = concatStringsSep "\n" ( - optional (cfg.enableSshSupport) "enable-ssh-support" - ++ optional cfg.grabKeyboardAndMouse "grab" - ++ optional (!cfg.enableScDaemon) "disable-scdaemon" - ++ optional (cfg.noAllowExternalCache) "no-allow-external-cache" - ++ optional (cfg.defaultCacheTtl != null) "default-cache-ttl ${toString cfg.defaultCacheTtl}" - ++ optional ( - cfg.defaultCacheTtlSsh != null - ) "default-cache-ttl-ssh ${toString cfg.defaultCacheTtlSsh}" - ++ optional (cfg.maxCacheTtl != null) "max-cache-ttl ${toString cfg.maxCacheTtl}" - ++ optional (cfg.maxCacheTtlSsh != null) "max-cache-ttl-ssh ${toString cfg.maxCacheTtlSsh}" - ++ optional (cfg.pinentryPackage != null) "pinentry-program ${lib.getExe cfg.pinentryPackage}" - ++ [ cfg.extraConfig ] - ); + config = mkIf cfg.enable ( + lib.mkMerge [ + { + home.file."${homedir}/gpg-agent.conf".text = lib.concatStringsSep "\n" ( + optional (cfg.enableSshSupport) "enable-ssh-support" + ++ optional cfg.grabKeyboardAndMouse "grab" + ++ optional (!cfg.enableScDaemon) "disable-scdaemon" + ++ optional (cfg.noAllowExternalCache) "no-allow-external-cache" + ++ optional (cfg.defaultCacheTtl != null) "default-cache-ttl ${toString cfg.defaultCacheTtl}" + ++ optional ( + cfg.defaultCacheTtlSsh != null + ) "default-cache-ttl-ssh ${toString cfg.defaultCacheTtlSsh}" + ++ optional (cfg.maxCacheTtl != null) "max-cache-ttl ${toString cfg.maxCacheTtl}" + ++ optional (cfg.maxCacheTtlSsh != null) "max-cache-ttl-ssh ${toString cfg.maxCacheTtlSsh}" + ++ optional (cfg.pinentryPackage != null) "pinentry-program ${lib.getExe cfg.pinentryPackage}" + ++ [ cfg.extraConfig ] + ); - home.sessionVariablesExtra = optionalString cfg.enableSshSupport '' - if [ -z "$SSH_AUTH_SOCK" ]; then - export SSH_AUTH_SOCK="$(${gpgPkg}/bin/gpgconf --list-dirs agent-ssh-socket)" - fi - ''; + home.sessionVariablesExtra = optionalString cfg.enableSshSupport '' + if [ -z "$SSH_AUTH_SOCK" ]; then + export SSH_AUTH_SOCK="$(${gpgPkg}/bin/gpgconf --list-dirs agent-ssh-socket)" + fi + ''; - programs.bash.initExtra = mkIf cfg.enableBashIntegration gpgInitStr; - programs.zsh.initContent = mkIf cfg.enableZshIntegration gpgZshInitStr; - programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration gpgFishInitStr; + programs.bash.initExtra = mkIf cfg.enableBashIntegration gpgInitStr; + programs.zsh.initContent = mkIf cfg.enableZshIntegration gpgZshInitStr; + programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration gpgFishInitStr; - programs.nushell.extraEnv = mkIf cfg.enableNushellIntegration gpgNushellInitStr; - } + programs.nushell.extraEnv = mkIf cfg.enableNushellIntegration gpgNushellInitStr; + } - (mkIf (cfg.sshKeys != null) { - # Trailing newlines are important - home.file."${homedir}/sshcontrol".text = concatMapStrings (s: '' - ${s} - '') cfg.sshKeys; - }) - - (mkMerge [ - (mkIf pkgs.stdenv.isLinux { - systemd.user.services.gpg-agent = { - Unit = { - Description = "GnuPG cryptographic agent and passphrase cache"; - Documentation = "man:gpg-agent(1)"; - Requires = "gpg-agent.socket"; - After = "gpg-agent.socket"; - # This is a socket-activated service: - RefuseManualStart = true; - }; - - Service = { - ExecStart = "${gpgPkg}/bin/gpg-agent --supervised" + optionalString cfg.verbose " --verbose"; - ExecReload = "${gpgPkg}/bin/gpgconf --reload gpg-agent"; - Environment = [ "GNUPGHOME=${homedir}" ]; - }; - }; - - systemd.user.sockets.gpg-agent = mkSocket { - desc = "GnuPG cryptographic agent and passphrase cache"; - docs = "man:gpg-agent(1)"; - stream = "S.gpg-agent"; - fdName = "std"; - }; - - systemd.user.sockets.gpg-agent-ssh = mkIf cfg.enableSshSupport (mkSocket ({ - desc = "GnuPG cryptographic agent (ssh-agent emulation)"; - docs = "man:gpg-agent(1) man:ssh-add(1) man:ssh-agent(1) man:ssh(1)"; - stream = "S.gpg-agent.ssh"; - fdName = "ssh"; - })); - - systemd.user.sockets.gpg-agent-extra = mkIf cfg.enableExtraSocket (mkSocket { - desc = "GnuPG cryptographic agent and passphrase cache (restricted)"; - docs = "man:gpg-agent(1) man:ssh(1)"; - stream = "S.gpg-agent.extra"; - fdName = "extra"; - }); + (mkIf (cfg.sshKeys != null) { + # Trailing newlines are important + home.file."${homedir}/sshcontrol".text = lib.concatMapStrings (s: '' + ${s} + '') cfg.sshKeys; }) - (mkIf pkgs.stdenv.isDarwin { - launchd.agents.gpg-agent = { - enable = true; - config = { - ProgramArguments = [ - "${gpgPkg}/bin/gpg-agent" - "--supervised" - ] ++ optional cfg.verbose "--verbose"; - EnvironmentVariables = { - GNUPGHOME = homedir; + (lib.mkMerge [ + (mkIf pkgs.stdenv.isLinux { + systemd.user.services.gpg-agent = { + Unit = { + Description = "GnuPG cryptographic agent and passphrase cache"; + Documentation = "man:gpg-agent(1)"; + Requires = "gpg-agent.socket"; + After = "gpg-agent.socket"; + # This is a socket-activated service: + RefuseManualStart = true; }; - KeepAlive = { - Crashed = true; - SuccessfulExit = false; - }; - ProcessType = "Background"; - RunAtLoad = cfg.enableSshSupport; - Sockets = { - Agent = mkAgentSock "S.gpg-agent"; - Ssh = mkIf cfg.enableSshSupport (mkAgentSock "S.gpg-agent.ssh"); - Extra = mkIf cfg.enableExtraSocket (mkAgentSock "S.gpg-agent.extra"); + + Service = { + ExecStart = "${gpgPkg}/bin/gpg-agent --supervised" + optionalString cfg.verbose " --verbose"; + ExecReload = "${gpgPkg}/bin/gpgconf --reload gpg-agent"; + Environment = [ "GNUPGHOME=${homedir}" ]; }; }; - }; - }) - ]) - ]); + + systemd.user.sockets.gpg-agent = mkSocket { + desc = "GnuPG cryptographic agent and passphrase cache"; + docs = "man:gpg-agent(1)"; + stream = "S.gpg-agent"; + fdName = "std"; + }; + + systemd.user.sockets.gpg-agent-ssh = mkIf cfg.enableSshSupport (mkSocket { + desc = "GnuPG cryptographic agent (ssh-agent emulation)"; + docs = "man:gpg-agent(1) man:ssh-add(1) man:ssh-agent(1) man:ssh(1)"; + stream = "S.gpg-agent.ssh"; + fdName = "ssh"; + }); + + systemd.user.sockets.gpg-agent-extra = mkIf cfg.enableExtraSocket (mkSocket { + desc = "GnuPG cryptographic agent and passphrase cache (restricted)"; + docs = "man:gpg-agent(1) man:ssh(1)"; + stream = "S.gpg-agent.extra"; + fdName = "extra"; + }); + }) + + (mkIf pkgs.stdenv.isDarwin { + launchd.agents.gpg-agent = { + enable = true; + config = { + ProgramArguments = [ + "${gpgPkg}/bin/gpg-agent" + "--supervised" + ] ++ optional cfg.verbose "--verbose"; + EnvironmentVariables = { + GNUPGHOME = homedir; + }; + KeepAlive = { + Crashed = true; + SuccessfulExit = false; + }; + ProcessType = "Background"; + RunAtLoad = cfg.enableSshSupport; + Sockets = { + Agent = mkAgentSock "S.gpg-agent"; + Ssh = mkIf cfg.enableSshSupport (mkAgentSock "S.gpg-agent.ssh"); + Extra = mkIf cfg.enableExtraSocket (mkAgentSock "S.gpg-agent.extra"); + }; + }; + }; + }) + ]) + ] + ); } diff --git a/modules/services/grobi.nix b/modules/services/grobi.nix index 853c0686a..ce40b2111 100644 --- a/modules/services/grobi.nix +++ b/modules/services/grobi.nix @@ -4,10 +4,8 @@ pkgs, ... }: - -with lib; - let + inherit (lib) mkOption mkIf types; cfg = config.services.grobi; @@ -15,11 +13,11 @@ let in { - meta.maintainers = [ maintainers.mbrgm ]; + meta.maintainers = [ lib.maintainers.mbrgm ]; options = { services.grobi = { - enable = mkEnableOption "the grobi display setup daemon"; + enable = lib.mkEnableOption "the grobi display setup daemon"; executeAfter = mkOption { type = with types; listOf str; @@ -36,7 +34,7 @@ in rules = mkOption { type = with types; listOf (attrsOf eitherStrBoolIntList); default = [ ]; - example = literalExpression '' + example = lib.literalExpression '' [ { name = "Home"; diff --git a/modules/services/gromit-mpx.nix b/modules/services/gromit-mpx.nix index 928ec691c..64486518b 100644 --- a/modules/services/gromit-mpx.nix +++ b/modules/services/gromit-mpx.nix @@ -4,16 +4,14 @@ pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; cfg = config.services.gromit-mpx; # Select the appropriate hot key: hotkey = - if isInt cfg.hotKey then + if lib.isInt cfg.hotKey then "--keycode ${toString cfg.hotKey}" else if cfg.hotKey != null then "--key ${cfg.hotKey}" @@ -22,7 +20,7 @@ let # Select the appropriate undo key: undokey = - if isInt cfg.undoKey then + if lib.isInt cfg.undoKey then "--undo-keycode ${toString cfg.undoKey}" else if cfg.undoKey != null then "--undo-key ${cfg.undoKey}" @@ -30,7 +28,7 @@ let "--undo-key none"; # The command line to send to gromit-mpx: - commandArgs = concatStringsSep " " [ + commandArgs = lib.concatStringsSep " " [ hotkey undokey ]; @@ -39,7 +37,7 @@ let # state. That will break our config so we set it manually which, # thanks to the read-only Nix store, prevents Gromit from writing to # it. - keyFile = generators.toINI { } { + keyFile = lib.generators.toINI { } { General.ShowIntroOnStartup = false; Drawing.Opacity = cfg.opacity; }; @@ -60,19 +58,19 @@ let # Create a string of tool attributes: toolAttrs = tool: - concatStringsSep " " ( + lib.concatStringsSep " " ( [ "size=${toString tool.size}" ] - ++ optional (tool.type != "eraser") ''color="${tool.color}"'' - ++ optional (tool.arrowSize != null) "arrowsize=${toString tool.arrowSize}" + ++ lib.optional (tool.type != "eraser") ''color="${tool.color}"'' + ++ lib.optional (tool.arrowSize != null) "arrowsize=${toString tool.arrowSize}" ); # Optional tool modifier string: toolMod = - tool: if tool.modifiers != [ ] then "[" + concatStringsSep ", " tool.modifiers + "]" else ""; + tool: if tool.modifiers != [ ] then "[" + lib.concatStringsSep ", " tool.modifiers + "]" else ""; # A single tool configuration: toolToCfg = n: tool: '' - "tool-${toString n}" = ${toUpper tool.type} (${toolAttrs tool}); + "tool-${toString n}" = ${lib.toUpper tool.type} (${toolAttrs tool}); "${tool.device}"${toolMod tool} = "tool-${toString n}"; ''; @@ -136,10 +134,10 @@ let in { - meta.maintainers = [ maintainers.pjones ]; + meta.maintainers = [ lib.maintainers.pjones ]; options.services.gromit-mpx = { - enable = mkEnableOption "Gromit-MPX annotation tool"; + enable = lib.mkEnableOption "Gromit-MPX annotation tool"; package = mkOption { type = types.package; @@ -224,13 +222,13 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.gromit-mpx" pkgs lib.platforms.linux) ]; xdg.configFile."gromit-mpx.ini".text = keyFile; - xdg.configFile."gromit-mpx.cfg".text = concatStringsSep "\n" (imap1 toolToCfg cfg.tools); + xdg.configFile."gromit-mpx.cfg".text = lib.concatStringsSep "\n" (lib.imap1 toolToCfg cfg.tools); home.packages = [ cfg.package ]; diff --git a/modules/services/hound.nix b/modules/services/hound.nix index 3c4a7a619..5b061bfcf 100644 --- a/modules/services/hound.nix +++ b/modules/services/hound.nix @@ -4,10 +4,8 @@ pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; cfg = config.services.hound; @@ -27,10 +25,10 @@ let in { - meta.maintainers = [ maintainers.adisbladis ]; + meta.maintainers = [ lib.maintainers.adisbladis ]; options.services.hound = { - enable = mkEnableOption "hound"; + enable = lib.mkEnableOption "hound"; maxConcurrentIndexers = mkOption { type = types.ints.positive; @@ -54,7 +52,7 @@ in repositories = mkOption { type = types.attrsOf jsonFormat.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { SomeGitRepo = { url = "https://www.github.com/YourOrganization/RepoOne.git"; @@ -67,7 +65,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.hound" pkgs lib.platforms.linux) ]; @@ -86,13 +84,13 @@ in Service = { Environment = [ "PATH=${ - makeBinPath [ + lib.makeBinPath [ pkgs.mercurial pkgs.git ] }" ]; - ExecStart = "${pkgs.hound}/bin/houndd ${concatStringsSep " " houndOptions}"; + ExecStart = "${pkgs.hound}/bin/houndd ${lib.concatStringsSep " " houndOptions}"; }; }; }; diff --git a/modules/services/imapnotify.nix b/modules/services/imapnotify.nix index 07c366fe7..295196460 100644 --- a/modules/services/imapnotify.nix +++ b/modules/services/imapnotify.nix @@ -4,10 +4,13 @@ pkgs, ... }: - -with lib; - let + inherit (lib) + mkOption + types + listToAttrs + optionalAttrs + ; cfg = config.services.imapnotify; @@ -15,7 +18,9 @@ let configName = account: "imapnotify-${safeName account.name}-config.json"; - imapnotifyAccounts = filter (a: a.imapnotify.enable) (attrValues config.accounts.email.accounts); + imapnotifyAccounts = lib.filter (a: a.imapnotify.enable) ( + lib.attrValues config.accounts.email.accounts + ); genAccountUnit = account: @@ -32,7 +37,7 @@ let Service = { # Use the nix store path for config to ensure service restarts when it changes ExecStart = - "${getExe cfg.package} -conf '${genAccountConfig account}'" + "${lib.getExe cfg.package} -conf '${genAccountConfig account}'" + " ${lib.optionalString (account.imapnotify.extraArgs != [ ]) ( toString account.imapnotify.extraArgs )}"; @@ -41,7 +46,7 @@ let Type = "simple"; Environment = [ "PATH=${cfg.path}" ] - ++ optional account.notmuch.enable "NOTMUCH_CONFIG=${config.xdg.configHome}/notmuch/default/config"; + ++ lib.optional account.notmuch.enable "NOTMUCH_CONFIG=${config.xdg.configHome}/notmuch/default/config"; }; Install = { @@ -63,7 +68,7 @@ let { # Use the nix store path for config to ensure service restarts when it changes ProgramArguments = [ - "${getExe cfg.package}" + "${lib.getExe cfg.package}" "-conf" "${genAccountConfig account}" ]; @@ -115,17 +120,17 @@ let in { - meta.maintainers = [ maintainers.nickhu ]; + meta.maintainers = [ lib.maintainers.nickhu ]; options = { services.imapnotify = { - enable = mkEnableOption "imapnotify"; + enable = lib.mkEnableOption "imapnotify"; package = mkOption { type = types.package; default = pkgs.goimapnotify; - defaultText = literalExpression "pkgs.goimapnotify"; - example = literalExpression "pkgs.imapnotify"; + defaultText = lib.literalExpression "pkgs.goimapnotify"; + example = lib.literalExpression "pkgs.imapnotify"; description = "The imapnotify package to use"; }; @@ -146,18 +151,18 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = let checkAccounts = pred: msg: let - badAccounts = filter pred imapnotifyAccounts; + badAccounts = lib.filter pred imapnotifyAccounts; in { assertion = badAccounts == [ ]; message = - "imapnotify: Missing ${msg} for accounts: " + concatMapStringsSep ", " (a: a.name) badAccounts; + "imapnotify: Missing ${msg} for accounts: " + lib.concatMapStringsSep ", " (a: a.name) badAccounts; }; in [ diff --git a/modules/services/kanshi.nix b/modules/services/kanshi.nix index 3c94f20ed..06d67f8fa 100644 --- a/modules/services/kanshi.nix +++ b/modules/services/kanshi.nix @@ -4,10 +4,15 @@ pkgs, ... }: - -with lib; - let + inherit (lib) + concatStringsSep + literalExpression + mkIf + mkOption + optionalString + types + ; cfg = config.services.kanshi; @@ -42,12 +47,12 @@ let else if x ? include then ''include "${x.include}"'' else - throw "Unknown tags ${attrNames x}"; + throw "Unknown tags ${lib.attrNames x}"; directivesStr = concatStringsSep "\n" (map tagToStr cfg.settings); oldDirectivesStr = '' - ${concatStringsSep "\n" (mapAttrsToList (n: v: profileStr (v // { name = n; })) cfg.profiles)} + ${concatStringsSep "\n" (lib.mapAttrsToList (n: v: profileStr (v // { name = n; })) cfg.profiles)} ${cfg.extraConfig} ''; @@ -194,7 +199,7 @@ let }; exec = mkOption { - type = with types; coercedTo str singleton (listOf str); + type = with types; coercedTo str lib.singleton (listOf str); default = [ ]; example = "[ \${pkg.sway}/bin/swaymsg workspace 1, move workspace to eDP-1 ]"; description = '' @@ -216,10 +221,10 @@ let in { - meta.maintainers = [ hm.maintainers.nurelin ]; + meta.maintainers = [ lib.hm.maintainers.nurelin ]; options.services.kanshi = { - enable = mkEnableOption "kanshi, a Wayland daemon that automatically configures outputs"; + enable = lib.mkEnableOption "kanshi, a Wayland daemon that automatically configures outputs"; package = mkOption { type = types.package; @@ -314,67 +319,70 @@ in }; }; - config = mkIf cfg.enable (mkMerge [ - { - assertions = [ - (lib.hm.assertions.assertPlatform "services.kanshi" pkgs lib.platforms.linux) - { - assertion = (cfg.profiles == { } && cfg.extraConfig == "") || (length cfg.settings) == 0; - message = "Cannot mix kanshi.settings with kanshi.profiles or kanshi.extraConfig"; - } - { - assertion = - let - profiles = filter (x: x ? profile) cfg.settings; - in - length (filter (x: any (a: a ? alias && a.alias != null) x.profile.outputs) profiles) == 0; - message = "Output kanshi.*.output.alias can only be defined on global scope"; - } - ]; - } + config = mkIf cfg.enable ( + lib.mkMerge [ + { + assertions = [ + (lib.hm.assertions.assertPlatform "services.kanshi" pkgs lib.platforms.linux) + { + assertion = (cfg.profiles == { } && cfg.extraConfig == "") || (lib.length cfg.settings) == 0; + message = "Cannot mix kanshi.settings with kanshi.profiles or kanshi.extraConfig"; + } + { + assertion = + let + profiles = lib.filter (x: x ? profile) cfg.settings; + in + lib.length (lib.filter (x: lib.any (a: a ? alias && a.alias != null) x.profile.outputs) profiles) + == 0; + message = "Output kanshi.*.output.alias can only be defined on global scope"; + } + ]; + } - (mkIf (cfg.profiles != { }) { - warnings = [ - "kanshi.profiles option is deprecated. Use kanshi.settings instead." - ]; - }) + (mkIf (cfg.profiles != { }) { + warnings = [ + "kanshi.profiles option is deprecated. Use kanshi.settings instead." + ]; + }) - (mkIf (cfg.extraConfig != "") { - warnings = [ - "kanshi.extraConfig option is deprecated. Use kanshi.settings instead." - ]; - }) + (mkIf (cfg.extraConfig != "") { + warnings = [ + "kanshi.extraConfig option is deprecated. Use kanshi.settings instead." + ]; + }) - { - home.packages = [ cfg.package ]; + { + home.packages = [ cfg.package ]; - xdg.configFile."kanshi/config" = - let - generatedConfigStr = - if cfg.profiles == { } && cfg.extraConfig == "" then directivesStr else oldDirectivesStr; - in - mkIf (generatedConfigStr != "") { text = generatedConfigStr; }; + xdg.configFile."kanshi/config" = + let + generatedConfigStr = + if cfg.profiles == { } && cfg.extraConfig == "" then directivesStr else oldDirectivesStr; + in + mkIf (generatedConfigStr != "") { text = generatedConfigStr; }; - systemd.user.services.kanshi = { - Unit = { - Description = "Dynamic output configuration"; - Documentation = "man:kanshi(1)"; - ConditionEnvironment = "WAYLAND_DISPLAY"; - PartOf = cfg.systemdTarget; - Requires = cfg.systemdTarget; - After = cfg.systemdTarget; + systemd.user.services.kanshi = { + Unit = { + Description = "Dynamic output configuration"; + Documentation = "man:kanshi(1)"; + ConditionEnvironment = "WAYLAND_DISPLAY"; + PartOf = cfg.systemdTarget; + Requires = cfg.systemdTarget; + After = cfg.systemdTarget; + }; + + Service = { + Type = "simple"; + ExecStart = "${cfg.package}/bin/kanshi"; + Restart = "always"; + }; + + Install = { + WantedBy = [ cfg.systemdTarget ]; + }; }; - - Service = { - Type = "simple"; - ExecStart = "${cfg.package}/bin/kanshi"; - Restart = "always"; - }; - - Install = { - WantedBy = [ cfg.systemdTarget ]; - }; - }; - } - ]); + } + ] + ); } diff --git a/modules/services/kbfs.nix b/modules/services/kbfs.nix index 85de4a7f1..27883ae75 100644 --- a/modules/services/kbfs.nix +++ b/modules/services/kbfs.nix @@ -4,9 +4,6 @@ pkgs, ... }: - -with lib; - let cfg = config.services.kbfs; @@ -15,10 +12,10 @@ in { options = { services.kbfs = { - enable = mkEnableOption "Keybase File System"; + enable = lib.mkEnableOption "Keybase File System"; - mountPoint = mkOption { - type = types.str; + mountPoint = lib.mkOption { + type = lib.types.str; default = "keybase"; description = '' Mount point for the Keybase filesystem, relative to @@ -26,8 +23,8 @@ in ''; }; - extraFlags = mkOption { - type = types.listOf types.str; + extraFlags = lib.mkOption { + type = lib.types.listOf lib.types.str; default = [ ]; example = [ "-label kbfs" @@ -40,7 +37,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.kbfs" pkgs lib.platforms.linux) ]; diff --git a/modules/services/kdeconnect.nix b/modules/services/kdeconnect.nix index ba224ddaa..6b043f532 100644 --- a/modules/services/kdeconnect.nix +++ b/modules/services/kdeconnect.nix @@ -4,41 +4,38 @@ pkgs, ... }: - -with lib; - let cfg = config.services.kdeconnect; in { - meta.maintainers = [ maintainers.adisbladis ]; + meta.maintainers = [ lib.maintainers.adisbladis ]; options = { services.kdeconnect = { - enable = mkEnableOption "KDE connect"; - package = mkOption { - type = types.package; + enable = lib.mkEnableOption "KDE connect"; + package = lib.mkOption { + type = lib.types.package; default = pkgs.kdePackages.kdeconnect-kde; - example = literalExpression "pkgs.plasma5Packages.kdeconnect-kde"; + example = lib.literalExpression "pkgs.plasma5Packages.kdeconnect-kde"; description = "The KDE connect package to use"; }; - indicator = mkOption { - type = types.bool; + indicator = lib.mkOption { + type = lib.types.bool; default = false; description = "Whether to enable kdeconnect-indicator service."; }; }; }; - config = mkMerge [ - (mkIf cfg.enable { + config = lib.mkMerge [ + (lib.mkIf cfg.enable { home.packages = [ cfg.package ]; assertions = [ - (hm.assertions.assertPlatform "services.kdeconnect" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "services.kdeconnect" pkgs lib.platforms.linux) ]; systemd.user.services.kdeconnect = { @@ -55,7 +52,7 @@ in Service = { Environment = [ "PATH=${config.home.profileDirectory}/bin" ]; ExecStart = - if strings.versionAtLeast (versions.majorMinor cfg.package.version) "24.05" then + if lib.strings.versionAtLeast (lib.versions.majorMinor cfg.package.version) "24.05" then "${cfg.package}/bin/kdeconnectd" else "${cfg.package}/libexec/kdeconnectd"; @@ -64,9 +61,9 @@ in }; }) - (mkIf cfg.indicator { + (lib.mkIf cfg.indicator { assertions = [ - (hm.assertions.assertPlatform "services.kdeconnect" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "services.kdeconnect" pkgs lib.platforms.linux) ]; systemd.user.services.kdeconnect-indicator = { diff --git a/modules/services/keybase.nix b/modules/services/keybase.nix index 75c142f6f..bd5754646 100644 --- a/modules/services/keybase.nix +++ b/modules/services/keybase.nix @@ -4,18 +4,15 @@ pkgs, ... }: - -with lib; - let cfg = config.services.keybase; in { - options.services.keybase.enable = mkEnableOption "Keybase"; + options.services.keybase.enable = lib.mkEnableOption "Keybase"; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.keybase" pkgs lib.platforms.linux) ]; diff --git a/modules/services/keynav.nix b/modules/services/keynav.nix index 43b280427..406bce1e9 100644 --- a/modules/services/keynav.nix +++ b/modules/services/keynav.nix @@ -4,9 +4,6 @@ pkgs, ... }: - -with lib; - let cfg = config.services.keynav; @@ -14,10 +11,10 @@ let in { options.services.keynav = { - enable = mkEnableOption "keynav"; + enable = lib.mkEnableOption "keynav"; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.keynav" pkgs lib.platforms.linux) ]; diff --git a/modules/services/lieer.nix b/modules/services/lieer.nix index 2a3b3a5a5..53fffd23c 100644 --- a/modules/services/lieer.nix +++ b/modules/services/lieer.nix @@ -4,23 +4,20 @@ pkgs, ... }: - -with lib; - let cfg = config.services.lieer; - syncAccounts = filter (a: a.lieer.enable && a.lieer.sync.enable) ( - attrValues config.accounts.email.accounts + syncAccounts = lib.filter (a: a.lieer.enable && a.lieer.sync.enable) ( + lib.attrValues config.accounts.email.accounts ); escapeUnitName = name: let - good = upperChars ++ lowerChars ++ stringToCharacters "0123456789-_"; - subst = c: if any (x: x == c) good then c else "-"; + good = lib.upperChars ++ lib.lowerChars ++ lib.stringToCharacters "0123456789-_"; + subst = c: if lib.any (x: x == c) good then c else "-"; in - stringAsChars subst name; + lib.stringAsChars subst name; serviceUnit = account: { name = escapeUnitName "lieer-${account.name}"; @@ -59,17 +56,17 @@ let in { - meta.maintainers = [ maintainers.tadfisher ]; + meta.maintainers = [ lib.maintainers.tadfisher ]; - options.services.lieer.enable = mkEnableOption "lieer Gmail synchronization service"; + options.services.lieer.enable = lib.mkEnableOption "lieer Gmail synchronization service"; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.lieer" pkgs lib.platforms.linux) ]; programs.lieer.enable = true; - systemd.user.services = listToAttrs (map serviceUnit syncAccounts); - systemd.user.timers = listToAttrs (map timerUnit syncAccounts); + systemd.user.services = lib.listToAttrs (map serviceUnit syncAccounts); + systemd.user.timers = lib.listToAttrs (map timerUnit syncAccounts); }; } diff --git a/modules/services/linux-wallpaperengine.nix b/modules/services/linux-wallpaperengine.nix index 682ca648f..77492edc5 100644 --- a/modules/services/linux-wallpaperengine.nix +++ b/modules/services/linux-wallpaperengine.nix @@ -4,21 +4,19 @@ pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; cfg = config.services.linux-wallpaperengine; in { - meta.maintainers = [ hm.maintainers.ckgxrg ]; + meta.maintainers = [ lib.hm.maintainers.ckgxrg ]; options.services.linux-wallpaperengine = { - enable = mkEnableOption "linux-wallpaperengine, an implementation of Wallpaper Engine functionality"; + enable = lib.mkEnableOption "linux-wallpaperengine, an implementation of Wallpaper Engine functionality"; - package = mkPackageOption pkgs "linux-wallpaperengine" { }; + package = lib.mkPackageOption pkgs "linux-wallpaperengine" { }; assetsPath = mkOption { type = types.path; @@ -103,7 +101,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.linux-wallpaperengine" pkgs lib.platforms.linux) ]; @@ -112,10 +110,10 @@ in systemd.user.services."linux-wallpaperengine" = let - args = lists.forEach cfg.wallpapers ( + args = lib.lists.forEach cfg.wallpapers ( each: - concatStringsSep " " ( - cli.toGNUCommandLine { } { + lib.concatStringsSep " " ( + lib.cli.toGNUCommandLine { } { screen-root = each.monitor; inherit (each) scaling fps; silent = each.audio.silent; @@ -136,10 +134,10 @@ in }; Service = { ExecStart = - getExe cfg.package + lib.getExe cfg.package + " --assets-dir ${cfg.assetsPath} " + "--clamping ${cfg.clamping} " - + (strings.concatStringsSep " " args); + + (lib.strings.concatStringsSep " " args); Restart = "on-failure"; }; Install = { diff --git a/modules/services/lorri.nix b/modules/services/lorri.nix index 25e5cd6df..ff669f302 100644 --- a/modules/services/lorri.nix +++ b/modules/services/lorri.nix @@ -4,9 +4,6 @@ pkgs, ... }: - -with lib; - let cfg = config.services.lorri; @@ -14,27 +11,27 @@ let in { meta.maintainers = [ - maintainers.gerschtli - maintainers.nyarly + lib.maintainers.gerschtli + lib.maintainers.nyarly ]; options.services.lorri = { - enable = mkEnableOption "lorri build daemon"; + enable = lib.mkEnableOption "lorri build daemon"; - enableNotifications = mkEnableOption "lorri build notifications"; + enableNotifications = lib.mkEnableOption "lorri build notifications"; package = lib.mkPackageOption pkgs "lorri" { }; - nixPackage = mkOption { - type = types.package; + nixPackage = lib.mkOption { + type = lib.types.package; default = pkgs.nix; - defaultText = literalExpression "pkgs.nix"; - example = literalExpression "pkgs.nixVersions.unstable"; + defaultText = lib.literalExpression "pkgs.nix"; + example = lib.literalExpression "pkgs.nixVersions.unstable"; description = "Which nix package to use."; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.lorri" pkgs lib.platforms.linux) ]; @@ -95,7 +92,7 @@ in }; }; - services.lorri-notify = mkIf cfg.enableNotifications { + services.lorri-notify = lib.mkIf cfg.enableNotifications { Unit = { Description = "lorri build notifications"; After = "lorri.service"; @@ -123,7 +120,7 @@ in Restart = "on-failure"; Environment = let - path = makeSearchPath "bin" ( + path = lib.makeSearchPath "bin" ( with pkgs; [ bash diff --git a/modules/services/mako.nix b/modules/services/mako.nix index ab3627776..40edcce4f 100644 --- a/modules/services/mako.nix +++ b/modules/services/mako.nix @@ -4,29 +4,27 @@ pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; cfg = config.services.mako; in { - meta.maintainers = [ maintainers.onny ]; + meta.maintainers = [ lib.maintainers.onny ]; - imports = [ (mkRenamedOptionModule [ "programs" "mako" ] [ "services" "mako" ]) ]; + imports = [ (lib.mkRenamedOptionModule [ "programs" "mako" ] [ "services" "mako" ]) ]; options = { services.mako = { - enable = mkEnableOption '' + enable = lib.mkEnableOption '' Mako, lightweight notification daemon for Wayland ''; package = mkOption { type = types.package; default = pkgs.mako; - defaultText = literalExpression "pkgs.mako"; + defaultText = lib.literalExpression "pkgs.mako"; description = "The mako package to use."; }; @@ -314,7 +312,7 @@ in extraConfig = mkOption { default = ""; type = types.lines; - example = literalExpression '' + example = lib.literalExpression '' [urgency=low] border-color=#b8bb26 ''; @@ -330,8 +328,10 @@ in optionalInteger = name: val: lib.optionalString (val != null) "${name}=${toString val}"; optionalString = name: val: lib.optionalString (val != null) "${name}=${val}"; in - mkIf cfg.enable { - assertions = [ (hm.assertions.assertPlatform "services.mako" pkgs platforms.linux) ]; + lib.mkIf cfg.enable { + assertions = [ + (lib.hm.assertions.assertPlatform "services.mako" pkgs lib.platforms.linux) + ]; home.packages = [ cfg.package ]; diff --git a/modules/services/mbsync.nix b/modules/services/mbsync.nix index d34b12dc5..e29c4d0fd 100644 --- a/modules/services/mbsync.nix +++ b/modules/services/mbsync.nix @@ -4,30 +4,28 @@ pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; cfg = config.services.mbsync; mbsyncOptions = [ "--all" ] - ++ optional (cfg.verbose) "--verbose" - ++ optional (cfg.configFile != null) "--config ${cfg.configFile}"; + ++ lib.optional (cfg.verbose) "--verbose" + ++ lib.optional (cfg.configFile != null) "--config ${cfg.configFile}"; in { - meta.maintainers = [ maintainers.pjones ]; + meta.maintainers = [ lib.maintainers.pjones ]; options.services.mbsync = { - enable = mkEnableOption "mbsync"; + enable = lib.mkEnableOption "mbsync"; package = mkOption { type = types.package; default = pkgs.isync; - defaultText = literalExpression "pkgs.isync"; - example = literalExpression "pkgs.isync"; + defaultText = lib.literalExpression "pkgs.isync"; + example = lib.literalExpression "pkgs.isync"; description = "The package to use for the mbsync binary."; }; @@ -80,7 +78,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.mbsync" pkgs lib.platforms.linux) ]; @@ -93,12 +91,12 @@ in Service = { Type = "oneshot"; - ExecStart = "${cfg.package}/bin/mbsync ${concatStringsSep " " mbsyncOptions}"; + ExecStart = "${cfg.package}/bin/mbsync ${lib.concatStringsSep " " mbsyncOptions}"; } - // (optionalAttrs (cfg.postExec != null) { + // (lib.optionalAttrs (cfg.postExec != null) { ExecStartPost = cfg.postExec; }) - // (optionalAttrs (cfg.preExec != null) { + // (lib.optionalAttrs (cfg.preExec != null) { ExecStartPre = cfg.preExec; }); }; diff --git a/modules/services/mopidy.nix b/modules/services/mopidy.nix index 11d011710..7bb9de1d5 100644 --- a/modules/services/mopidy.nix +++ b/modules/services/mopidy.nix @@ -5,10 +5,13 @@ pkgs, ... }: - -with lib; - let + inherit (lib) + generators + mkIf + mkOption + types + ; cfg = config.services.mopidy; @@ -18,13 +21,17 @@ let toMopidyConf = generators.toINI { mkKeyValue = generators.mkKeyValueDefault { mkValueString = - v: if isList v then "\n " + concatStringsSep "\n " v else generators.mkValueStringDefault { } v; + v: + if lib.isList v then + "\n " + lib.concatStringsSep "\n " v + else + generators.mkValueStringDefault { } v; } " = "; }; mopidyEnv = pkgs.buildEnv { name = "mopidy-with-extensions-${pkgs.mopidy.version}"; - paths = closePropagation cfg.extensionPackages; + paths = lib.closePropagation cfg.extensionPackages; pathsToLink = [ "/${pkgs.mopidyPackages.python.sitePackages}" ]; nativeBuildInputs = [ pkgs.makeWrapper ]; ignoreCollisions = true; @@ -60,7 +67,7 @@ let settingsFormat = mopidyConfFormat { }; - configFilePaths = concatStringsSep ":" ( + configFilePaths = lib.concatStringsSep ":" ( [ "${config.xdg.configHome}/mopidy/mopidy.conf" ] ++ cfg.extraConfigFiles ); @@ -68,15 +75,15 @@ let in { - meta.maintainers = [ hm.maintainers.foo-dogsquared ]; + meta.maintainers = [ lib.hm.maintainers.foo-dogsquared ]; options.services.mopidy = { - enable = mkEnableOption "Mopidy music player daemon"; + enable = lib.mkEnableOption "Mopidy music player daemon"; extensionPackages = mkOption { type = with types; listOf package; default = [ ]; - example = literalExpression "with pkgs; [ mopidy-spotify mopidy-mpd mopidy-mpris ]"; + example = lib.literalExpression "with pkgs; [ mopidy-spotify mopidy-mpd mopidy-mpris ]"; description = '' Mopidy extensions that should be loaded by the service. ''; @@ -85,7 +92,7 @@ in settings = mkOption { type = settingsFormat.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { file = { media_dirs = [ @@ -131,7 +138,9 @@ in }; config = mkIf cfg.enable { - assertions = [ (hm.assertions.assertPlatform "services.mopidy" pkgs platforms.linux) ]; + assertions = [ + (lib.hm.assertions.assertPlatform "services.mopidy" pkgs lib.platforms.linux) + ]; xdg.configFile."mopidy/mopidy.conf".source = settingsFormat.generate "mopidy-${config.home.username}" cfg.settings; diff --git a/modules/services/mpd-discord-rpc.nix b/modules/services/mpd-discord-rpc.nix index a4ffaa30a..0db0347aa 100644 --- a/modules/services/mpd-discord-rpc.nix +++ b/modules/services/mpd-discord-rpc.nix @@ -4,24 +4,21 @@ pkgs, ... }: - -with lib; - let cfg = config.services.mpd-discord-rpc; tomlFormat = pkgs.formats.toml { }; configFile = tomlFormat.generate "config.toml" cfg.settings; in { - meta.maintainers = [ maintainers.kranzes ]; + meta.maintainers = [ lib.maintainers.kranzes ]; options.services.mpd-discord-rpc = { - enable = mkEnableOption "the mpd-discord-rpc service"; + enable = lib.mkEnableOption "the mpd-discord-rpc service"; - settings = mkOption { + settings = lib.mkOption { type = tomlFormat.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { hosts = [ "localhost:6600" ]; format = { @@ -36,17 +33,17 @@ in ''; }; - package = mkOption { - type = types.package; + package = lib.mkOption { + type = lib.types.package; default = pkgs.mpd-discord-rpc; - defaultText = literalExpression "pkgs.mpd-discord-rpc"; + defaultText = lib.literalExpression "pkgs.mpd-discord-rpc"; description = "mpd-discord-rpc package to use."; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ - (hm.assertions.assertPlatform "services.mpd-discord-rpc" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "services.mpd-discord-rpc" pkgs lib.platforms.linux) ]; xdg.configFile."discord-rpc/config.toml".source = configFile; diff --git a/modules/services/mpdris2.nix b/modules/services/mpdris2.nix index 99813760c..d59db3520 100644 --- a/modules/services/mpdris2.nix +++ b/modules/services/mpdris2.nix @@ -4,18 +4,16 @@ pkgs, ... }: - -with lib; - let + inherit (lib) mkEnableOption mkOption types; cfg = config.services.mpdris2; - toIni = generators.toINI { + toIni = lib.generators.toINI { mkKeyValue = key: value: let - value' = if isBool value then (if value then "True" else "False") else toString value; + value' = if lib.isBool value then (if value then "True" else "False") else toString value; in "${key} = ${value'}"; }; @@ -27,7 +25,7 @@ let port = cfg.mpd.port; music_dir = cfg.mpd.musicDirectory; } - // optionalAttrs (cfg.mpd.password != null) { + // lib.optionalAttrs (cfg.mpd.password != null) { password = cfg.mpd.password; }; @@ -39,7 +37,7 @@ let in { - meta.maintainers = [ maintainers.pjones ]; + meta.maintainers = [ lib.maintainers.pjones ]; options.services.mpdris2 = { enable = mkEnableOption "mpDris2 the MPD to MPRIS2 bridge"; @@ -49,7 +47,7 @@ in package = mkOption { type = types.package; default = pkgs.mpdris2; - defaultText = literalExpression "pkgs.mpdris2"; + defaultText = lib.literalExpression "pkgs.mpdris2"; description = "The mpDris2 package to use."; }; @@ -90,7 +88,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.mpdris2" pkgs lib.platforms.linux) ]; diff --git a/modules/services/mpris-proxy.nix b/modules/services/mpris-proxy.nix index 33beac44f..7a936d0ef 100644 --- a/modules/services/mpris-proxy.nix +++ b/modules/services/mpris-proxy.nix @@ -4,20 +4,17 @@ pkgs, ... }: - -with lib; - let cfg = config.services.mpris-proxy; in { - meta.maintainers = [ maintainers.thibautmarty ]; + meta.maintainers = [ lib.maintainers.thibautmarty ]; - options.services.mpris-proxy.enable = mkEnableOption "a proxy forwarding Bluetooth MIDI controls via MPRIS2 to control media players"; + options.services.mpris-proxy.enable = lib.mkEnableOption "a proxy forwarding Bluetooth MIDI controls via MPRIS2 to control media players"; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.mpris-proxy" pkgs lib.platforms.linux) ]; diff --git a/modules/services/muchsync.nix b/modules/services/muchsync.nix index 9e3f26b84..a4f5e81d0 100644 --- a/modules/services/muchsync.nix +++ b/modules/services/muchsync.nix @@ -4,13 +4,17 @@ pkgs, ... }: - -with lib; - # Documentation was partially copied from the muchsync manual. # See http://www.muchsync.org/muchsync.html let + inherit (lib) + escapeShellArg + mkOption + optional + types + ; + cfg = config.services.muchsync; syncOptions = { options = { @@ -132,13 +136,13 @@ let in { - meta.maintainers = with maintainers; [ euxane ]; + meta.maintainers = with lib.maintainers; [ euxane ]; options.services.muchsync = { remotes = mkOption { type = with types; attrsOf (submodule syncOptions); default = { }; - example = literalExpression '' + example = lib.literalExpression '' { server = { frequency = "*:0/10"; @@ -156,12 +160,13 @@ in let mapRemotes = gen: - with attrsets; - mapAttrs' (name: remoteCfg: nameValuePair "muchsync-${name}" (gen name remoteCfg)) cfg.remotes; + lib.attrsets.mapAttrs' ( + name: remoteCfg: lib.attrsets.nameValuePair "muchsync-${name}" (gen name remoteCfg) + ) cfg.remotes; in - mkIf (cfg.remotes != { }) { + lib.mkIf (cfg.remotes != { }) { assertions = [ - (hm.assertions.assertPlatform "services.muchsync" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "services.muchsync" pkgs lib.platforms.linux) { assertion = config.programs.notmuch.enable; @@ -184,7 +189,7 @@ in ''"NOTMUCH_CONFIG=${config.home.sessionVariables.NOTMUCH_CONFIG}"'' ''"NMBGIT=${config.home.sessionVariables.NMBGIT}"'' ]; - ExecStart = concatStringsSep " " ( + ExecStart = lib.concatStringsSep " " ( [ "${pkgs.muchsync}/bin/muchsync" ] ++ [ "-s ${escapeShellArg remoteCfg.sshCommand}" ] ++ optional (!remoteCfg.upload) "--noup" diff --git a/modules/services/network-manager-applet.nix b/modules/services/network-manager-applet.nix index e09e89dfd..ef2363613 100644 --- a/modules/services/network-manager-applet.nix +++ b/modules/services/network-manager-applet.nix @@ -4,9 +4,6 @@ pkgs, ... }: - -with lib; - let cfg = config.services.network-manager-applet; @@ -14,17 +11,17 @@ let in { meta.maintainers = [ - maintainers.rycee - maintainers.midirhee12 + lib.maintainers.rycee + lib.maintainers.midirhee12 ]; options = { services.network-manager-applet = { - enable = mkEnableOption "the Network Manager applet (nm-applet)"; + enable = lib.mkEnableOption "the Network Manager applet (nm-applet)"; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.network-manager-applet" pkgs lib.platforms.linux) ]; @@ -50,7 +47,7 @@ in Service = { ExecStart = toString ( [ "${pkgs.networkmanagerapplet}/bin/nm-applet" ] - ++ optional config.xsession.preferStatusNotifierItems "--indicator" + ++ lib.optional config.xsession.preferStatusNotifierItems "--indicator" ); }; }; diff --git a/modules/services/nextcloud-client.nix b/modules/services/nextcloud-client.nix index 9bd56c3c7..2f651b747 100644 --- a/modules/services/nextcloud-client.nix +++ b/modules/services/nextcloud-client.nix @@ -4,9 +4,6 @@ pkgs, ... }: - -with lib; - let cfg = config.services.nextcloud-client; @@ -15,24 +12,24 @@ in { options = { services.nextcloud-client = { - enable = mkEnableOption "Nextcloud Client"; + enable = lib.mkEnableOption "Nextcloud Client"; - package = mkOption { - type = types.package; + package = lib.mkOption { + type = lib.types.package; default = pkgs.nextcloud-client; - defaultText = literalExpression "pkgs.nextcloud-client"; + defaultText = lib.literalExpression "pkgs.nextcloud-client"; description = "The package to use for the nextcloud client binary."; }; - startInBackground = mkOption { - type = types.bool; + startInBackground = lib.mkOption { + type = lib.types.bool; default = false; description = "Whether to start the Nextcloud client in the background."; }; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.nextcloud-client" pkgs lib.platforms.linux) ]; @@ -46,7 +43,8 @@ in Service = { Environment = [ "PATH=${config.home.profileDirectory}/bin" ]; - ExecStart = "${cfg.package}/bin/nextcloud" + (optionalString cfg.startInBackground " --background"); + ExecStart = + "${cfg.package}/bin/nextcloud" + (lib.optionalString cfg.startInBackground " --background"); }; Install = { diff --git a/modules/services/nix-gc.nix b/modules/services/nix-gc.nix index 5f0af9031..d95d6e94c 100644 --- a/modules/services/nix-gc.nix +++ b/modules/services/nix-gc.nix @@ -4,10 +4,9 @@ pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; + cfg = config.nix.gc; darwinIntervals = [ "hourly" @@ -73,7 +72,7 @@ let if config.nix.enable && config.nix.package != null then config.nix.package else pkgs.nix; in { - meta.maintainers = [ maintainers.shivaraj-bh ]; + meta.maintainers = [ lib.maintainers.shivaraj-bh ]; options = { nix.gc = { @@ -137,54 +136,56 @@ in }; }; - config = lib.mkIf cfg.automatic (mkMerge [ - (mkIf pkgs.stdenv.isLinux { - systemd.user.services.nix-gc = { - Unit = { - Description = "Nix Garbage Collector"; + config = lib.mkIf cfg.automatic ( + lib.mkMerge [ + (lib.mkIf pkgs.stdenv.isLinux { + systemd.user.services.nix-gc = { + Unit = { + Description = "Nix Garbage Collector"; + }; + Service = { + Type = "oneshot"; + ExecStart = toString ( + pkgs.writeShellScript "nix-gc" "exec ${nixPackage}/bin/nix-collect-garbage ${ + lib.optionalString (cfg.options != null) cfg.options + }" + ); + }; }; - Service = { - Type = "oneshot"; - ExecStart = toString ( - pkgs.writeShellScript "nix-gc" "exec ${nixPackage}/bin/nix-collect-garbage ${ - lib.optionalString (cfg.options != null) cfg.options - }" - ); + systemd.user.timers.nix-gc = { + Unit = { + Description = "Nix Garbage Collector"; + }; + Timer = { + OnCalendar = "${cfg.frequency}"; + RandomizedDelaySec = cfg.randomizedDelaySec; + Persistent = cfg.persistent; + Unit = "nix-gc.service"; + }; + Install = { + WantedBy = [ "timers.target" ]; + }; }; - }; - systemd.user.timers.nix-gc = { - Unit = { - Description = "Nix Garbage Collector"; - }; - Timer = { - OnCalendar = "${cfg.frequency}"; - RandomizedDelaySec = cfg.randomizedDelaySec; - Persistent = cfg.persistent; - Unit = "nix-gc.service"; - }; - Install = { - WantedBy = [ "timers.target" ]; - }; - }; - }) + }) - (mkIf pkgs.stdenv.isDarwin { - assertions = [ - { - assertion = elem cfg.frequency darwinIntervals; - message = "On Darwin nix.gc.frequency must be one of: ${toString darwinIntervals}."; - } - ]; + (lib.mkIf pkgs.stdenv.isDarwin { + assertions = [ + { + assertion = lib.elem cfg.frequency darwinIntervals; + message = "On Darwin nix.gc.frequency must be one of: ${toString darwinIntervals}."; + } + ]; - launchd.agents.nix-gc = { - enable = true; - config = { - ProgramArguments = [ - "${nixPackage}/bin/nix-collect-garbage" - ] ++ lib.optional (cfg.options != null) cfg.options; - StartCalendarInterval = mkCalendarInterval cfg.frequency; + launchd.agents.nix-gc = { + enable = true; + config = { + ProgramArguments = [ + "${nixPackage}/bin/nix-collect-garbage" + ] ++ lib.optional (cfg.options != null) cfg.options; + StartCalendarInterval = mkCalendarInterval cfg.frequency; + }; }; - }; - }) - ]); + }) + ] + ); } diff --git a/modules/services/notify-osd.nix b/modules/services/notify-osd.nix index 13bc9904d..a160a42c5 100644 --- a/modules/services/notify-osd.nix +++ b/modules/services/notify-osd.nix @@ -4,25 +4,22 @@ pkgs, ... }: - -with lib; - let cfg = config.services.notify-osd; in { - meta.maintainers = [ maintainers.imalison ]; + meta.maintainers = [ lib.maintainers.imalison ]; options = { services.notify-osd = { - enable = mkEnableOption "notify-osd"; + enable = lib.mkEnableOption "notify-osd"; - package = mkOption { - type = types.package; + package = lib.mkOption { + type = lib.types.package; default = pkgs.notify-osd; - defaultText = literalExpression "pkgs.notify-osd"; + defaultText = lib.literalExpression "pkgs.notify-osd"; description = '' Package containing the {command}`notify-osd` program. ''; @@ -30,7 +27,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.notify-osd" pkgs lib.platforms.linux) ]; diff --git a/modules/services/ollama.nix b/modules/services/ollama.nix index b0c69a8d1..b72a42e95 100644 --- a/modules/services/ollama.nix +++ b/modules/services/ollama.nix @@ -4,10 +4,8 @@ pkgs, ... }: - -with lib; - let + inherit (lib) mkIf mkOption types; cfg = config.services.ollama; @@ -19,13 +17,13 @@ let in { - meta.maintainers = [ maintainers.terlar ]; + meta.maintainers = [ lib.maintainers.terlar ]; options = { services.ollama = { - enable = mkEnableOption "ollama server for local large language models"; + enable = lib.mkEnableOption "ollama server for local large language models"; - package = mkPackageOption pkgs "ollama" { }; + package = lib.mkPackageOption pkgs "ollama" { }; host = mkOption { type = types.str; @@ -96,8 +94,8 @@ in }; Service = { - ExecStart = "${getExe ollamaPackage} serve"; - Environment = (mapAttrsToList (n: v: "${n}=${v}") cfg.environmentVariables) ++ [ + ExecStart = "${lib.getExe ollamaPackage} serve"; + Environment = (lib.mapAttrsToList (n: v: "${n}=${v}") cfg.environmentVariables) ++ [ "OLLAMA_HOST=${cfg.host}:${toString cfg.port}" ]; }; @@ -111,7 +109,7 @@ in enable = true; config = { ProgramArguments = [ - "${getExe ollamaPackage}" + "${lib.getExe ollamaPackage}" "serve" ]; EnvironmentVariables = cfg.environmentVariables // { diff --git a/modules/services/opensnitch-ui.nix b/modules/services/opensnitch-ui.nix index 1556da01e..5c1c3d4bb 100644 --- a/modules/services/opensnitch-ui.nix +++ b/modules/services/opensnitch-ui.nix @@ -4,9 +4,6 @@ pkgs, ... }: - -with lib; - let cfg = config.services.opensnitch-ui; @@ -14,15 +11,15 @@ let in { - meta.maintainers = [ maintainers.onny ]; + meta.maintainers = [ lib.maintainers.onny ]; options = { services.opensnitch-ui = { - enable = mkEnableOption "Opensnitch client"; + enable = lib.mkEnableOption "Opensnitch client"; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.opensnitch-ui" pkgs lib.platforms.linux) ]; diff --git a/modules/services/osmscout-server.nix b/modules/services/osmscout-server.nix index 1042bed22..174528e1e 100644 --- a/modules/services/osmscout-server.nix +++ b/modules/services/osmscout-server.nix @@ -4,20 +4,19 @@ pkgs, ... }: - -with lib; - let + inherit (lib) mkIf mkOption types; + cfg = config.services.osmscout-server; in { - meta.maintainers = [ maintainers.Thra11 ]; + meta.maintainers = [ lib.maintainers.Thra11 ]; options = { services.osmscout-server = { - enable = mkEnableOption "OSM Scout Server"; + enable = lib.mkEnableOption "OSM Scout Server"; - package = mkPackageOption pkgs "osmscout-server" { }; + package = lib.mkPackageOption pkgs "osmscout-server" { }; network = { startWhenNeeded = mkOption { diff --git a/modules/services/owncloud-client.nix b/modules/services/owncloud-client.nix index 449c6d6c1..35f728a15 100644 --- a/modules/services/owncloud-client.nix +++ b/modules/services/owncloud-client.nix @@ -4,9 +4,6 @@ pkgs, ... }: - -with lib; - let cfg = config.services.owncloud-client; @@ -15,15 +12,15 @@ in { options = { services.owncloud-client = { - enable = mkEnableOption "Owncloud Client"; + enable = lib.mkEnableOption "Owncloud Client"; - package = mkPackageOption pkgs "owncloud-client" { }; + package = lib.mkPackageOption pkgs "owncloud-client" { }; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ - (hm.assertions.assertPlatform "services.owncloud-client" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "services.owncloud-client" pkgs lib.platforms.linux) ]; systemd.user.services.owncloud-client = { diff --git a/modules/services/pantalaimon.nix b/modules/services/pantalaimon.nix index eb9f25aaa..3bd5a9333 100644 --- a/modules/services/pantalaimon.nix +++ b/modules/services/pantalaimon.nix @@ -4,33 +4,30 @@ pkgs, ... }: - -with lib; - let cfg = config.services.pantalaimon; iniFmt = pkgs.formats.ini { }; in { - meta.maintainers = [ maintainers.jojosch ]; + meta.maintainers = [ lib.maintainers.jojosch ]; options = { services.pantalaimon = { - enable = mkEnableOption "Pantalaimon, an E2EE aware proxy daemon for matrix clients"; + enable = lib.mkEnableOption "Pantalaimon, an E2EE aware proxy daemon for matrix clients"; - package = mkOption { - type = types.package; + package = lib.mkOption { + type = lib.types.package; default = pkgs.pantalaimon; - defaultText = literalExpression "pkgs.pantalaimon"; + defaultText = lib.literalExpression "pkgs.pantalaimon"; description = "Package providing the {command}`pantalaimon` executable to use."; }; - settings = mkOption { + settings = lib.mkOption { type = iniFmt.type; default = { }; - defaultText = literalExpression "{ }"; - example = literalExpression '' + defaultText = lib.literalExpression "{ }"; + example = lib.literalExpression '' { Default = { LogLevel = "Debug"; @@ -55,7 +52,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.pantalaimon" pkgs lib.platforms.linux) ]; diff --git a/modules/services/parcellite.nix b/modules/services/parcellite.nix index 51254d1b9..a9f02bb5d 100644 --- a/modules/services/parcellite.nix +++ b/modules/services/parcellite.nix @@ -4,22 +4,19 @@ pkgs, ... }: - -with lib; - let cfg = config.services.parcellite; in { - meta.maintainers = [ maintainers.gleber ]; + meta.maintainers = [ lib.maintainers.gleber ]; options.services.parcellite = { - enable = mkEnableOption "Parcellite"; + enable = lib.mkEnableOption "Parcellite"; - extraOptions = mkOption { - type = types.listOf types.str; + extraOptions = lib.mkOption { + type = lib.types.listOf lib.types.str; default = [ ]; example = [ "--no-icon" ]; description = '' @@ -27,16 +24,16 @@ in ''; }; - package = mkOption { - type = types.package; + package = lib.mkOption { + type = lib.types.package; default = pkgs.parcellite; - defaultText = literalExpression "pkgs.parcellite"; - example = literalExpression "pkgs.clipit"; + defaultText = lib.literalExpression "pkgs.parcellite"; + example = lib.literalExpression "pkgs.clipit"; description = "Parcellite derivation to use."; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.parcellite" pkgs lib.platforms.linux) ]; @@ -59,7 +56,7 @@ in }; Service = { - ExecStart = "${cfg.package}/bin/${cfg.package.pname} ${escapeShellArgs cfg.extraOptions}"; + ExecStart = "${cfg.package}/bin/${cfg.package.pname} ${lib.escapeShellArgs cfg.extraOptions}"; Restart = "on-abort"; }; }; diff --git a/modules/services/pass-secret-service.nix b/modules/services/pass-secret-service.nix index a44bde8c2..0d0799328 100644 --- a/modules/services/pass-secret-service.nix +++ b/modules/services/pass-secret-service.nix @@ -4,24 +4,23 @@ lib, ... }: - -with lib; - let + inherit (lib) mkOption types; + cfg = config.services.pass-secret-service; busName = "org.freedesktop.secrets"; in { - meta.maintainers = with maintainers; [ + meta.maintainers = with lib.maintainers; [ cab404 cyntheticfox ]; options.services.pass-secret-service = { - enable = mkEnableOption "Pass libsecret service"; + enable = lib.mkEnableOption "Pass libsecret service"; - package = mkPackageOption pkgs "pass-secret-service" { }; + package = lib.mkPackageOption pkgs "pass-secret-service" { }; storePath = mkOption { type = with types; nullOr str; @@ -37,9 +36,9 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ - (hm.assertions.assertPlatform "services.pass-secret-service" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "services.pass-secret-service" pkgs lib.platforms.linux) { assertion = !config.services.gnome-keyring.enable; message = '' @@ -64,7 +63,7 @@ in Service = { Type = "dbus"; - ExecStart = "${binPath} ${optionalString (cfg.storePath != null) "--path ${cfg.storePath}"}"; + ExecStart = "${binPath} ${lib.optionalString (cfg.storePath != null) "--path ${cfg.storePath}"}"; BusName = busName; Environment = [ "GNUPGHOME=${config.programs.gpg.homedir}" ]; }; diff --git a/modules/services/pasystray.nix b/modules/services/pasystray.nix index 6cf34c037..5f21aa23e 100644 --- a/modules/services/pasystray.nix +++ b/modules/services/pasystray.nix @@ -4,22 +4,19 @@ pkgs, ... }: - -with lib; - let cfg = config.services.pasystray; in { - meta.maintainers = [ hm.maintainers.pltanton ]; + meta.maintainers = [ lib.hm.maintainers.pltanton ]; options = { services.pasystray = { - enable = mkEnableOption "PulseAudio system tray"; + enable = lib.mkEnableOption "PulseAudio system tray"; - extraOptions = mkOption { - type = types.listOf types.str; + extraOptions = lib.mkOption { + type = lib.types.listOf lib.types.str; default = [ ]; description = '' Extra command-line arguments to pass to {command}`pasystray`. @@ -28,9 +25,9 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ - (hm.assertions.assertPlatform "services.pasystray" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "services.pasystray" pkgs lib.platforms.linux) ]; systemd.user.services.pasystray = { @@ -51,13 +48,13 @@ in Service = { Environment = let - toolPaths = makeBinPath [ + toolPaths = lib.makeBinPath [ pkgs.paprefs pkgs.pavucontrol ]; in [ "PATH=${toolPaths}" ]; - ExecStart = escapeShellArgs ([ "${pkgs.pasystray}/bin/pasystray" ] ++ cfg.extraOptions); + ExecStart = lib.escapeShellArgs ([ "${pkgs.pasystray}/bin/pasystray" ] ++ cfg.extraOptions); }; }; }; diff --git a/modules/services/pbgopy.nix b/modules/services/pbgopy.nix index 9383429f2..ceeabe60e 100644 --- a/modules/services/pbgopy.nix +++ b/modules/services/pbgopy.nix @@ -4,21 +4,19 @@ pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; cfg = config.services.pbgopy; package = pkgs.pbgopy; - commandLine = concatStringsSep " " ( + commandLine = lib.concatStringsSep " " ( [ "${package}/bin/pbgopy serve" "--port ${toString cfg.port}" "--ttl ${cfg.cache.ttl}" ] - ++ optional (cfg.httpAuth != null) "--basic-auth ${escapeShellArg cfg.httpAuth}" + ++ lib.optional (cfg.httpAuth != null) "--basic-auth ${lib.escapeShellArg cfg.httpAuth}" ); in @@ -26,7 +24,7 @@ in meta.maintainers = [ ]; options.services.pbgopy = { - enable = mkEnableOption "pbgopy"; + enable = lib.mkEnableOption "pbgopy"; port = mkOption { type = types.port; @@ -57,7 +55,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.pbgopy" pkgs lib.platforms.linux) ]; diff --git a/modules/services/picom.nix b/modules/services/picom.nix index 423554ee6..c3138a430 100644 --- a/modules/services/picom.nix +++ b/modules/services/picom.nix @@ -10,10 +10,8 @@ let inherit (builtins) elemAt isAttrs - isBool length mapAttrs - toJSON ; inherit (lib) boolToString @@ -28,9 +26,7 @@ let mkDefault mkIf mkOption - optional types - warn getExe ; diff --git a/modules/services/plan9port.nix b/modules/services/plan9port.nix index 35a4feb85..3d4bf17ce 100644 --- a/modules/services/plan9port.nix +++ b/modules/services/plan9port.nix @@ -4,34 +4,31 @@ pkgs, ... }: - -with lib; - let cfg = config.services.plan9port; in { - meta.maintainers = [ maintainers.ehmry ]; + meta.maintainers = [ lib.maintainers.ehmry ]; options.services.plan9port = { - fontsrv.enable = mkEnableOption "the Plan 9 file system access to host fonts"; - plumber.enable = mkEnableOption "the Plan 9 file system for interprocess messaging"; + fontsrv.enable = lib.mkEnableOption "the Plan 9 file system access to host fonts"; + plumber.enable = lib.mkEnableOption "the Plan 9 file system for interprocess messaging"; }; - config = mkIf (cfg.fontsrv.enable || cfg.plumber.enable) { + config = lib.mkIf (cfg.fontsrv.enable || cfg.plumber.enable) { assertions = [ - (hm.assertions.assertPlatform "services.plan9port" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "services.plan9port" pkgs lib.platforms.linux) ]; - systemd.user.services.fontsrv = mkIf cfg.fontsrv.enable { + systemd.user.services.fontsrv = lib.mkIf cfg.fontsrv.enable { Unit.Description = "the Plan 9 file system access to host fonts"; Install.WantedBy = [ "default.target" ]; Service.ExecStart = "${pkgs.plan9port}/bin/9 fontsrv"; }; - systemd.user.services.plumber = mkIf cfg.plumber.enable { + systemd.user.services.plumber = lib.mkIf cfg.plumber.enable { Unit.Description = "file system for interprocess messaging"; Install.WantedBy = [ "default.target" ]; Service.ExecStart = "${pkgs.plan9port}/bin/9 plumber -f"; diff --git a/modules/services/playerctld.nix b/modules/services/playerctld.nix index 9dfc75a52..3278af762 100644 --- a/modules/services/playerctld.nix +++ b/modules/services/playerctld.nix @@ -4,29 +4,26 @@ pkgs, ... }: - -with lib; - let cfg = config.services.playerctld; in { - meta.maintainers = [ hm.maintainers.fendse ]; + meta.maintainers = [ lib.hm.maintainers.fendse ]; options.services.playerctld = { - enable = mkEnableOption "playerctld daemon"; + enable = lib.mkEnableOption "playerctld daemon"; - package = mkOption { - type = types.package; + package = lib.mkOption { + type = lib.types.package; default = pkgs.playerctl; - defaultText = literalExpression "pkgs.playerctl"; + defaultText = lib.literalExpression "pkgs.playerctl"; description = "The playerctl package to use."; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.playerctld" pkgs lib.platforms.linux) ]; diff --git a/modules/services/plex-mpv-shim.nix b/modules/services/plex-mpv-shim.nix index 0c8952021..f34ddd80b 100644 --- a/modules/services/plex-mpv-shim.nix +++ b/modules/services/plex-mpv-shim.nix @@ -4,9 +4,6 @@ pkgs, ... }: - -with lib; - let jsonFormat = pkgs.formats.json { }; @@ -14,23 +11,23 @@ let in { - meta.maintainers = [ maintainers.starcraft66 ]; + meta.maintainers = [ lib.maintainers.starcraft66 ]; options = { services.plex-mpv-shim = { - enable = mkEnableOption "Plex mpv shim"; + enable = lib.mkEnableOption "Plex mpv shim"; - package = mkOption { - type = types.package; + package = lib.mkOption { + type = lib.types.package; default = pkgs.plex-mpv-shim; - defaultText = literalExpression "pkgs.plex-mpv-shim"; + defaultText = lib.literalExpression "pkgs.plex-mpv-shim"; description = "The package to use for the Plex mpv shim."; }; - settings = mkOption { + settings = lib.mkOption { type = jsonFormat.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { adaptive_transcode = false; allow_http = false; @@ -51,12 +48,12 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.plex-mpv-shim" pkgs lib.platforms.linux) ]; - xdg.configFile."plex-mpv-shim/conf.json" = mkIf (cfg.settings != { }) { + xdg.configFile."plex-mpv-shim/conf.json" = lib.mkIf (cfg.settings != { }) { source = jsonFormat.generate "conf.json" cfg.settings; }; diff --git a/modules/services/podman-linux/builds.nix b/modules/services/podman-linux/builds.nix index 81e415e24..087f7b68e 100644 --- a/modules/services/podman-linux/builds.nix +++ b/modules/services/podman-linux/builds.nix @@ -4,8 +4,9 @@ pkgs, ... }: -with lib; let + inherit (lib) mkOption types; + cfg = config.services.podman; podman-lib = import ./podman-lib.nix { inherit pkgs lib config; }; @@ -27,7 +28,7 @@ let TLSVerify = buildDef.tlsVerify; }; Install = { - WantedBy = optionals buildDef.autoStart [ + WantedBy = lib.optionals buildDef.autoStart [ "default.target" "multi-user.target" ]; @@ -93,7 +94,7 @@ let environment = mkOption { type = podman-lib.primitiveAttrs; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { VAR1 = "0:100"; VAR2 = true; @@ -106,7 +107,7 @@ let extraConfig = mkOption { type = podman-lib.extraConfigType; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { Build = { Arch = "aarch64"; @@ -128,7 +129,7 @@ let file = mkOption { type = types.str; - example = literalExpression '' + example = lib.literalExpression '' `"xdg.configFile."containerfiles/my-img/Containerfile"` or `"https://github.com/.../my-img/Containerfile"` @@ -179,11 +180,11 @@ in config = let - buildQuadlets = mapAttrsToList toQuadletInternal cfg.builds; + buildQuadlets = lib.mapAttrsToList toQuadletInternal cfg.builds; in - mkIf cfg.enable { + lib.mkIf cfg.enable { services.podman.internal.quadletDefinitions = buildQuadlets; - assertions = flatten (map (build: build.assertions) buildQuadlets); + assertions = lib.flatten (map (build: build.assertions) buildQuadlets); xdg.configFile."podman/images.manifest".text = podman-lib.generateManifestText buildQuadlets; }; diff --git a/modules/services/podman-linux/containers.nix b/modules/services/podman-linux/containers.nix index f3af13cc5..f8182adae 100644 --- a/modules/services/podman-linux/containers.nix +++ b/modules/services/podman-linux/containers.nix @@ -4,10 +4,9 @@ pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; + cfg = config.services.podman; podman-lib = import ./podman-lib.nix { inherit pkgs lib config; }; @@ -25,11 +24,14 @@ let dependencyBySuffix = type: value: - if (hasInfix ".${type}" value) then + if (lib.hasInfix ".${type}" value) then let name = extractQuadletReference type value; in - if (hasAttr name cfg.internal.builtQuadlets) then [ (cfg.internal.builtQuadlets.${name}) ] else [ ] + if (lib.hasAttr name cfg.internal.builtQuadlets) then + [ (cfg.internal.builtQuadlets.${name}) ] + else + [ ] else [ ]; @@ -55,25 +57,29 @@ let builtins.concatLists (map (checkQuadletReference types) value) else let - type = findFirst (t: hasInfix ".${t}" value) null types; + type = lib.findFirst (t: lib.hasInfix ".${t}" value) null types; in if (type != null) then let quadletName = extractQuadletReference type value; - quadletsOfType = filterAttrs (n: v: v.quadletData.resourceType == type) cfg.internal.builtQuadlets; + quadletsOfType = lib.filterAttrs ( + n: v: v.quadletData.resourceType == type + ) cfg.internal.builtQuadlets; in - if (hasAttr quadletName quadletsOfType) then + if (lib.hasAttr quadletName quadletsOfType) then [ - (replaceStrings [ quadletName ] [ "podman-${quadletName}" ] value) + (lib.replaceStrings [ quadletName ] [ "podman-${quadletName}" ] value) ] else [ value ] - else if ((hasInfix "/nix/store" value) == false && hasAttr value cfg.internal.builtQuadlets) then + else if + ((lib.hasInfix "/nix/store" value) == false && lib.hasAttr value cfg.internal.builtQuadlets) + then lib.warn '' A value for Podman container '${name}' might use a reference to another quadlet: ${value}. Append the type '.${ cfg.internal.builtQuadlets.${value}.quadletData.resourceType - }' to '${baseName value}' if this is intended. + }' to '${lib.baseName value}' if this is intended. '' [ value ] else [ value ]; @@ -104,7 +110,7 @@ let Volume = checkQuadletReference [ "volume" ] containerDef.volumes; }; Install = { - WantedBy = optionals containerDef.autoStart [ + WantedBy = lib.optionals containerDef.autoStart [ "default.target" "multi-user.target" ]; @@ -226,7 +232,7 @@ let environment = mkOption { type = podman-lib.primitiveAttrs; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { VAR1 = "0:100"; VAR2 = true; @@ -268,7 +274,7 @@ let extraConfig = mkOption { type = podman-lib.extraConfigType; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { Container = { User = 1000; @@ -320,8 +326,8 @@ let network = mkOption { type = with types; either str (listOf str); default = [ ]; - apply = value: if isString value then [ value ] else value; - example = literalMD '' + apply = value: if lib.isString value then [ value ] else value; + example = lib.literalMD '' `"host"` or `"bridge_network_1"` @@ -392,11 +398,11 @@ in config = let - containerQuadlets = mapAttrsToList toQuadletInternal cfg.containers; + containerQuadlets = lib.mapAttrsToList toQuadletInternal cfg.containers; in - mkIf cfg.enable { + lib.mkIf cfg.enable { services.podman.internal.quadletDefinitions = containerQuadlets; - assertions = flatten (map (container: container.assertions) containerQuadlets); + assertions = lib.flatten (map (container: container.assertions) containerQuadlets); # manifest file xdg.configFile."podman/containers.manifest".text = diff --git a/modules/services/podman-linux/images.nix b/modules/services/podman-linux/images.nix index 519221cfd..275896183 100644 --- a/modules/services/podman-linux/images.nix +++ b/modules/services/podman-linux/images.nix @@ -4,8 +4,9 @@ pkgs, ... }: -with lib; let + inherit (lib) mkOption types; + cfg = config.services.podman; podman-lib = import ./podman-lib.nix { inherit pkgs lib config; }; @@ -29,7 +30,7 @@ let TLSVerify = imageDef.tlsVerify; }; Install = { - WantedBy = optionals imageDef.autoStart [ + WantedBy = lib.optionals imageDef.autoStart [ "default.target" "multi-user.target" ]; @@ -99,7 +100,7 @@ let extraConfig = mkOption { type = podman-lib.extraConfigType; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { Image = { ContainersConfModule = "/etc/nvd.conf"; @@ -162,10 +163,10 @@ in config = let - imageQuadlets = mapAttrsToList toQuadletInternal cfg.images; + imageQuadlets = lib.mapAttrsToList toQuadletInternal cfg.images; in - mkIf cfg.enable { + lib.mkIf cfg.enable { services.podman.internal.quadletDefinitions = imageQuadlets; - assertions = flatten (map (image: image.assertions) imageQuadlets); + assertions = lib.flatten (map (image: image.assertions) imageQuadlets); }; } diff --git a/modules/services/podman-linux/install-quadlet.nix b/modules/services/podman-linux/install-quadlet.nix index 952963d6d..668612566 100644 --- a/modules/services/podman-linux/install-quadlet.nix +++ b/modules/services/podman-linux/install-quadlet.nix @@ -4,9 +4,6 @@ pkgs, ... }: - -with lib; - let cfg = config.services.podman; @@ -25,7 +22,7 @@ let unpackPhase = '' mkdir -p $out/quadlets - ${concatStringsSep "\n" ( + ${lib.concatStringsSep "\n" ( map ( v: "echo 'linking ${v.quadletData.serviceName}.${v.quadletData.resourceType}'; ln -s ${v.out}/quadlets/${v.quadletData.serviceName}.${v.quadletData.resourceType} $out/quadlets" @@ -46,7 +43,7 @@ let ''; passthru = { - outPath = self.out; + outPath = lib.self.out; quadletData = quadlet; }; }; @@ -76,9 +73,9 @@ let } ]; in - flatten (map (name: processEntry name (getAttr name entries)) (attrNames entries)); + lib.flatten (map (name: processEntry name (lib.getAttr name entries)) (lib.attrNames entries)); - allUnitFiles = concatMap ( + allUnitFiles = lib.concatMap ( builtQuadlet: accumulateUnitFiles "" "${builtQuadlet.outPath}/units" builtQuadlet.quadletData ) builtQuadlets; @@ -86,7 +83,7 @@ let # merge from multiple sources. so we link each file explicitly, which is fine for all unique files generateSystemdFileLinks = files: - listToAttrs ( + lib.listToAttrs ( map (unitFile: { name = "${config.xdg.configHome}/systemd/user/${unitFile.key}"; value = { @@ -99,7 +96,7 @@ in { imports = [ ./options.nix ]; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.file = generateSystemdFileLinks allUnitFiles; # if the length of builtQuadlets is 0, then we don't need register the activation script @@ -107,10 +104,10 @@ in lib.hm.dag.entryAfter [ "reloadSystemd" ] activationCleanupScript ); - services.podman.internal.builtQuadlets = listToAttrs ( + services.podman.internal.builtQuadlets = lib.listToAttrs ( map (pkg: { name = - (removePrefix "podman-" pkg.passthru.quadletData.serviceName) + (lib.removePrefix "podman-" pkg.passthru.quadletData.serviceName) + "." + pkg.passthru.quadletData.resourceType; value = pkg; diff --git a/modules/services/podman-linux/networks.nix b/modules/services/podman-linux/networks.nix index b82758bb8..f495553de 100644 --- a/modules/services/podman-linux/networks.nix +++ b/modules/services/podman-linux/networks.nix @@ -4,10 +4,9 @@ pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; + cfg = config.services.podman; podman-lib = import ./podman-lib.nix { inherit pkgs lib config; }; @@ -44,7 +43,7 @@ let PATH = ( builtins.concatStringsSep ":" [ "${podman-lib.newuidmapPaths}" - "${makeBinPath [ + "${lib.makeBinPath [ pkgs.su pkgs.coreutils ]}" @@ -112,7 +111,7 @@ let extraConfig = mkOption { type = podman-lib.extraConfigType; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { Network = { ContainerConfModule = "/etc/nvd.conf"; @@ -179,11 +178,11 @@ in config = let - networkQuadlets = mapAttrsToList toQuadletInternal cfg.networks; + networkQuadlets = lib.mapAttrsToList toQuadletInternal cfg.networks; in - mkIf cfg.enable { + lib.mkIf cfg.enable { services.podman.internal.quadletDefinitions = networkQuadlets; - assertions = flatten (map (network: network.assertions) networkQuadlets); + assertions = lib.flatten (map (network: network.assertions) networkQuadlets); xdg.configFile."podman/networks.manifest".text = podman-lib.generateManifestText networkQuadlets; }; diff --git a/modules/services/podman-linux/podman-lib.nix b/modules/services/podman-linux/podman-lib.nix index cdf8a04c0..e6276f640 100644 --- a/modules/services/podman-linux/podman-lib.nix +++ b/modules/services/podman-linux/podman-lib.nix @@ -4,8 +4,14 @@ config, ... }: -with lib; let + inherit (lib) + concatStringsSep + isList + mapAttrsToList + types + ; + normalizeKeyValue = k: v: let @@ -32,7 +38,7 @@ let path ]); - toQuadletIni = generators.toINI { + toQuadletIni = lib.generators.toINI { listsAsDuplicateKeys = true; mkKeyValue = normalizeKeyValue; }; @@ -40,7 +46,7 @@ let # meant for ini. favours b when two values are unmergeable deepMerge = a: b: - foldl' ( + lib.foldl' ( result: key: let aVal = if builtins.hasAttr key a then a.${key} else null; @@ -53,7 +59,7 @@ let && builtins.length list > 0 && builtins.typeOf (builtins.head list) == builtins.typeOf val; in - if isAttrs aVal && isAttrs bVal then + if lib.isAttrs aVal && lib.isAttrs bVal then result // { ${key} = deepMerge aVal bVal; } else if isList aVal && isList bVal then result // { ${key} = aVal ++ bVal; } @@ -102,7 +108,7 @@ in buildSectionAsserts = section: attrs: if builtins.hasAttr section configRules then - flatten ( + lib.flatten ( mapAttrsToList ( attrName: attrValue: if builtins.hasAttr attrName configRules.${section} then @@ -126,7 +132,7 @@ in let imageTags = (extraConfig.Build or { }).ImageTag or [ ]; containsRequiredTag = builtins.elem "homemanager/${quadletName}" imageTags; - imageTagsStr = concatMapStringsSep ''" "'' toString imageTags; + imageTagsStr = lib.concatMapStringsSep ''" "'' toString imageTags; in [ { @@ -136,10 +142,12 @@ in ]; # Flatten assertions from all sections in `extraConfig`. in - flatten (concatLists [ - (mapAttrsToList buildSectionAsserts extraConfig) - (checkImageTag extraConfig) - ]); + lib.flatten ( + lib.concatLists [ + (mapAttrsToList buildSectionAsserts extraConfig) + (checkImageTag extraConfig) + ] + ); extraConfigType = with types; @@ -156,9 +164,9 @@ in quadlets: let # create a list of all unique quadlet.resourceType in quadlets - quadletTypes = unique (map (quadlet: quadlet.resourceType) quadlets); + quadletTypes = lib.unique (map (quadlet: quadlet.resourceType) quadlets); # if quadletTypes is > 1, then all quadlets are not the same type - allQuadletsSameType = length quadletTypes <= 1; + allQuadletsSameType = lib.length quadletTypes <= 1; # ensures the service name is formatted correctly to be easily read # by the activation script and matches `podman ls` output @@ -200,8 +208,8 @@ in removeBlankLines = text: let - lines = splitString "\n" text; - nonEmptyLines = filter (line: line != "") lines; + lines = lib.splitString "\n" text; + nonEmptyLines = lib.filter (line: line != "") lines; in concatStringsSep "\n" nonEmptyLines; diff --git a/modules/services/podman-linux/services.nix b/modules/services/podman-linux/services.nix index 8c911699c..1ffb001dd 100644 --- a/modules/services/podman-linux/services.nix +++ b/modules/services/podman-linux/services.nix @@ -4,23 +4,20 @@ pkgs, ... }: - -with lib; - let cfg = config.services.podman; in { options.services.podman = { autoUpdate = { - enable = mkOption { - type = types.bool; + enable = lib.mkOption { + type = lib.types.bool; default = false; description = "Automatically update the podman images."; }; - onCalendar = mkOption { - type = types.str; + onCalendar = lib.mkOption { + type = lib.types.str; default = "Sun *-*-* 00:00"; description = '' The systemd `OnCalendar` expression for the update. See @@ -30,63 +27,65 @@ in }; }; - config = mkIf cfg.enable (mkMerge [ - (mkIf cfg.autoUpdate.enable { - systemd.user.services."podman-auto-update" = { - Unit = { - Description = "Podman auto-update service"; - Documentation = "man:podman-auto-update(1)"; - Wants = [ "network-online.target" ]; - After = [ "network-online.target" ]; - }; + config = lib.mkIf cfg.enable ( + lib.mkMerge [ + (lib.mkIf cfg.autoUpdate.enable { + systemd.user.services."podman-auto-update" = { + Unit = { + Description = "Podman auto-update service"; + Documentation = "man:podman-auto-update(1)"; + Wants = [ "network-online.target" ]; + After = [ "network-online.target" ]; + }; - Service = { - Type = "oneshot"; - Environment = "PATH=${ - builtins.concatStringsSep ":" [ - "/run/wrappers/bin" - "/run/current-system/sw/bin" - "${config.home.homeDirectory}/.nix-profile/bin" - ] - }"; - ExecStart = "${cfg.package}/bin/podman auto-update"; - ExecStartPost = "${cfg.package}/bin/podman image prune -f"; - TimeoutStartSec = "300s"; - TimeoutStopSec = "10s"; - }; - }; - - systemd.user.timers."podman-auto-update" = { - Unit = { - Description = "Podman auto-update timer"; - }; - - Timer = { - OnCalendar = cfg.autoUpdate.onCalendar; - RandomizedDelaySec = 300; - Persistent = true; - }; - - Install = { - WantedBy = [ "timers.target" ]; - }; - }; - }) - ({ - xdg.configFile."systemd/user/podman-user-wait-network-online.service.d/50-exec-search-path.conf".text = - '' - [Service] - ExecSearchPath=${ - makeBinPath ( - with pkgs; - [ - bashInteractive - systemd - coreutils + Service = { + Type = "oneshot"; + Environment = "PATH=${ + builtins.concatStringsSep ":" [ + "/run/wrappers/bin" + "/run/current-system/sw/bin" + "${config.home.homeDirectory}/.nix-profile/bin" ] - ) - }:/bin - ''; - }) - ]); + }"; + ExecStart = "${cfg.package}/bin/podman auto-update"; + ExecStartPost = "${cfg.package}/bin/podman image prune -f"; + TimeoutStartSec = "300s"; + TimeoutStopSec = "10s"; + }; + }; + + systemd.user.timers."podman-auto-update" = { + Unit = { + Description = "Podman auto-update timer"; + }; + + Timer = { + OnCalendar = cfg.autoUpdate.onCalendar; + RandomizedDelaySec = 300; + Persistent = true; + }; + + Install = { + WantedBy = [ "timers.target" ]; + }; + }; + }) + { + xdg.configFile."systemd/user/podman-user-wait-network-online.service.d/50-exec-search-path.conf".text = + '' + [Service] + ExecSearchPath=${ + lib.makeBinPath ( + with pkgs; + [ + bashInteractive + systemd + coreutils + ] + ) + }:/bin + ''; + } + ] + ); } diff --git a/modules/services/podman-linux/volumes.nix b/modules/services/podman-linux/volumes.nix index aedb0fcd9..91cfd6bc2 100644 --- a/modules/services/podman-linux/volumes.nix +++ b/modules/services/podman-linux/volumes.nix @@ -4,10 +4,9 @@ pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; + cfg = config.services.podman; podman-lib = import ./podman-lib.nix { inherit pkgs lib config; }; @@ -17,7 +16,7 @@ let let quadlet = podman-lib.deepMerge { Install = { - WantedBy = optionals volumeDef.autoStart [ + WantedBy = lib.optionals volumeDef.autoStart [ "default.target" "multi-user.target" ]; @@ -27,7 +26,7 @@ let PATH = ( builtins.concatStringsSep ":" [ "${podman-lib.newuidmapPaths}" - "${makeBinPath [ + "${lib.makeBinPath [ pkgs.su pkgs.coreutils ]}" @@ -117,7 +116,7 @@ let extraConfig = mkOption { type = podman-lib.extraConfigType; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { Volume = { ContainerConfModule = "/etc/nvd.conf"; @@ -191,11 +190,11 @@ in config = let - volumeQuadlets = mapAttrsToList toQuadletInternal cfg.volumes; + volumeQuadlets = lib.mapAttrsToList toQuadletInternal cfg.volumes; in - mkIf cfg.enable { + lib.mkIf cfg.enable { services.podman.internal.quadletDefinitions = volumeQuadlets; - assertions = flatten (map (volume: volume.assertions) volumeQuadlets); + assertions = lib.flatten (map (volume: volume.assertions) volumeQuadlets); xdg.configFile."podman/volumes.manifest".text = podman-lib.generateManifestText volumeQuadlets; }; diff --git a/modules/services/polybar.nix b/modules/services/polybar.nix index 21297b8a6..019c63057 100644 --- a/modules/services/polybar.nix +++ b/modules/services/polybar.nix @@ -5,10 +5,13 @@ pkgs, ... }: - -with lib; - let + inherit (lib) + concatLists + mkIf + mkOption + types + ; cfg = config.services.polybar; opt = options.services.polybar; @@ -24,8 +27,8 @@ let # foo-0 = "a"; # foo-1 = "b"; # } - if isList val then - concatLists (imap0 (i: convertPolybarKeyVal "${key}-${toString i}") val) + if lib.isList val then + concatLists (lib.imap0 (i: convertPolybarKeyVal "${key}-${toString i}") val) # Convert { # foo.text = "a"; # foo.font = 1; @@ -33,29 +36,29 @@ let # foo = "a"; # foo-font = 1; # } - else if isAttrs val && !lib.isDerivation val then + else if lib.isAttrs val && !lib.isDerivation val then concatLists ( - mapAttrsToList (k: convertPolybarKeyVal (if k == "text" then key else "${key}-${k}")) val + lib.mapAttrsToList (k: convertPolybarKeyVal (if k == "text" then key else "${key}-${k}")) val ) # Base case else - [ (nameValuePair key val) ]; + [ (lib.nameValuePair key val) ]; convertPolybarSection = - _: attrs: listToAttrs (concatLists (mapAttrsToList convertPolybarKeyVal attrs)); + _: attrs: lib.listToAttrs (concatLists (lib.mapAttrsToList convertPolybarKeyVal attrs)); # Converts an attrset to INI text, quoting values as expected by polybar. # This does no more fancy conversion. - toPolybarIni = generators.toINI { + toPolybarIni = lib.generators.toINI { mkKeyValue = key: value: let - quoted = v: if hasPrefix " " v || hasSuffix " " v then ''"${v}"'' else v; + quoted = v: if lib.hasPrefix " " v || lib.hasSuffix " " v then ''"${v}"'' else v; value' = - if isBool value then + if lib.isBool value then (if value then "true" else "false") - else if (isString value && key != "include-file") then + else if (lib.isString value && key != "include-file") then quoted value else toString value; @@ -73,7 +76,7 @@ let if isDeclarativeConfig then pkgs.writeText "polybar.conf" '' ${toPolybarIni cfg.config} - ${toPolybarIni (mapAttrs convertPolybarSection cfg.settings)} + ${toPolybarIni (lib.mapAttrs convertPolybarSection cfg.settings)} ${cfg.extraConfig} '' else @@ -83,7 +86,7 @@ in { options = { services.polybar = { - enable = mkEnableOption "Polybar status bar"; + enable = lib.mkEnableOption "Polybar status bar"; package = lib.mkPackageOption pkgs "polybar" { example = '' @@ -108,7 +111,7 @@ in See also {option}`services.polybar.settings` for a more nix-friendly format. ''; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { "bar/top" = { monitor = "\''${env:MONITOR:eDP1}"; @@ -177,7 +180,7 @@ in ``` ''; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { "module/volume" = { type = "internal/pulseaudio"; @@ -225,7 +228,7 @@ in (lib.hm.assertions.assertPlatform "services.polybar" pkgs lib.platforms.linux) ]; - meta.maintainers = with maintainers; [ h7x4 ]; + meta.maintainers = with lib.maintainers; [ h7x4 ]; home.packages = [ cfg.package ]; xdg.configFile."polybar/config.ini" = mkIf (configFile != null) { source = configFile; }; diff --git a/modules/services/poweralertd.nix b/modules/services/poweralertd.nix index 62bbc0d35..92eac20c1 100644 --- a/modules/services/poweralertd.nix +++ b/modules/services/poweralertd.nix @@ -4,35 +4,34 @@ pkgs, ... }: - -with lib; - let + inherit (lib) types; inherit (lib.strings) toJSON; + cfg = config.services.poweralertd; escapeSystemdExecArg = arg: let s = - if isPath arg then + if lib.isPath arg then "${arg}" - else if isString arg then + else if lib.isString arg then arg - else if isInt arg || isFloat arg || isDerivation arg then + else if lib.isInt arg || lib.isFloat arg || lib.isDerivation arg then toString arg else throw "escapeSystemdExecArg only allows strings, paths, numbers and derivations"; in - replaceStrings [ "%" "$" ] [ "%%" "$$" ] (toJSON s); - escapeSystemdExecArgs = concatMapStringsSep " " escapeSystemdExecArg; + lib.replaceStrings [ "%" "$" ] [ "%%" "$$" ] (toJSON s); + escapeSystemdExecArgs = lib.concatMapStringsSep " " escapeSystemdExecArg; in { - meta.maintainers = [ maintainers.thibautmarty ]; + meta.maintainers = [ lib.maintainers.thibautmarty ]; options.services.poweralertd = { - enable = mkEnableOption "the Upower-powered power alertd"; + enable = lib.mkEnableOption "the Upower-powered power alertd"; - extraArgs = mkOption { + extraArgs = lib.mkOption { type = with types; listOf str; default = [ ]; example = [ @@ -45,7 +44,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.poweralertd" pkgs lib.platforms.linux) ]; diff --git a/modules/services/pueue.nix b/modules/services/pueue.nix index 9462fd91c..620b15af1 100644 --- a/modules/services/pueue.nix +++ b/modules/services/pueue.nix @@ -4,9 +4,6 @@ pkgs, ... }: - -with lib; - let cfg = config.services.pueue; @@ -15,17 +12,17 @@ let in { - meta.maintainers = [ maintainers.AndersonTorres ]; + meta.maintainers = [ lib.maintainers.AndersonTorres ]; options.services.pueue = { - enable = mkEnableOption "Pueue, CLI process scheduler and manager"; + enable = lib.mkEnableOption "Pueue, CLI process scheduler and manager"; - package = mkPackageOption pkgs "pueue" { nullable = true; }; + package = lib.mkPackageOption pkgs "pueue" { nullable = true; }; - settings = mkOption { + settings = lib.mkOption { type = yamlFormat.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { daemon = { default_parallel_tasks = 2; @@ -39,8 +36,10 @@ in }; }; - config = mkIf cfg.enable { - assertions = [ (hm.assertions.assertPlatform "services.pueue" pkgs platforms.linux) ]; + config = lib.mkIf cfg.enable { + assertions = [ + (lib.hm.assertions.assertPlatform "services.pueue" pkgs lib.platforms.linux) + ]; home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; diff --git a/modules/services/pulseeffects.nix b/modules/services/pulseeffects.nix index 4f8d8b3fe..16c36d408 100644 --- a/modules/services/pulseeffects.nix +++ b/modules/services/pulseeffects.nix @@ -4,21 +4,18 @@ pkgs, ... }: - -with lib; - let cfg = config.services.pulseeffects; - presetOpts = optionalString (cfg.preset != "") "--load-preset ${cfg.preset}"; + presetOpts = lib.optionalString (cfg.preset != "") "--load-preset ${cfg.preset}"; in { - meta.maintainers = [ hm.maintainers.jonringer ]; + meta.maintainers = [ lib.hm.maintainers.jonringer ]; options.services.pulseeffects = { - enable = mkEnableOption '' + enable = lib.mkEnableOption '' Pulseeffects daemon Note, it is necessary to add ```nix @@ -26,15 +23,15 @@ in ``` to your system configuration for the daemon to work correctly''; - package = mkOption { - type = types.package; + package = lib.mkOption { + type = lib.types.package; default = pkgs.pulseeffects-legacy; - defaultText = literalExpression "pkgs.pulseeffects-legacy"; + defaultText = lib.literalExpression "pkgs.pulseeffects-legacy"; description = "Pulseeffects package to use."; }; - preset = mkOption { - type = types.str; + preset = lib.mkOption { + type = lib.types.str; default = ""; description = '' Which preset to use when starting pulseeffects. @@ -43,7 +40,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.pulseeffects" pkgs lib.platforms.linux) ]; diff --git a/modules/services/random-background.nix b/modules/services/random-background.nix index 04b202499..d08bf3b0a 100644 --- a/modules/services/random-background.nix +++ b/modules/services/random-background.nix @@ -5,9 +5,8 @@ ... }: -with lib; - let + inherit (lib) mkOption types; cfg = config.services.random-background; @@ -22,11 +21,11 @@ let in { - meta.maintainers = [ maintainers.rycee ]; + meta.maintainers = [ lib.maintainers.rycee ]; options = { services.random-background = { - enable = mkEnableOption "" // { + enable = lib.mkEnableOption "" // { description = '' Whether to enable random desktop background. @@ -83,44 +82,46 @@ in }; }; - config = mkIf cfg.enable (mkMerge ([ - { - assertions = [ - (hm.assertions.assertPlatform "services.random-background" pkgs platforms.linux) - ]; + config = lib.mkIf cfg.enable ( + lib.mkMerge [ + { + assertions = [ + (lib.hm.assertions.assertPlatform "services.random-background" pkgs lib.platforms.linux) + ]; - systemd.user.services.random-background = { - Unit = { - Description = "Set random desktop background using feh"; - After = [ "graphical-session.target" ]; - PartOf = [ "graphical-session.target" ]; - }; + systemd.user.services.random-background = { + Unit = { + Description = "Set random desktop background using feh"; + After = [ "graphical-session.target" ]; + PartOf = [ "graphical-session.target" ]; + }; - Service = { - Type = "oneshot"; - ExecStart = "${pkgs.feh}/bin/feh ${flags} ${cfg.imageDirectory}"; - IOSchedulingClass = "idle"; - }; + Service = { + Type = "oneshot"; + ExecStart = "${pkgs.feh}/bin/feh ${flags} ${cfg.imageDirectory}"; + IOSchedulingClass = "idle"; + }; - Install = { - WantedBy = [ "graphical-session.target" ]; - }; - }; - } - (mkIf (cfg.interval != null) { - systemd.user.timers.random-background = { - Unit = { - Description = "Set random desktop background using feh"; + Install = { + WantedBy = [ "graphical-session.target" ]; + }; }; + } + (lib.mkIf (cfg.interval != null) { + systemd.user.timers.random-background = { + Unit = { + Description = "Set random desktop background using feh"; + }; - Timer = { - OnUnitActiveSec = cfg.interval; - }; + Timer = { + OnUnitActiveSec = cfg.interval; + }; - Install = { - WantedBy = [ "timers.target" ]; + Install = { + WantedBy = [ "timers.target" ]; + }; }; - }; - }) - ])); + }) + ] + ); } diff --git a/modules/services/recoll.nix b/modules/services/recoll.nix index 4266200c5..4548aa2a2 100644 --- a/modules/services/recoll.nix +++ b/modules/services/recoll.nix @@ -6,10 +6,16 @@ ... }: -with lib; - # TODO: Fix the formatting of the resulting config. let + inherit (lib) + generators + isAttrs + literalExpression + mkOption + types + ; + cfg = config.services.recoll; # The key-value generator for Recoll config format. For future references, @@ -18,15 +24,15 @@ let mkRecollConfKeyValue = generators.mkKeyValueDefault { mkValueString = let - mkQuoted = v: ''"${escape [ ''"'' ] v}"''; + mkQuoted = v: ''"${lib.escape [ ''"'' ] v}"''; in v: if v == true then "1" else if v == false then "0" - else if isList v then - concatMapStringsSep " " mkQuoted v + else if lib.isList v then + lib.concatMapStringsSep " " mkQuoted v else generators.mkValueStringDefault { } v; } " = "; @@ -43,7 +49,7 @@ let inherit listsAsDuplicateKeys; mkKeyValue = mkRecollConfKeyValue; }; - mkSectionName = name: strings.escape [ "[" "]" ] name; + mkSectionName = name: lib.strings.escape [ "[" "]" ] name; convert = k: v: if isAttrs v then @@ -58,11 +64,11 @@ let # There's a possibility of attributes with attrsets overriding other # top-level attributes with non-attrsets so we're forcing the attrsets to # come last. - _config = mapAttrsToList convert (filterAttrs (k: v: !isAttrs v) attr); - _config' = mapAttrsToList convert (filterAttrs (k: v: isAttrs v) attr); + _config = lib.mapAttrsToList convert (lib.filterAttrs (k: v: !isAttrs v) attr); + _config' = lib.mapAttrsToList convert (lib.filterAttrs (k: v: isAttrs v) attr); config = _config ++ _config'; in - concatStringsSep "\n" config; + lib.concatStringsSep "\n" config; # A specific type for Recoll config format. Taken from `pkgs.formats` # implementation from nixpkgs. See the 'Nix-representable formats' from the @@ -97,10 +103,10 @@ let settingsFormat = recollConfFormat { }; in { - meta.maintainers = [ maintainers.foo-dogsquared ]; + meta.maintainers = [ lib.maintainers.foo-dogsquared ]; options.services.recoll = { - enable = mkEnableOption "Recoll file index service"; + enable = lib.mkEnableOption "Recoll file index service"; package = mkOption { type = types.package; @@ -159,7 +165,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.recoll" pkgs lib.platforms.linux) ]; @@ -185,7 +191,7 @@ in Service = { ExecStart = "${cfg.package}/bin/recollindex"; - Environment = [ "RECOLL_CONFDIR=${escapeShellArg cfg.configDir}" ]; + Environment = [ "RECOLL_CONFDIR=${lib.escapeShellArg cfg.configDir}" ]; }; }; diff --git a/modules/services/redshift-gammastep/gammastep.nix b/modules/services/redshift-gammastep/gammastep.nix index 3955116e9..340c776c7 100644 --- a/modules/services/redshift-gammastep/gammastep.nix +++ b/modules/services/redshift-gammastep/gammastep.nix @@ -4,9 +4,6 @@ pkgs, ... }: - -with lib; - let commonOptions = import ./lib/options.nix { inherit config lib pkgs; @@ -27,5 +24,5 @@ in { inherit (commonOptions) imports meta; options.services.gammastep = commonOptions.options; - config = mkIf config.services.gammastep.enable commonOptions.config; + config = lib.mkIf config.services.gammastep.enable commonOptions.config; } diff --git a/modules/services/redshift-gammastep/lib/options.nix b/modules/services/redshift-gammastep/lib/options.nix index cad157d2b..60c8fa24a 100644 --- a/modules/services/redshift-gammastep/lib/options.nix +++ b/modules/services/redshift-gammastep/lib/options.nix @@ -12,17 +12,15 @@ xdgConfigFilePath, serviceDocumentation, }: - -with lib; - let + inherit (lib) mkOption mkIf types; cfg = config.services.${moduleName}; settingsFormat = pkgs.formats.ini { }; in { - meta.maintainers = with maintainers; [ + meta.maintainers = with lib.maintainers; [ rycee thiagokokada ]; @@ -31,7 +29,7 @@ in let mkRenamed = old: new: - mkRenamedOptionModule + lib.mkRenamedOptionModule ( [ "services" @@ -48,7 +46,7 @@ in ]; in [ - (mkRemovedOptionModule [ "services" moduleName "extraOptions" ] + (lib.mkRemovedOptionModule [ "services" moduleName "extraOptions" ] "All ${programName} configuration is now available through services.${moduleName}.settings instead." ) (mkRenamed [ "brightness" "day" ] "brightness-day") @@ -56,7 +54,7 @@ in ]; options = { - enable = mkEnableOption programName; + enable = lib.mkEnableOption programName; dawnTime = mkOption { type = types.nullOr types.str; @@ -134,13 +132,13 @@ in package = mkOption { type = types.package; default = defaultPackage; - defaultText = literalExpression examplePackage; + defaultText = lib.literalExpression examplePackage; description = '' ${programName} derivation to use. ''; }; - enableVerboseLogging = mkEnableOption "verbose service logging"; + enableVerboseLogging = lib.mkEnableOption "verbose service logging"; tray = mkOption { type = types.bool; @@ -154,7 +152,7 @@ in settings = mkOption { type = types.submodule { freeformType = settingsFormat.type; }; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { ${mainSection} = { adjustment-method = "randr"; @@ -174,7 +172,7 @@ in config = { assertions = [ - (hm.assertions.assertPlatform "services.${moduleName}" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "services.${moduleName}" pkgs lib.platforms.linux) { assertion = @@ -238,7 +236,7 @@ in configFullPath = config.xdg.configHome + "/${xdgConfigFilePath}"; in "${cfg.package}/bin/${command} " - + cli.toGNUCommandLineShell { } { + + lib.cli.toGNUCommandLineShell { } { v = cfg.enableVerboseLogging; c = configFullPath; }; diff --git a/modules/services/redshift-gammastep/redshift.nix b/modules/services/redshift-gammastep/redshift.nix index d752e9383..5afceca2f 100644 --- a/modules/services/redshift-gammastep/redshift.nix +++ b/modules/services/redshift-gammastep/redshift.nix @@ -4,9 +4,6 @@ pkgs, ... }: - -with lib; - let commonOptions = import ./lib/options.nix { inherit config lib pkgs; @@ -26,5 +23,5 @@ in { inherit (commonOptions) imports meta; options.services.redshift = commonOptions.options; - config = mkIf config.services.redshift.enable commonOptions.config; + config = lib.mkIf config.services.redshift.enable commonOptions.config; } diff --git a/modules/services/rsibreak.nix b/modules/services/rsibreak.nix index 108bf3f13..d8d3abbb6 100644 --- a/modules/services/rsibreak.nix +++ b/modules/services/rsibreak.nix @@ -5,8 +5,6 @@ ... }: -with lib; - let cfg = config.services.rsibreak; @@ -15,11 +13,11 @@ in { options.services.rsibreak = { - enable = mkEnableOption "rsibreak"; + enable = lib.mkEnableOption "rsibreak"; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.rsibreak" pkgs lib.platforms.linux) ]; diff --git a/modules/services/safeeyes.nix b/modules/services/safeeyes.nix index 23b87568b..a21737246 100644 --- a/modules/services/safeeyes.nix +++ b/modules/services/safeeyes.nix @@ -5,27 +5,25 @@ ... }: -with lib; - let cfg = config.services.safeeyes; in { - meta.maintainers = [ hm.maintainers.rosuavio ]; + meta.maintainers = [ lib.hm.maintainers.rosuavio ]; options = { services.safeeyes = { - enable = mkEnableOption "The Safe Eyes OSGI service"; + enable = lib.mkEnableOption "The Safe Eyes OSGI service"; - package = mkPackageOption pkgs "safeeyes" { }; + package = lib.mkPackageOption pkgs "safeeyes" { }; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ - (hm.assertions.assertPlatform "services.safeeyes" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "services.safeeyes" pkgs lib.platforms.linux) ]; home.packages = [ cfg.package ]; @@ -41,7 +39,7 @@ in }; Service = { - ExecStart = getExe pkgs.safeeyes; + ExecStart = lib.getExe pkgs.safeeyes; Restart = "on-failure"; RestartSec = 3; }; diff --git a/modules/services/screen-locker.nix b/modules/services/screen-locker.nix index 3b74bd58d..20ceb6a50 100644 --- a/modules/services/screen-locker.nix +++ b/modules/services/screen-locker.nix @@ -5,17 +5,21 @@ ... }: -with lib; - let + inherit (lib) + mkIf + mkRenamedOptionModule + mkOption + types + ; cfg = config.services.screen-locker; in { meta.maintainers = [ - hm.maintainers.jrobsonchase - hm.maintainers.rszamszur + lib.hm.maintainers.jrobsonchase + lib.hm.maintainers.rszamszur ]; imports = @@ -45,7 +49,7 @@ in ]; options.services.screen-locker = { - enable = mkEnableOption "screen locker for X session"; + enable = lib.mkEnableOption "screen locker for X session"; lockCmd = mkOption { type = types.str; @@ -136,67 +140,69 @@ in }; }; - config = mkIf cfg.enable (mkMerge [ - { - assertions = [ - (lib.hm.assertions.assertPlatform "services.screen-locker" pkgs lib.platforms.linux) - ]; + config = mkIf cfg.enable ( + lib.mkMerge [ + { + assertions = [ + (lib.hm.assertions.assertPlatform "services.screen-locker" pkgs lib.platforms.linux) + ]; - systemd.user.services.xss-lock = { - Unit = { - Description = "xss-lock, session locker service"; - After = [ "graphical-session.target" ]; - PartOf = [ "graphical-session.target" ]; - }; + systemd.user.services.xss-lock = { + Unit = { + Description = "xss-lock, session locker service"; + After = [ "graphical-session.target" ]; + PartOf = [ "graphical-session.target" ]; + }; - Install = { - WantedBy = [ "graphical-session.target" ]; - }; + Install = { + WantedBy = [ "graphical-session.target" ]; + }; - Service = { - ExecStart = concatStringsSep " " ( - [ - "${cfg.xss-lock.package}/bin/xss-lock" - "-s \${XDG_SESSION_ID}" - ] - ++ cfg.xss-lock.extraOptions - ++ [ "-- ${cfg.lockCmd}" ] - ); - Environment = cfg.lockCmdEnv; - Restart = "always"; - }; - }; - } - (mkIf (!cfg.xautolock.enable) { - systemd.user.services.xss-lock.Service.ExecStartPre = "${pkgs.xorg.xset}/bin/xset s ${ - toString (cfg.inactiveInterval * 60) - } ${toString cfg.xss-lock.screensaverCycle}"; - }) - (mkIf cfg.xautolock.enable { - systemd.user.services.xautolock-session = { - Unit = { - Description = "xautolock, session locker service"; - After = [ "graphical-session.target" ]; - PartOf = [ "graphical-session.target" ]; + Service = { + ExecStart = lib.concatStringsSep " " ( + [ + "${cfg.xss-lock.package}/bin/xss-lock" + "-s \${XDG_SESSION_ID}" + ] + ++ cfg.xss-lock.extraOptions + ++ [ "-- ${cfg.lockCmd}" ] + ); + Environment = cfg.lockCmdEnv; + Restart = "always"; + }; }; + } + (mkIf (!cfg.xautolock.enable) { + systemd.user.services.xss-lock.Service.ExecStartPre = "${pkgs.xorg.xset}/bin/xset s ${ + toString (cfg.inactiveInterval * 60) + } ${toString cfg.xss-lock.screensaverCycle}"; + }) + (mkIf cfg.xautolock.enable { + systemd.user.services.xautolock-session = { + Unit = { + Description = "xautolock, session locker service"; + After = [ "graphical-session.target" ]; + PartOf = [ "graphical-session.target" ]; + }; - Install = { - WantedBy = [ "graphical-session.target" ]; - }; + Install = { + WantedBy = [ "graphical-session.target" ]; + }; - Service = { - ExecStart = concatStringsSep " " ( - [ - "${cfg.xautolock.package}/bin/xautolock" - "-time ${toString cfg.inactiveInterval}" - "-locker '${pkgs.systemd}/bin/loginctl lock-session \${XDG_SESSION_ID}'" - ] - ++ optional cfg.xautolock.detectSleep "-detectsleep" - ++ cfg.xautolock.extraOptions - ); - Restart = "always"; + Service = { + ExecStart = lib.concatStringsSep " " ( + [ + "${cfg.xautolock.package}/bin/xautolock" + "-time ${toString cfg.inactiveInterval}" + "-locker '${pkgs.systemd}/bin/loginctl lock-session \${XDG_SESSION_ID}'" + ] + ++ lib.optional cfg.xautolock.detectSleep "-detectsleep" + ++ cfg.xautolock.extraOptions + ); + Restart = "always"; + }; }; - }; - }) - ]); + }) + ] + ); } diff --git a/modules/services/sctd.nix b/modules/services/sctd.nix index f047e707a..3b70f339b 100644 --- a/modules/services/sctd.nix +++ b/modules/services/sctd.nix @@ -5,17 +5,15 @@ ... }: -with lib; - { - meta.maintainers = [ maintainers.somasis ]; + meta.maintainers = [ lib.maintainers.somasis ]; options = { services.sctd = { - enable = mkEnableOption "sctd"; + enable = lib.mkEnableOption "sctd"; - baseTemperature = mkOption { - type = types.ints.between 2500 9000; + baseTemperature = lib.mkOption { + type = lib.types.ints.between 2500 9000; default = 4500; description = '' The base color temperature used by sctd, which should be between 2500 and 9000. @@ -27,8 +25,8 @@ with lib; }; }; - config = mkIf config.services.sctd.enable { - assertions = [ (hm.assertions.assertPlatform "services.sctd" pkgs platforms.linux) ]; + config = lib.mkIf config.services.sctd.enable { + assertions = [ (lib.hm.assertions.assertPlatform "services.sctd" pkgs lib.platforms.linux) ]; systemd.user.services.sctd = { Unit = { diff --git a/modules/services/signaturepdf.nix b/modules/services/signaturepdf.nix index 8bdd4a88a..5aa33ece9 100644 --- a/modules/services/signaturepdf.nix +++ b/modules/services/signaturepdf.nix @@ -6,6 +6,8 @@ }: let + inherit (lib) mkOption types; + cfg = config.services.signaturepdf; extraConfigToArgs = extraConfig: @@ -19,8 +21,8 @@ in { meta.maintainers = [ lib.maintainers.DamienCassou ]; - options.services.signaturepdf = with lib; { - enable = mkEnableOption "signaturepdf; signing, organizing, editing metadatas or compressing PDFs"; + options.services.signaturepdf = { + enable = lib.mkEnableOption "signaturepdf; signing, organizing, editing metadatas or compressing PDFs"; package = mkOption { type = types.package; diff --git a/modules/services/snixembed.nix b/modules/services/snixembed.nix index f722b9912..e9b1572ee 100644 --- a/modules/services/snixembed.nix +++ b/modules/services/snixembed.nix @@ -5,22 +5,20 @@ ... }: -with lib; - let cfg = config.services.snixembed; in { - meta.maintainers = [ maintainers.DamienCassou ]; + meta.maintainers = [ lib.maintainers.DamienCassou ]; options = { services.snixembed = { - enable = mkEnableOption "snixembed: proxy StatusNotifierItems as XEmbedded systemtray-spec icons"; + enable = lib.mkEnableOption "snixembed: proxy StatusNotifierItems as XEmbedded systemtray-spec icons"; - package = mkPackageOption pkgs "snixembed" { }; + package = lib.mkPackageOption pkgs "snixembed" { }; - beforeUnits = mkOption { - type = with types; listOf str; + beforeUnits = lib.mkOption { + type = with lib.types; listOf str; default = [ ]; example = [ "safeeyes.service" ]; description = '' @@ -30,9 +28,9 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ - (hm.assertions.assertPlatform "services.snixembed" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "services.snixembed" pkgs lib.platforms.linux) ]; systemd.user.services.snixembed = { @@ -47,7 +45,7 @@ in }; Service = { - ExecStart = getExe pkgs.snixembed; + ExecStart = lib.getExe pkgs.snixembed; Restart = "on-failure"; RestartSec = 3; }; diff --git a/modules/services/spotifyd.nix b/modules/services/spotifyd.nix index 7c7d5f2da..866cfbd79 100644 --- a/modules/services/spotifyd.nix +++ b/modules/services/spotifyd.nix @@ -5,9 +5,8 @@ ... }: -with lib; - let + inherit (lib) literalExpression; cfg = config.services.spotifyd; @@ -18,10 +17,10 @@ let in { options.services.spotifyd = { - enable = mkEnableOption "SpotifyD connect"; + enable = lib.mkEnableOption "SpotifyD connect"; - package = mkOption { - type = types.package; + package = lib.mkOption { + type = lib.types.package; default = pkgs.spotifyd; defaultText = literalExpression "pkgs.spotifyd"; example = literalExpression "(pkgs.spotifyd.override { withKeyring = true; })"; @@ -31,7 +30,7 @@ in ''; }; - settings = mkOption { + settings = lib.mkOption { type = tomlFormat.type; default = { }; description = "Configuration for spotifyd"; @@ -47,7 +46,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.spotifyd" pkgs lib.platforms.linux) ]; diff --git a/modules/services/ssh-agent.nix b/modules/services/ssh-agent.nix index a0b51e859..54a05ba59 100644 --- a/modules/services/ssh-agent.nix +++ b/modules/services/ssh-agent.nix @@ -1,6 +1,5 @@ { config, - options, lib, pkgs, ... diff --git a/modules/services/stalonetray.nix b/modules/services/stalonetray.nix index b7442eee2..037555063 100644 --- a/modules/services/stalonetray.nix +++ b/modules/services/stalonetray.nix @@ -5,9 +5,13 @@ ... }: -with lib; - let + inherit (lib) + mkIf + mkOption + types + literalExpression + ; cfg = config.services.stalonetray; @@ -15,7 +19,7 @@ in { options = { services.stalonetray = { - enable = mkEnableOption "Stalonetray system tray"; + enable = lib.mkEnableOption "Stalonetray system tray"; package = mkOption { default = pkgs.stalonetray; @@ -55,52 +59,54 @@ in }; }; - config = mkIf cfg.enable (mkMerge [ - { - assertions = [ - (hm.assertions.assertPlatform "services.stalonetray" pkgs platforms.linux) - ]; + config = mkIf cfg.enable ( + lib.mkMerge [ + { + assertions = [ + (lib.hm.assertions.assertPlatform "services.stalonetray" pkgs lib.platforms.linux) + ]; - home.packages = [ cfg.package ]; + home.packages = [ cfg.package ]; - systemd.user.services.stalonetray = { - Unit = { - Description = "Stalonetray system tray"; - PartOf = [ "tray.target" ]; + systemd.user.services.stalonetray = { + Unit = { + Description = "Stalonetray system tray"; + PartOf = [ "tray.target" ]; + }; + + Install = { + WantedBy = [ "tray.target" ]; + }; + + Service = { + ExecStart = "${cfg.package}/bin/stalonetray"; + Restart = "on-failure"; + }; }; + } - Install = { - WantedBy = [ "tray.target" ]; - }; + (mkIf (cfg.config != { }) { + xdg.configFile."stalonetrayrc".text = + let + valueToString = + v: + if lib.isBool v then + (if v then "true" else "false") + else if (v == null) then + "none" + else + ''"${toString v}"''; + in + lib.concatStrings ( + lib.mapAttrsToList (k: v: '' + ${k} ${valueToString v} + '') cfg.config + ); + }) - Service = { - ExecStart = "${cfg.package}/bin/stalonetray"; - Restart = "on-failure"; - }; - }; - } - - (mkIf (cfg.config != { }) { - xdg.configFile."stalonetrayrc".text = - let - valueToString = - v: - if isBool v then - (if v then "true" else "false") - else if (v == null) then - "none" - else - ''"${toString v}"''; - in - concatStrings ( - mapAttrsToList (k: v: '' - ${k} ${valueToString v} - '') cfg.config - ); - }) - - (mkIf (cfg.extraConfig != "") { - xdg.configFile."stalonetrayrc".text = cfg.extraConfig; - }) - ]); + (mkIf (cfg.extraConfig != "") { + xdg.configFile."stalonetrayrc".text = cfg.extraConfig; + }) + ] + ); } diff --git a/modules/services/status-notifier-watcher.nix b/modules/services/status-notifier-watcher.nix index 52b34f25e..f90b1ae2f 100644 --- a/modules/services/status-notifier-watcher.nix +++ b/modules/services/status-notifier-watcher.nix @@ -5,31 +5,27 @@ ... }: -with lib; - let - cfg = config.services.status-notifier-watcher; - in { - meta.maintainers = [ hm.maintainers.pltanton ]; + meta.maintainers = [ lib.hm.maintainers.pltanton ]; options = { services.status-notifier-watcher = { - enable = mkEnableOption "Status Notifier Watcher"; + enable = lib.mkEnableOption "Status Notifier Watcher"; - package = mkOption { + package = lib.mkOption { default = pkgs.haskellPackages.status-notifier-item; - defaultText = literalExpression "pkgs.haskellPackages.status-notifier-item"; - type = types.package; - example = literalExpression "pkgs.haskellPackages.status-notifier-item"; + defaultText = lib.literalExpression "pkgs.haskellPackages.status-notifier-item"; + type = lib.types.package; + example = lib.literalExpression "pkgs.haskellPackages.status-notifier-item"; description = "The package to use for the status notifier watcher binary."; }; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.status-notifier-watcher" pkgs lib.platforms.linux) ]; diff --git a/modules/services/swayidle.nix b/modules/services/swayidle.nix index 8a2be0137..cdf54b193 100644 --- a/modules/services/swayidle.nix +++ b/modules/services/swayidle.nix @@ -5,15 +5,18 @@ ... }: -with lib; - let + inherit (lib) + mkOption + types + literalExpression + ; cfg = config.services.swayidle; in { - meta.maintainers = [ maintainers.c0deaddict ]; + meta.maintainers = [ lib.maintainers.c0deaddict ]; options.services.swayidle = let @@ -64,7 +67,7 @@ in in { - enable = mkEnableOption "idle manager for Wayland"; + enable = lib.mkEnableOption "idle manager for Wayland"; package = lib.mkPackageOption pkgs "swayidle" { }; @@ -110,9 +113,9 @@ in }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ - (hm.assertions.assertPlatform "services.swayidle" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "services.swayidle" pkgs lib.platforms.linux) ]; systemd.user.services.swayidle = { @@ -128,7 +131,7 @@ in Type = "simple"; Restart = "always"; # swayidle executes commands using "sh -c", so the PATH needs to contain a shell. - Environment = [ "PATH=${makeBinPath [ pkgs.bash ]}" ]; + Environment = [ "PATH=${lib.makeBinPath [ pkgs.bash ]}" ]; ExecStart = let mkTimeout = @@ -138,7 +141,7 @@ in (toString t.timeout) t.command ] - ++ optionals (t.resumeCommand != null) [ + ++ lib.optionals (t.resumeCommand != null) [ "resume" t.resumeCommand ]; @@ -148,9 +151,10 @@ in e.command ]; - args = cfg.extraArgs ++ (concatMap mkTimeout cfg.timeouts) ++ (concatMap mkEvent cfg.events); + args = + cfg.extraArgs ++ (lib.concatMap mkTimeout cfg.timeouts) ++ (lib.concatMap mkEvent cfg.events); in - "${getExe cfg.package} ${escapeShellArgs args}"; + "${lib.getExe cfg.package} ${lib.escapeShellArgs args}"; }; Install = { diff --git a/modules/services/swayosd.nix b/modules/services/swayosd.nix index d2f0defe7..ac766cf23 100644 --- a/modules/services/swayosd.nix +++ b/modules/services/swayosd.nix @@ -5,22 +5,25 @@ ... }: -with lib; - let + inherit (lib) + mkOption + types + optionalString + ; cfg = config.services.swayosd; in { - meta.maintainers = [ hm.maintainers.pltanton ]; + meta.maintainers = [ lib.hm.maintainers.pltanton ]; options.services.swayosd = { - enable = mkEnableOption '' + enable = lib.mkEnableOption '' swayosd, a GTK based on screen display for keyboard shortcuts like caps-lock and volume''; - package = mkPackageOption pkgs "swayosd" { }; + package = lib.mkPackageOption pkgs "swayosd" { }; topMargin = mkOption { type = types.nullOr ( @@ -53,9 +56,9 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ - (hm.assertions.assertPlatform "services.swayosd" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "services.swayosd" pkgs lib.platforms.linux) ]; home.packages = [ cfg.package ]; @@ -77,7 +80,7 @@ in ExecStart = "${cfg.package}/bin/swayosd-server" + (optionalString (cfg.display != null) " --display ${cfg.display}") - + (optionalString (cfg.stylePath != null) " --style ${escapeShellArg cfg.stylePath}") + + (optionalString (cfg.stylePath != null) " --style ${lib.escapeShellArg cfg.stylePath}") + (optionalString (cfg.topMargin != null) " --top-margin ${toString cfg.topMargin}"); Restart = "always"; RestartSec = "2s"; diff --git a/modules/services/sxhkd.nix b/modules/services/sxhkd.nix index bc80d4f51..c0a2d64c8 100644 --- a/modules/services/sxhkd.nix +++ b/modules/services/sxhkd.nix @@ -5,16 +5,19 @@ ... }: -with lib; - let + inherit (lib) + mkOption + types + literalExpression + ; cfg = config.services.sxhkd; - keybindingsStr = concatStringsSep "\n" ( - mapAttrsToList ( + keybindingsStr = lib.concatStringsSep "\n" ( + lib.mapAttrsToList ( hotkey: command: - optionalString (command != null) '' + lib.optionalString (command != null) '' ${hotkey} ${command} '' @@ -24,7 +27,7 @@ let in { imports = [ - (mkRemovedOptionModule [ + (lib.mkRemovedOptionModule [ "services" "sxhkd" "extraPath" @@ -32,7 +35,7 @@ in ]; options.services.sxhkd = { - enable = mkEnableOption "simple X hotkey daemon"; + enable = lib.mkEnableOption "simple X hotkey daemon"; package = mkOption { type = types.package; @@ -79,14 +82,14 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.sxhkd" pkgs lib.platforms.linux) ]; home.packages = [ cfg.package ]; - xdg.configFile."sxhkd/sxhkdrc".text = concatStringsSep "\n" [ + xdg.configFile."sxhkd/sxhkdrc".text = lib.concatStringsSep "\n" [ keybindingsStr cfg.extraConfig ]; diff --git a/modules/services/syncthing.nix b/modules/services/syncthing.nix index c3996d319..3fb605352 100644 --- a/modules/services/syncthing.nix +++ b/modules/services/syncthing.nix @@ -8,8 +8,6 @@ let inherit (lib) literalExpression mkOption - mkEnableOption - mkPackageOption types ; @@ -226,7 +224,7 @@ in options = { services.syncthing = { - enable = mkEnableOption '' + enable = lib.mkEnableOption '' Syncthing, a self-hosted open-source alternative to Dropbox and Bittorrent Sync. ''; @@ -408,7 +406,7 @@ in will be reverted on restart if [overrideFolders](#opt-services.syncthing.overrideFolders) is enabled. ''; - example = literalExpression '' + example = lib.literalExpression '' { "/home/user/sync" = { id = "syncme"; @@ -492,7 +490,7 @@ in There are 4 different types of versioning with different parameters. See . ''; - example = literalExpression '' + example = lib.literalExpression '' [ { versioning = { @@ -631,7 +629,7 @@ in ''; }; - package = mkPackageOption pkgs "syncthing" { }; + package = lib.mkPackageOption pkgs "syncthing" { }; tray = mkOption { type = diff --git a/modules/services/systembus-notify.nix b/modules/services/systembus-notify.nix index 77d4717e8..d73cd7828 100644 --- a/modules/services/systembus-notify.nix +++ b/modules/services/systembus-notify.nix @@ -5,20 +5,18 @@ ... }: -with lib; - { - meta.maintainers = [ maintainers.asymmetric ]; + meta.maintainers = [ lib.maintainers.asymmetric ]; options = { services.systembus-notify = { - enable = mkEnableOption "systembus-notify - system bus notification daemon"; + enable = lib.mkEnableOption "systembus-notify - system bus notification daemon"; }; }; - config = mkIf config.services.systembus-notify.enable { + config = lib.mkIf config.services.systembus-notify.enable { assertions = [ - (hm.assertions.assertPlatform "services.systembus-notify" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "services.systembus-notify" pkgs lib.platforms.linux) ]; systemd.user.services.systembus-notify = { diff --git a/modules/services/taffybar.nix b/modules/services/taffybar.nix index 6bb4aa2a3..1d9a68974 100644 --- a/modules/services/taffybar.nix +++ b/modules/services/taffybar.nix @@ -5,33 +5,31 @@ ... }: -with lib; - let cfg = config.services.taffybar; in { - meta.maintainers = [ maintainers.rycee ]; + meta.maintainers = [ lib.maintainers.rycee ]; options = { services.taffybar = { - enable = mkEnableOption "Taffybar"; + enable = lib.mkEnableOption "Taffybar"; - package = mkOption { + package = lib.mkOption { default = pkgs.taffybar; - defaultText = literalExpression "pkgs.taffybar"; - type = types.package; - example = literalExpression "pkgs.taffybar"; + defaultText = lib.literalExpression "pkgs.taffybar"; + type = lib.types.package; + example = lib.literalExpression "pkgs.taffybar"; description = "The package to use for the Taffybar binary."; }; }; }; - config = mkIf config.services.taffybar.enable { + config = lib.mkIf config.services.taffybar.enable { assertions = [ - (hm.assertions.assertPlatform "services.taffybar" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "services.taffybar" pkgs lib.platforms.linux) ]; systemd.user.services.taffybar = { diff --git a/modules/services/tahoe-lafs.nix b/modules/services/tahoe-lafs.nix index f4b2f7629..24ade1bf5 100644 --- a/modules/services/tahoe-lafs.nix +++ b/modules/services/tahoe-lafs.nix @@ -5,20 +5,18 @@ ... }: -with lib; - { - meta.maintainers = [ maintainers.rycee ]; + meta.maintainers = [ lib.maintainers.rycee ]; options = { services.tahoe-lafs = { - enable = mkEnableOption "Tahoe-LAFS"; + enable = lib.mkEnableOption "Tahoe-LAFS"; }; }; - config = mkIf config.services.tahoe-lafs.enable { + config = lib.mkIf config.services.tahoe-lafs.enable { assertions = [ - (hm.assertions.assertPlatform "services.tahoe-lafs" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "services.tahoe-lafs" pkgs lib.platforms.linux) ]; systemd.user.services.tahoe-lafs = { diff --git a/modules/services/taskwarrior-sync.nix b/modules/services/taskwarrior-sync.nix index 2da9350b7..959019b87 100644 --- a/modules/services/taskwarrior-sync.nix +++ b/modules/services/taskwarrior-sync.nix @@ -5,26 +5,24 @@ ... }: -with lib; - let cfg = config.services.taskwarrior-sync; in { - meta.maintainers = with maintainers; [ + meta.maintainers = with lib.maintainers; [ euxane minijackson ]; options.services.taskwarrior-sync = { - enable = mkEnableOption "Taskwarrior periodic sync"; + enable = lib.mkEnableOption "Taskwarrior periodic sync"; - package = mkPackageOption pkgs "taskwarrior" { example = "pkgs.taskwarrior3"; }; + package = lib.mkPackageOption pkgs "taskwarrior" { example = "pkgs.taskwarrior3"; }; - frequency = mkOption { - type = types.str; + frequency = lib.mkOption { + type = lib.types.str; default = "*:0/5"; description = '' How often to run `taskwarrior sync`. This @@ -36,7 +34,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.taskwarrior-sync" pkgs lib.platforms.linux) ]; diff --git a/modules/services/trayer.nix b/modules/services/trayer.nix index 0fbac6edf..fb84980a0 100644 --- a/modules/services/trayer.nix +++ b/modules/services/trayer.nix @@ -5,9 +5,8 @@ ... }: -with lib; - let + inherit (lib) types; boolTrue = { type = types.bool; @@ -115,35 +114,35 @@ let in { - meta.maintainers = [ hm.maintainers.mager ]; + meta.maintainers = [ lib.hm.maintainers.mager ]; options = { services.trayer = { - enable = mkEnableOption "trayer, the lightweight GTK2+ systray for UNIX desktops"; + enable = lib.mkEnableOption "trayer, the lightweight GTK2+ systray for UNIX desktops"; - package = mkOption { + package = lib.mkOption { default = pkgs.trayer; - defaultText = literalExpression "pkgs.trayer"; + defaultText = lib.literalExpression "pkgs.trayer"; type = types.package; - example = literalExpression "pkgs.trayer"; + example = lib.literalExpression "pkgs.trayer"; description = "The package to use for the trayer binary."; }; - settings = mkOption { + settings = lib.mkOption { type = with types; attrsOf (nullOr (either str (either bool int))); description = '' Trayer configuration as a set of attributes. Further details can be found in [trayer's README](https://github.com/sargon/trayer-srg/blob/master/README). - ${concatStringsSep "\n" ( - mapAttrsToList (n: v: '' + ${lib.concatStringsSep "\n" ( + lib.mapAttrsToList (n: v: '' {var}`${n}` : ${v.type.description} (default: `${builtins.toJSON v.default}`) '') knownSettings )} ''; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { edge = "top"; padding = 6; @@ -155,7 +154,7 @@ in }; }; - config = mkIf cfg.enable ({ + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.trayer" pkgs lib.platforms.linux) ]; @@ -164,9 +163,9 @@ in systemd.user.services.trayer = let - valueToString = v: if isBool v then (if v then "true" else "false") else "${toString v}"; + valueToString = v: if lib.isBool v then (if v then "true" else "false") else "${toString v}"; parameter = k: v: "--${k} ${valueToString v}"; - parameters = concatStringsSep " " (mapAttrsToList parameter cfg.settings); + parameters = lib.concatStringsSep " " (lib.mapAttrsToList parameter cfg.settings); in { Unit = { @@ -181,5 +180,5 @@ in Restart = "on-failure"; }; }; - }); + }; } diff --git a/modules/services/twmn.nix b/modules/services/twmn.nix index 23015efcb..3efff9a5a 100644 --- a/modules/services/twmn.nix +++ b/modules/services/twmn.nix @@ -2,13 +2,16 @@ config, lib, pkgs, - stdenv, ... }: -with lib; - let + inherit (lib) + mkOption + mkEnableOption + types + literalExpression + ; cfg = config.services.twmn; @@ -34,7 +37,7 @@ let in { - meta.maintainers = [ hm.maintainers.austreelis ]; + meta.maintainers = [ lib.hm.maintainers.austreelis ]; options.services.twmn = { enable = mkEnableOption "twmn, a tiling window manager notification daemon"; @@ -304,7 +307,7 @@ in ################# # Implementation - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.twmn" pkgs lib.platforms.linux) ]; @@ -313,7 +316,7 @@ in xdg.configFile."twmn/twmn.conf".text = let - conf = recursiveUpdate { + conf = lib.recursiveUpdate { gui = { always_on_top = if cfg.window.alwaysOnTop then "true" else "false"; background_color = cfg.window.color; @@ -337,7 +340,7 @@ in }; # map null values to empty strings because formats.toml generator fails # when encountering a null. - icons = mapAttrs (_: toString) cfg.icons; + icons = lib.mapAttrs (_: toString) cfg.icons; main = { duration = toString cfg.duration; host = cfg.host; @@ -350,10 +353,10 @@ in mkSection = section: conf: '' [${section}] - ${concatStringsSep "\n" (mapAttrsToList mkLine conf)} + ${lib.concatStringsSep "\n" (lib.mapAttrsToList mkLine conf)} ''; in - concatStringsSep "\n" (mapAttrsToList mkSection conf) + "\n"; + lib.concatStringsSep "\n" (lib.mapAttrsToList mkSection conf) + "\n"; systemd.user.services.twmnd = { Unit = { diff --git a/modules/services/udiskie.nix b/modules/services/udiskie.nix index 9dd119436..ab775c450 100644 --- a/modules/services/udiskie.nix +++ b/modules/services/udiskie.nix @@ -5,11 +5,13 @@ ... }: -with lib; - let + inherit (lib) + mkOption + types + ; - mergeSets = sets: lists.fold attrsets.recursiveUpdate { } sets; + mergeSets = sets: lib.lists.fold lib.attrsets.recursiveUpdate { } sets; yaml = pkgs.formats.yaml { }; @@ -17,10 +19,10 @@ let in { - meta.maintainers = [ maintainers.rycee ]; + meta.maintainers = [ lib.maintainers.rycee ]; imports = [ - (mkRemovedOptionModule [ "services" "udiskie" "sni" ] '' + (lib.mkRemovedOptionModule [ "services" "udiskie" "sni" ] '' Support for Status Notifier Items is now configured globally through the xsession.preferStatusNotifierItems @@ -31,7 +33,7 @@ in options = { services.udiskie = { - enable = mkEnableOption "" // { + enable = lib.mkEnableOption "" // { description = '' Whether to enable the udiskie mount daemon. @@ -45,7 +47,7 @@ in settings = mkOption { type = yaml.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { program_options = { udisks_version = 2; @@ -100,9 +102,9 @@ in }; }; - config = mkIf config.services.udiskie.enable { + config = lib.mkIf config.services.udiskie.enable { assertions = [ - (hm.assertions.assertPlatform "services.udiskie" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "services.udiskie" pkgs lib.platforms.linux) ]; xdg.configFile."udiskie/config.yml".source = yaml.generate "udiskie-config.yml" (mergeSets [ @@ -132,7 +134,7 @@ in Service.ExecStart = toString ( [ "${pkgs.udiskie}/bin/udiskie" ] - ++ optional config.xsession.preferStatusNotifierItems "--appindicator" + ++ lib.optional config.xsession.preferStatusNotifierItems "--appindicator" ); Install.WantedBy = [ "graphical-session.target" ]; diff --git a/modules/services/unclutter.nix b/modules/services/unclutter.nix index 68d648e51..5047dd06d 100644 --- a/modules/services/unclutter.nix +++ b/modules/services/unclutter.nix @@ -5,22 +5,25 @@ ... }: -with lib; - let + inherit (lib) + mkOption + types + ; + cfg = config.services.unclutter; in { options.services.unclutter = { - enable = mkEnableOption "unclutter"; + enable = lib.mkEnableOption "unclutter"; package = mkOption { description = "unclutter derivation to use."; type = types.package; default = pkgs.unclutter-xfixes; - defaultText = literalExpression "pkgs.unclutter-xfixes"; + defaultText = lib.literalExpression "pkgs.unclutter-xfixes"; }; timeout = mkOption { @@ -46,7 +49,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.unclutter" pkgs lib.platforms.linux) ]; @@ -63,7 +66,7 @@ in ${cfg.package}/bin/unclutter \ --timeout ${toString cfg.timeout} \ --jitter ${toString (cfg.threshold - 1)} \ - ${concatMapStrings (x: " --${x}") cfg.extraOptions} + ${lib.concatMapStrings (x: " --${x}") cfg.extraOptions} ''; RestartSec = 3; Restart = "always"; diff --git a/modules/services/unison.nix b/modules/services/unison.nix index d34c39350..36b4609be 100644 --- a/modules/services/unison.nix +++ b/modules/services/unison.nix @@ -5,16 +5,18 @@ ... }: -with lib; - let + inherit (lib) + mkOption + types + ; cfg = config.services.unison; pairOf = t: let - list = types.addCheck (types.listOf t) (l: length l == 2); + list = types.addCheck (types.listOf t) (l: lib.length l == 2); in list // { description = list.description + " of length 2"; }; @@ -31,7 +33,7 @@ let commandOptions = mkOption rec { type = with types; attrsOf (either str (listOf str)); - apply = mergeAttrs default; + apply = lib.mergeAttrs default; default = { repeat = "watch"; sshcmd = "${pkgs.openssh}/bin/ssh"; @@ -54,7 +56,7 @@ let roots = mkOption { type = pairOf types.str; - example = literalExpression '' + example = lib.literalExpression '' [ "/home/user/documents" "ssh://remote/documents" @@ -69,30 +71,32 @@ let serialiseArg = key: val: - concatStringsSep " " (forEach (toList val) (x: escapeShellArg "-${key}=${escape [ "=" ] x}")); + lib.concatStringsSep " " ( + lib.forEach (lib.toList val) (x: lib.escapeShellArg "-${key}=${lib.escape [ "=" ] x}") + ); - serialiseArgs = args: concatStringsSep " " (mapAttrsToList serialiseArg args); + serialiseArgs = args: lib.concatStringsSep " " (lib.mapAttrsToList serialiseArg args); unitName = name: "unison-pair-${name}"; makeDefs = - gen: mapAttrs' (name: pairCfg: nameValuePair (unitName name) (gen name pairCfg)) cfg.pairs; + gen: lib.mapAttrs' (name: pairCfg: lib.nameValuePair (unitName name) (gen name pairCfg)) cfg.pairs; in { - meta.maintainers = with maintainers; [ euxane ]; + meta.maintainers = with lib.maintainers; [ euxane ]; options.services.unison = { - enable = mkEnableOption "Unison synchronisation"; + enable = lib.mkEnableOption "Unison synchronisation"; - package = mkPackageOption pkgs "unison" { + package = lib.mkPackageOption pkgs "unison" { example = "pkgs.unison.override { enableX11 = false; }"; }; pairs = mkOption { type = with types; attrsOf (submodule pairOptions); default = { }; - example = literalExpression '' + example = lib.literalExpression '' { "my-documents" = { roots = [ @@ -108,7 +112,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.unison" pkgs lib.platforms.linux) ]; @@ -123,7 +127,7 @@ in ExecStart = '' ${cfg.package}/bin/unison \ ${serialiseArgs pairCfg.commandOptions} \ - ${strings.concatMapStringsSep " " escapeShellArg pairCfg.roots} + ${lib.strings.concatMapStringsSep " " lib.escapeShellArg pairCfg.roots} ''; }; } diff --git a/modules/services/vdirsyncer.nix b/modules/services/vdirsyncer.nix index ca4ca8eb0..a111a5947 100644 --- a/modules/services/vdirsyncer.nix +++ b/modules/services/vdirsyncer.nix @@ -5,9 +5,8 @@ ... }: -with lib; - let + inherit (lib) mkOption optional types; cfg = config.services.vdirsyncer; @@ -18,16 +17,16 @@ let in { - meta.maintainers = [ maintainers.pjones ]; + meta.maintainers = [ lib.maintainers.pjones ]; options.services.vdirsyncer = { - enable = mkEnableOption "vdirsyncer"; + enable = lib.mkEnableOption "vdirsyncer"; package = mkOption { type = types.package; default = pkgs.vdirsyncer; defaultText = "pkgs.vdirsyncer"; - example = literalExpression "pkgs.vdirsyncer"; + example = lib.literalExpression "pkgs.vdirsyncer"; description = "The package to use for the vdirsyncer binary."; }; @@ -68,7 +67,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { systemd.user.services.vdirsyncer = { Unit = { Description = "vdirsyncer calendar&contacts synchronization"; @@ -80,7 +79,7 @@ in # TODO `vdirsyncer discover` ExecStart = let - optStr = concatStringsSep " " vdirsyncerOptions; + optStr = lib.concatStringsSep " " vdirsyncerOptions; in [ "${cfg.package}/bin/vdirsyncer ${optStr} metasync" diff --git a/modules/services/volnoti.nix b/modules/services/volnoti.nix index 6bec00923..db86a2452 100644 --- a/modules/services/volnoti.nix +++ b/modules/services/volnoti.nix @@ -5,27 +5,25 @@ ... }: -with lib; - let cfg = config.services.volnoti; in { - meta.maintainers = with maintainers; [ + meta.maintainers = with lib.maintainers; [ imalison tomodachi94 ]; options = { services.volnoti = { - enable = mkEnableOption "Volnoti volume HUD daemon"; + enable = lib.mkEnableOption "Volnoti volume HUD daemon"; - package = mkOption { - type = types.package; + package = lib.mkOption { + type = lib.types.package; default = pkgs.volnoti; - defaultText = literalExpression "pkgs.volnoti"; + defaultText = lib.literalExpression "pkgs.volnoti"; description = '' Package containing the {command}`volnoti` program. ''; @@ -33,7 +31,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.volnoti" pkgs lib.platforms.linux) ]; diff --git a/modules/services/window-managers/awesome.nix b/modules/services/window-managers/awesome.nix index 6664f152e..9fc742b16 100644 --- a/modules/services/window-managers/awesome.nix +++ b/modules/services/window-managers/awesome.nix @@ -4,10 +4,8 @@ pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; cfg = config.xsession.windowManager.awesome; awesome = cfg.package; @@ -20,12 +18,12 @@ in { options = { xsession.windowManager.awesome = { - enable = mkEnableOption "Awesome window manager"; + enable = lib.mkEnableOption "Awesome window manager"; package = mkOption { type = types.package; default = pkgs.awesome; - defaultText = literalExpression "pkgs.awesome"; + defaultText = lib.literalExpression "pkgs.awesome"; description = "Package to use for running the Awesome WM."; }; @@ -36,7 +34,7 @@ in List of lua packages available for being used in the Awesome configuration. ''; - example = literalExpression "[ pkgs.luaPackages.vicious ]"; + example = lib.literalExpression "[ pkgs.luaPackages.vicious ]"; }; noArgb = mkOption { @@ -50,14 +48,16 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ - (hm.assertions.assertPlatform "xsession.windowManager.awesome" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "xsession.windowManager.awesome" pkgs lib.platforms.linux) ]; home.packages = [ awesome ]; xsession.windowManager.command = - "${awesome}/bin/awesome " + optionalString cfg.noArgb "--no-argb " + makeSearchPath cfg.luaModules; + "${awesome}/bin/awesome " + + lib.optionalString cfg.noArgb "--no-argb " + + makeSearchPath cfg.luaModules; }; } diff --git a/modules/services/window-managers/bspwm/default.nix b/modules/services/window-managers/bspwm/default.nix index 51cf397b6..6c5f64f65 100644 --- a/modules/services/window-managers/bspwm/default.nix +++ b/modules/services/window-managers/bspwm/default.nix @@ -4,14 +4,18 @@ pkgs, ... }: - -with lib; - let + inherit (lib) + escapeShellArg + escapeShellArgs + concatMapStringsSep + mapAttrsToList + concatStringsSep + ; cfg = config.xsession.windowManager.bspwm; - camelToSnake = builtins.replaceStrings upperChars (map (c: "_${c}") lowerChars); + camelToSnake = builtins.replaceStrings lib.upperChars (map (c: "_${c}") lib.lowerChars); formatMonitor = monitor: desktops: @@ -29,13 +33,13 @@ let formatValue = v: - if isList v then + if lib.isList v then concatMapStringsSep "," formatValue v - else if isBool v then + else if lib.isBool v then if v then "on" else "off" - else if isInt v || isFloat v then + else if lib.isInt v || lib.isFloat v then toString v - else if isString v then + else if lib.isString v then v else throw "unsupported type"; # should not happen @@ -55,7 +59,7 @@ let formatDirective = n: v: "${camelToSnake n}=${formatValue v}"; directivesStr = escapeShellArgs ( - mapAttrsToList formatDirective (filterAttrs (n: v: v != null) directives) + mapAttrsToList formatDirective (lib.filterAttrs (n: v: v != null) directives) ); in "bspc rule -a ${escapeShellArg target} ${directivesStr}"; @@ -64,19 +68,19 @@ let in { - meta.maintainers = [ maintainers.ncfavier ]; + meta.maintainers = [ lib.maintainers.ncfavier ]; options = import ./options.nix { inherit pkgs lib; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ - (hm.assertions.assertPlatform "xsession.windowManager.bspwm" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "xsession.windowManager.bspwm" pkgs lib.platforms.linux) ]; home.packages = [ cfg.package ]; xdg.configFile."bspwm/bspwmrc".source = pkgs.writeShellScript "bspwmrc" ( - (optionalString (cfg.extraConfigEarly != "") (cfg.extraConfigEarly + "\n")) + (lib.optionalString (cfg.extraConfigEarly != "") (cfg.extraConfigEarly + "\n")) + '' ${concatStringsSep "\n" (mapAttrsToList formatMonitor cfg.monitors)} diff --git a/modules/services/window-managers/bspwm/options.nix b/modules/services/window-managers/bspwm/options.nix index 97d19b43c..e44969c58 100644 --- a/modules/services/window-managers/bspwm/options.nix +++ b/modules/services/window-managers/bspwm/options.nix @@ -1,8 +1,6 @@ { pkgs, lib }: - -with lib; - let + inherit (lib) literalExpression mkOption types; primitive = with types; @@ -182,7 +180,7 @@ let in { xsession.windowManager.bspwm = { - enable = mkEnableOption "bspwm window manager"; + enable = lib.mkEnableOption "bspwm window manager"; package = mkOption { type = types.package; diff --git a/modules/services/window-managers/fluxbox.nix b/modules/services/window-managers/fluxbox.nix index 00d688b85..b625873af 100644 --- a/modules/services/window-managers/fluxbox.nix +++ b/modules/services/window-managers/fluxbox.nix @@ -4,22 +4,20 @@ pkgs, ... }: - -with lib; - let + inherit (lib) mkIf mkOption types; cfg = config.xsession.windowManager.fluxbox; in { - meta.maintainers = [ maintainers.AndersonTorres ]; + meta.maintainers = [ lib.maintainers.AndersonTorres ]; options = { xsession.windowManager.fluxbox = { - enable = mkEnableOption "Fluxbox window manager"; + enable = lib.mkEnableOption "Fluxbox window manager"; - package = mkPackageOption pkgs "fluxbox" { nullable = true; }; + package = lib.mkPackageOption pkgs "fluxbox" { nullable = true; }; init = mkOption { type = types.lines; @@ -100,7 +98,7 @@ in config = mkIf cfg.enable { assertions = [ - (hm.assertions.assertPlatform "xsession.windowManager.fluxbox" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "xsession.windowManager.fluxbox" pkgs lib.platforms.linux) ]; home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; @@ -114,8 +112,8 @@ in ".fluxbox/windowmenu" = mkIf (cfg.windowmenu != "") { text = cfg.windowmenu; }; }; - xsession.windowManager.command = escapeShellArgs ( - [ "${cfg.package}/bin/fluxbox" ] ++ remove "" cfg.extraCommandLineArgs + xsession.windowManager.command = lib.escapeShellArgs ( + [ "${cfg.package}/bin/fluxbox" ] ++ lib.remove "" cfg.extraCommandLineArgs ); }; } diff --git a/modules/services/window-managers/i3-sway/i3.nix b/modules/services/window-managers/i3-sway/i3.nix index b26e40e94..7fba897a7 100644 --- a/modules/services/window-managers/i3-sway/i3.nix +++ b/modules/services/window-managers/i3-sway/i3.nix @@ -4,10 +4,8 @@ pkgs, ... }: - -with lib; - let + inherit (lib) mkIf mkOption types; cfg = config.xsession.windowManager.i3; @@ -45,7 +43,7 @@ let keybindings = mkOption { type = types.attrsOf (types.nullOr types.str); - default = mapAttrs (n: mkOptionDefault) { + default = lib.mapAttrs (n: lib.mkOptionDefault) { "${cfg.config.modifier}+Return" = "exec ${cfg.config.terminal}"; "${cfg.config.modifier}+Shift+q" = "kill"; "${cfg.config.modifier}+d" = "exec ${cfg.config.menu}"; @@ -113,7 +111,7 @@ let Consider to use `lib.mkOptionDefault` function to extend or override default keybindings instead of specifying all of them from scratch. ''; - example = literalExpression '' + example = lib.literalExpression '' let modifier = config.xsession.windowManager.i3.config.modifier; in lib.mkOptionDefault { @@ -177,14 +175,14 @@ let workspace, ... }: - concatStringsSep " " [ + lib.concatStringsSep " " [ (if always then "exec_always" else "exec") (if (notification && workspace == null) then "" else "--no-startup-id") (if (workspace == null) then command else "i3-msg 'workspace ${workspace}; exec ${command}'") ]; configFile = pkgs.writeText "i3.conf" ( - concatStringsSep "\n" ( + lib.concatStringsSep "\n" ( ( if cfg.config != null then with cfg.config; @@ -210,10 +208,10 @@ let (keybindingsStr { keybindings = keybindingsRest; }) (keycodebindingsStr keycodebindings) ] - ++ mapAttrsToList (modeStr false) modes - ++ mapAttrsToList assignStr assigns + ++ lib.mapAttrsToList (modeStr false) modes + ++ lib.mapAttrsToList assignStr assigns ++ map barStr bars - ++ optional (gaps != null) gapsStr + ++ lib.optional (gaps != null) gapsStr ++ map floatingCriteriaStr floating.criteria ++ map windowCommandsStr window.commands ++ map startupEntryStr startup @@ -242,13 +240,13 @@ let in { - meta.maintainers = with maintainers; [ sumnerevans ]; + meta.maintainers = with lib.maintainers; [ sumnerevans ]; options = { xsession.windowManager.i3 = { - enable = mkEnableOption "i3 window manager"; + enable = lib.mkEnableOption "i3 window manager"; - package = mkPackageOption pkgs "i3" { nullable = true; }; + package = lib.mkPackageOption pkgs "i3" { nullable = true; }; config = mkOption { type = types.nullOr configModule; @@ -264,50 +262,52 @@ in }; }; - config = mkIf cfg.enable (mkMerge [ - { - assertions = [ - (hm.assertions.assertPlatform "xsession.windowManager.i3" pkgs platforms.linux) - ]; - - home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; - - xsession.windowManager.command = "${cfg.package}/bin/i3"; - - xdg.configFile."i3/config" = { - source = checkI3Config; - onChange = '' - # There may be several sockets after log out/log in, but the old ones - # will fail with "Connection refused". - for i3Socket in ''${XDG_RUNTIME_DIR:-/run/user/$UID}/i3/ipc-socket.*; do - if [[ -S $i3Socket ]]; then - ${cfg.package}/bin/i3-msg -s $i3Socket reload >/dev/null |& grep -v "Connection refused" || true - fi - done - ''; - }; - } - - (mkIf (cfg.config != null) { - warnings = - (optional (isList cfg.config.fonts) "Specifying i3.config.fonts as a list is deprecated. Use the attrset version instead.") - ++ flatten ( - map ( - b: - optional (isList b.fonts) "Specifying i3.config.bars[].fonts as a list is deprecated. Use the attrset version instead." - ) cfg.config.bars - ) - ++ [ - (mkIf (any (s: s.workspace != null) cfg.config.startup) ( - "'xsession.windowManager.i3.config.startup.*.workspace' is deprecated, " - + "use 'xsession.windowManager.i3.config.assigns' instead." - + "See https://github.com/nix-community/home-manager/issues/265." - )) - (mkIf cfg.config.focus.forceWrapping ( - "'xsession.windowManager.i3.config.focus.forceWrapping' is deprecated, " - + "use 'xsession.windowManager.i3.config.focus.wrapping' instead." - )) + config = mkIf cfg.enable ( + lib.mkMerge [ + { + assertions = [ + (lib.hm.assertions.assertPlatform "xsession.windowManager.i3" pkgs lib.platforms.linux) ]; - }) - ]); + + home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; + + xsession.windowManager.command = "${cfg.package}/bin/i3"; + + xdg.configFile."i3/config" = { + source = checkI3Config; + onChange = '' + # There may be several sockets after log out/log in, but the old ones + # will fail with "Connection refused". + for i3Socket in ''${XDG_RUNTIME_DIR:-/run/user/$UID}/i3/ipc-socket.*; do + if [[ -S $i3Socket ]]; then + ${cfg.package}/bin/i3-msg -s $i3Socket reload >/dev/null |& grep -v "Connection refused" || true + fi + done + ''; + }; + } + + (mkIf (cfg.config != null) { + warnings = + (lib.optional (lib.isList cfg.config.fonts) "Specifying i3.config.fonts as a list is deprecated. Use the attrset version instead.") + ++ lib.flatten ( + map ( + b: + lib.optional (lib.isList b.fonts) "Specifying i3.config.bars[].fonts as a list is deprecated. Use the attrset version instead." + ) cfg.config.bars + ) + ++ [ + (mkIf (lib.any (s: s.workspace != null) cfg.config.startup) ( + "'xsession.windowManager.i3.config.startup.*.workspace' is deprecated, " + + "use 'xsession.windowManager.i3.config.assigns' instead." + + "See https://github.com/nix-community/home-manager/issues/265." + )) + (mkIf cfg.config.focus.forceWrapping ( + "'xsession.windowManager.i3.config.focus.forceWrapping' is deprecated, " + + "use 'xsession.windowManager.i3.config.focus.wrapping' instead." + )) + ]; + }) + ] + ); } diff --git a/modules/services/window-managers/i3-sway/lib/functions.nix b/modules/services/window-managers/i3-sway/lib/functions.nix index ffec09986..2b8ecd7ef 100644 --- a/modules/services/window-managers/i3-sway/lib/functions.nix +++ b/modules/services/window-managers/i3-sway/lib/functions.nix @@ -4,9 +4,9 @@ lib, moduleName, }: - -with lib; - +let + inherit (lib) concatStringsSep mapAttrsToList optionalString; +in rec { criteriaStr = criteria: @@ -15,11 +15,11 @@ rec { in "[${concatStringsSep " " (mapAttrsToList toCriteria criteria)}]"; - keybindingDefaultWorkspace = filterAttrs ( + keybindingDefaultWorkspace = lib.filterAttrs ( n: v: cfg.config.defaultWorkspace != null && v == cfg.config.defaultWorkspace ) cfg.config.keybindings; - keybindingsRest = filterAttrs ( + keybindingsRest = lib.filterAttrs ( n: v: cfg.config.defaultWorkspace == null || v != cfg.config.defaultWorkspace ) cfg.config.keybindings; @@ -85,7 +85,7 @@ rec { size ? "", }: optionalString (names != [ ]) concatStringsSep " " ( - remove "" [ + lib.remove "" [ "font" "pango:${concatStringsSep ", " names}" style @@ -94,7 +94,7 @@ rec { ); in fontCfg: - if isList fontCfg then + if lib.isList fontCfg then toFontStr { names = fontCfg; } else toFontStr { @@ -122,61 +122,63 @@ rec { let colorsNotNull = lib.filterAttrs (n: v: v != null) colors != { }; in - concatMapStrings (x: x + "\n") ( - indent (lists.subtractLists [ "" null ] (flatten [ - "bar {" - (optionalString (id != null) "id ${id}") - (fontConfigStr fonts) - (optionalString (mode != null) "mode ${mode}") - (optionalString (hiddenState != null) "hidden_state ${hiddenState}") - (optionalString (position != null) "position ${position}") - (optionalString (statusCommand != null) "status_command ${statusCommand}") - "${moduleName}bar_command ${command}" - (optionalString ( - workspaceButtons != null - ) "workspace_buttons ${lib.hm.booleans.yesNo workspaceButtons}") - (optionalString (workspaceNumbers != null) - "strip_workspace_numbers ${lib.hm.booleans.yesNo (!workspaceNumbers)}" - ) - (optionalString (trayOutput != null) "tray_output ${trayOutput}") - (optionalString (trayPadding != null) "tray_padding ${toString trayPadding}") - (optionals colorsNotNull ( - indent (lists.subtractLists - [ "" null ] - [ - "colors {" - (optionalString (colors.background != null) "background ${colors.background}") - (optionalString (colors.statusline != null) "statusline ${colors.statusline}") - (optionalString (colors.separator != null) "separator ${colors.separator}") - (optionalString (colors.focusedBackground != null) "focused_background ${colors.focusedBackground}") - (optionalString (colors.focusedStatusline != null) "focused_statusline ${colors.focusedStatusline}") - (optionalString (colors.focusedSeparator != null) "focused_separator ${colors.focusedSeparator}") - (optionalString ( - colors.focusedWorkspace != null - ) "focused_workspace ${barColorSetStr colors.focusedWorkspace}") - (optionalString ( - colors.activeWorkspace != null - ) "active_workspace ${barColorSetStr colors.activeWorkspace}") - (optionalString ( - colors.inactiveWorkspace != null - ) "inactive_workspace ${barColorSetStr colors.inactiveWorkspace}") - (optionalString ( - colors.urgentWorkspace != null - ) "urgent_workspace ${barColorSetStr colors.urgentWorkspace}") - (optionalString (colors.bindingMode != null) "binding_mode ${barColorSetStr colors.bindingMode}") - "}" - ] - ) { } - )) - extraConfig - "}" - ])) { } + lib.concatMapStrings (x: x + "\n") ( + indent (lib.lists.subtractLists [ "" null ] ( + lib.flatten [ + "bar {" + (optionalString (id != null) "id ${id}") + (fontConfigStr fonts) + (optionalString (mode != null) "mode ${mode}") + (optionalString (hiddenState != null) "hidden_state ${hiddenState}") + (optionalString (position != null) "position ${position}") + (optionalString (statusCommand != null) "status_command ${statusCommand}") + "${moduleName}bar_command ${command}" + (optionalString ( + workspaceButtons != null + ) "workspace_buttons ${lib.hm.booleans.yesNo workspaceButtons}") + (optionalString (workspaceNumbers != null) + "strip_workspace_numbers ${lib.hm.booleans.yesNo (!workspaceNumbers)}" + ) + (optionalString (trayOutput != null) "tray_output ${trayOutput}") + (optionalString (trayPadding != null) "tray_padding ${toString trayPadding}") + (lib.optionals colorsNotNull ( + indent (lib.lists.subtractLists + [ "" null ] + [ + "colors {" + (optionalString (colors.background != null) "background ${colors.background}") + (optionalString (colors.statusline != null) "statusline ${colors.statusline}") + (optionalString (colors.separator != null) "separator ${colors.separator}") + (optionalString (colors.focusedBackground != null) "focused_background ${colors.focusedBackground}") + (optionalString (colors.focusedStatusline != null) "focused_statusline ${colors.focusedStatusline}") + (optionalString (colors.focusedSeparator != null) "focused_separator ${colors.focusedSeparator}") + (optionalString ( + colors.focusedWorkspace != null + ) "focused_workspace ${barColorSetStr colors.focusedWorkspace}") + (optionalString ( + colors.activeWorkspace != null + ) "active_workspace ${barColorSetStr colors.activeWorkspace}") + (optionalString ( + colors.inactiveWorkspace != null + ) "inactive_workspace ${barColorSetStr colors.inactiveWorkspace}") + (optionalString ( + colors.urgentWorkspace != null + ) "urgent_workspace ${barColorSetStr colors.urgentWorkspace}") + (optionalString (colors.bindingMode != null) "binding_mode ${barColorSetStr colors.bindingMode}") + "}" + ] + ) { } + )) + extraConfig + "}" + ] + )) { } ); gapsStr = with cfg.config.gaps; concatStringsSep "\n" ( - lists.subtractLists + lib.lists.subtractLists [ "" null ] [ (optionalString (inner != null) "gaps inner ${toString inner}") @@ -208,7 +210,7 @@ rec { workspaceOutputStr = item: let - outputs = concatMapStringsSep " " strings.escapeNixString item.output; + outputs = lib.concatMapStringsSep " " lib.strings.escapeNixString item.output; in ''workspace "${item.workspace}" output ${outputs}''; diff --git a/modules/services/window-managers/i3-sway/lib/options.nix b/modules/services/window-managers/i3-sway/lib/options.nix index 50884db71..ed6192f23 100644 --- a/modules/services/window-managers/i3-sway/lib/options.nix +++ b/modules/services/window-managers/i3-sway/lib/options.nix @@ -6,10 +6,9 @@ pkgs, capitalModuleName ? moduleName, }: - -with lib; - let + inherit (lib) literalExpression mkOption types; + isI3 = moduleName == "i3"; isSway = !isI3; @@ -62,7 +61,7 @@ let description = "Whether to run command on each ${moduleName} restart."; }; } - // optionalAttrs isI3 { + // lib.optionalAttrs isI3 { notification = mkOption { type = types.bool; default = true; @@ -88,7 +87,7 @@ let barModule = types.submodule { options = let - versionAtLeast2009 = versionAtLeast stateVersion "20.09"; + versionAtLeast2009 = lib.versionAtLeast stateVersion "20.09"; mkNullableOption = { type, default, ... }@args: mkOption ( @@ -420,7 +419,8 @@ in options = { titlebar = mkOption { type = types.bool; - default = if versionOlder stateVersion "23.05" then (isI3 && (cfg.config.gaps == null)) else true; + default = + if lib.versionOlder stateVersion "23.05" then (isI3 && (cfg.config.gaps == null)) else true; defaultText = if isI3 then '' @@ -488,7 +488,8 @@ in options = { titlebar = mkOption { type = types.bool; - default = if versionOlder stateVersion "23.05" then (isI3 && (cfg.config.gaps == null)) else true; + default = + if lib.versionOlder stateVersion "23.05" then (isI3 && (cfg.config.gaps == null)) else true; defaultText = if isI3 then '' @@ -563,7 +564,7 @@ in types.bool; default = if isSway then "yes" else true; description = "Whether focus should follow the mouse."; - apply = val: if (isSway && isBool val) then (lib.hm.booleans.yesNo val) else val; + apply = val: if (isSway && lib.isBool val) then (lib.hm.booleans.yesNo val) else val; }; wrapping = mkOption { @@ -783,7 +784,7 @@ in bars = mkOption { type = types.listOf barModule; default = - if versionAtLeast stateVersion "20.09" then + if lib.versionAtLeast stateVersion "20.09" then [ { mode = "dock"; @@ -985,12 +986,11 @@ in workspaceOutputAssign = mkOption { type = - with types; let - workspaceOutputOpts = submodule { + workspaceOutputOpts = types.submodule { options = { workspace = mkOption { - type = str; + type = types.str; default = ""; example = "Web"; description = '' @@ -1001,7 +1001,7 @@ in output = mkOption { type = with types; either str (listOf str); default = ""; - apply = lists.toList; + apply = lib.lists.toList; example = "eDP"; description = '' Name(s) of the output(s) from {command}` @@ -1012,7 +1012,7 @@ in }; }; in - listOf workspaceOutputOpts; + types.listOf workspaceOutputOpts; default = [ ]; description = "Assign workspaces to outputs."; }; diff --git a/modules/services/window-managers/i3-sway/sway.nix b/modules/services/window-managers/i3-sway/sway.nix index 82a82d561..b713c715e 100644 --- a/modules/services/window-managers/i3-sway/sway.nix +++ b/modules/services/window-managers/i3-sway/sway.nix @@ -4,10 +4,15 @@ pkgs, ... }: - -with lib; - let + inherit (lib) + concatStringsSep + mapAttrsToList + mkIf + mkOption + optional + types + ; cfg = config.wayland.windowManager.sway; @@ -70,7 +75,7 @@ let keybindings = mkOption { type = types.attrsOf (types.nullOr types.str); - default = mapAttrs (n: mkOptionDefault) { + default = lib.mapAttrs (n: lib.mkOptionDefault) { "${cfg.config.modifier}+Return" = "exec ${cfg.config.terminal}"; "${cfg.config.modifier}+Shift+q" = "kill"; "${cfg.config.modifier}+d" = "exec ${cfg.config.menu}"; @@ -146,7 +151,7 @@ let Consider to use `lib.mkOptionDefault` function to extend or override default keybindings instead of specifying all of them from scratch. ''; - example = literalExpression '' + example = lib.literalExpression '' let modifier = config.wayland.windowManager.sway.config.modifier; in lib.mkOptionDefault { @@ -292,7 +297,7 @@ let moduleStr = moduleType: name: attrs: '' ${moduleType} "${name}" { - ${concatStringsSep "\n" (mapAttrsToList (name: value: " ${name} ${value}") attrs)} + ${concatStringsSep "\n" (lib.mapAttrsToList (name: value: " ${name} ${value}") attrs)} } ''; inputStr = moduleStr "input"; @@ -376,7 +381,7 @@ let in { - meta.maintainers = with maintainers; [ + meta.maintainers = with lib.maintainers; [ Scrumplex alexarice sumnerevans @@ -392,7 +397,7 @@ in ]; in [ - (mkRenamedOptionModule (modulePath ++ [ "systemdIntegration" ]) ( + (lib.mkRenamedOptionModule (modulePath ++ [ "systemdIntegration" ]) ( modulePath ++ [ "systemd" @@ -402,7 +407,7 @@ in ]; options.wayland.windowManager.sway = { - enable = mkEnableOption "sway wayland compositor"; + enable = lib.mkEnableOption "sway wayland compositor"; package = mkOption { type = with types; nullOr package; @@ -412,7 +417,7 @@ in withBaseWrapper = cfg.wrapperFeatures.base; withGtkWrapper = cfg.wrapperFeatures.gtk; }; - defaultText = literalExpression "${pkgs.sway}"; + defaultText = lib.literalExpression "${pkgs.sway}"; description = '' Sway package to use. Will override the options 'wrapperFeatures', 'extraSessionCommands', and 'extraOptions'. @@ -477,7 +482,7 @@ in ''; }; - xdgAutostart = mkEnableOption '' + xdgAutostart = lib.mkEnableOption '' autostart of applications using {manpage}`systemd-xdg-autostart-generator(8)` ''; @@ -543,7 +548,7 @@ in checkConfig = mkOption { type = types.bool; default = cfg.package != null; - defaultText = literalExpression "wayland.windowManager.sway.package != null"; + defaultText = lib.literalExpression "wayland.windowManager.sway.package != null"; description = "If enabled, validates the generated config file."; }; @@ -560,54 +565,56 @@ in }; }; - config = mkIf cfg.enable (mkMerge [ - (mkIf (cfg.config != null) { - warnings = - (optional (isList cfg.config.fonts) "Specifying sway.config.fonts as a list is deprecated. Use the attrset version instead.") - ++ flatten ( - map ( - b: - optional (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.") + config = mkIf cfg.enable ( + 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 = [ + (lib.hm.assertions.assertPlatform "wayland.windowManager.sway" pkgs lib.platforms.linux) + { + assertion = cfg.checkConfig -> cfg.package != null; + message = "programs.sway.checkConfig requires non-null programs.sway.package"; + } ]; - }) - { - assertions = [ - (hm.assertions.assertPlatform "wayland.windowManager.sway" pkgs platforms.linux) - { - assertion = cfg.checkConfig -> cfg.package != null; - message = "programs.sway.checkConfig requires non-null programs.sway.package"; - } - ]; + home.packages = optional (cfg.package != null) cfg.package ++ optional cfg.xwayland pkgs.xwayland; - home.packages = optional (cfg.package != null) cfg.package ++ optional cfg.xwayland pkgs.xwayland; - - xdg.configFile."sway/config" = { - source = configFile; - onChange = lib.optionalString (cfg.package != null) '' - swaySocket="''${XDG_RUNTIME_DIR:-/run/user/$UID}/sway-ipc.$UID.$(${pkgs.procps}/bin/pgrep --uid $UID -x sway || true).sock" - if [ -S "$swaySocket" ]; then - ${cfg.package}/bin/swaymsg -s $swaySocket reload - fi - ''; - }; - - systemd.user.targets.sway-session = mkIf cfg.systemd.enable { - Unit = { - Description = "sway compositor session"; - Documentation = [ "man:systemd.special(7)" ]; - BindsTo = [ "graphical-session.target" ]; - Wants = [ - "graphical-session-pre.target" - ] ++ optional cfg.systemd.xdgAutostart "xdg-desktop-autostart.target"; - After = [ "graphical-session-pre.target" ]; - Before = optional cfg.systemd.xdgAutostart "xdg-desktop-autostart.target"; + xdg.configFile."sway/config" = { + source = configFile; + onChange = lib.optionalString (cfg.package != null) '' + swaySocket="''${XDG_RUNTIME_DIR:-/run/user/$UID}/sway-ipc.$UID.$(${pkgs.procps}/bin/pgrep --uid $UID -x sway || true).sock" + if [ -S "$swaySocket" ]; then + ${cfg.package}/bin/swaymsg -s $swaySocket reload + fi + ''; }; - }; - } - ]); + + systemd.user.targets.sway-session = mkIf cfg.systemd.enable { + Unit = { + Description = "sway compositor session"; + Documentation = [ "man:systemd.special(7)" ]; + BindsTo = [ "graphical-session.target" ]; + Wants = [ + "graphical-session-pre.target" + ] ++ optional cfg.systemd.xdgAutostart "xdg-desktop-autostart.target"; + After = [ "graphical-session-pre.target" ]; + Before = optional cfg.systemd.xdgAutostart "xdg-desktop-autostart.target"; + }; + }; + } + ] + ); } diff --git a/modules/services/window-managers/i3-sway/swaynag.nix b/modules/services/window-managers/i3-sway/swaynag.nix index 97137764e..f5366216a 100644 --- a/modules/services/window-managers/i3-sway/swaynag.nix +++ b/modules/services/window-managers/i3-sway/swaynag.nix @@ -4,16 +4,13 @@ pkgs, ... }: - -with lib; - let cfg = config.wayland.windowManager.sway.swaynag; iniFormat = pkgs.formats.ini { }; confFormat = - with types; + with lib.types; let confAtom = nullOr (oneOf [ @@ -33,10 +30,10 @@ in options = { wayland.windowManager.sway.swaynag = { - enable = mkEnableOption "configuration of swaynag, a lightweight error bar for sway"; + enable = lib.mkEnableOption "configuration of swaynag, a lightweight error bar for sway"; - settings = mkOption { - type = types.attrsOf confFormat; + settings = lib.mkOption { + type = lib.types.attrsOf confFormat; default = { }; description = '' Configuration written to @@ -48,7 +45,7 @@ in Note, configurations declared under `` will override the default type values of swaynag. ''; - example = literalExpression '' + example = lib.literalExpression '' { "" = { edge = "bottom"; @@ -68,12 +65,12 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ - (hm.assertions.assertPlatform "wayland.windowManager.sway.swaynag" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "wayland.windowManager.sway.swaynag" pkgs lib.platforms.linux) ]; - xdg.configFile."swaynag/config" = mkIf (cfg.settings != { }) { + xdg.configFile."swaynag/config" = lib.mkIf (cfg.settings != { }) { source = iniFormat.generate "swaynag.conf" cfg.settings; }; }; diff --git a/modules/services/window-managers/spectrwm.nix b/modules/services/window-managers/spectrwm.nix index 0f73cf92c..e3e94d0b3 100644 --- a/modules/services/window-managers/spectrwm.nix +++ b/modules/services/window-managers/spectrwm.nix @@ -4,14 +4,17 @@ pkgs, ... }: - -with lib; - let + inherit (lib) + literalExpression + mapAttrsToList + mkOption + types + ; cfg = config.xsession.windowManager.spectrwm; - renderedValue = val: if isBool val then if val then "1" else "0" else toString val; + renderedValue = val: if lib.isBool val then if val then "1" else "0" else toString val; renderedSettings = settings: mapAttrsToList (name: value: "${name} = ${renderedValue value}") settings; @@ -32,11 +35,11 @@ let in { - meta.maintainers = [ hm.maintainers.loicreynier ]; + meta.maintainers = [ lib.hm.maintainers.loicreynier ]; options = { xsession.windowManager.spectrwm = { - enable = mkEnableOption "Spectrwm window manager"; + enable = lib.mkEnableOption "Spectrwm window manager"; package = mkOption { type = types.package; @@ -118,9 +121,9 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ - (hm.assertions.assertPlatform "xsession.windowManager.spectrwm" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "xsession.windowManager.spectrwm" pkgs lib.platforms.linux) ]; home.packages = [ cfg.package ]; @@ -129,7 +132,7 @@ in xdg.configFile."spectrwm/spectrwm.conf".text = '' # Generated by Home Manager - ${concatStringsSep "\n" ( + ${lib.concatStringsSep "\n" ( # \ renderedSettings cfg.settings # \ ++ renderedPrograms cfg.programs # \ diff --git a/modules/services/window-managers/xmonad.nix b/modules/services/window-managers/xmonad.nix index 9c5efa64e..e0c5019a7 100644 --- a/modules/services/window-managers/xmonad.nix +++ b/modules/services/window-managers/xmonad.nix @@ -4,10 +4,8 @@ pkgs, ... }: - -with lib; - let + inherit (lib) literalExpression mkOption types; cfg = config.xsession.windowManager.xmonad; @@ -16,7 +14,7 @@ let packages = self: cfg.extraPackages self - ++ optionals cfg.enableContribAndExtras [ + ++ lib.optionals cfg.enableContribAndExtras [ self.xmonad-contrib self.xmonad-extras ]; @@ -26,7 +24,7 @@ in { options = { xsession.windowManager.xmonad = { - enable = mkEnableOption "xmonad window manager"; + enable = lib.mkEnableOption "xmonad window manager"; haskellPackages = mkOption { default = pkgs.haskellPackages; @@ -136,7 +134,7 @@ in declare -A libFiles libFiles=(${ - concatStringsSep " " (mapAttrsToList (name: value: "['${name}']='${value}'") cfg.libFiles) + lib.concatStringsSep " " (lib.mapAttrsToList (name: value: "['${name}']='${value}'") cfg.libFiles) }) for key in "''${!libFiles[@]}"; do mkdir -p "xmonad-config/lib/$(dirname "$key")" @@ -158,36 +156,38 @@ in }/bin/xmonad-${executableSystemSuffix}"; in - mkIf cfg.enable (mkMerge [ - { - assertions = [ - (hm.assertions.assertPlatform "xsession.windowManager.xmonad" pkgs platforms.linux) - ]; + lib.mkIf cfg.enable ( + lib.mkMerge [ + { + assertions = [ + (lib.hm.assertions.assertPlatform "xsession.windowManager.xmonad" pkgs lib.platforms.linux) + ]; - home.packages = [ (lowPrio xmonad) ]; + home.packages = [ (lib.lowPrio xmonad) ]; - home.file = mapAttrs' ( - name: value: attrsets.nameValuePair (".xmonad/lib/" + name) { source = value; } - ) cfg.libFiles; - } + home.file = lib.mapAttrs' ( + name: value: lib.attrsets.nameValuePair (".xmonad/lib/" + name) { source = value; } + ) cfg.libFiles; + } - (mkIf (cfg.config == null) { - xsession.windowManager.command = "${xmonad}/bin/xmonad"; - }) + (lib.mkIf (cfg.config == null) { + xsession.windowManager.command = "${xmonad}/bin/xmonad"; + }) - (mkIf (cfg.config != null) { - xsession.windowManager.command = xmonadBin; - home.file.".xmonad/xmonad.hs".source = cfg.config; - home.file.".xmonad/xmonad-${pkgs.stdenv.hostPlatform.system}" = { - source = xmonadBin; - onChange = '' - # Attempt to restart xmonad if X is running. - if [[ -v DISPLAY ]]; then - ${config.xsession.windowManager.command} --restart - fi - ''; - }; - }) + (lib.mkIf (cfg.config != null) { + xsession.windowManager.command = xmonadBin; + home.file.".xmonad/xmonad.hs".source = cfg.config; + home.file.".xmonad/xmonad-${pkgs.stdenv.hostPlatform.system}" = { + source = xmonadBin; + onChange = '' + # Attempt to restart xmonad if X is running. + if [[ -v DISPLAY ]]; then + ${config.xsession.windowManager.command} --restart + fi + ''; + }; + }) - ]); + ] + ); } diff --git a/modules/services/wlsunset.nix b/modules/services/wlsunset.nix index aa6d5281d..939cf8798 100644 --- a/modules/services/wlsunset.nix +++ b/modules/services/wlsunset.nix @@ -5,17 +5,19 @@ ... }: -with lib; - let - cfg = config.services.wlsunset; + inherit (lib) + mkOption + types + ; + cfg = config.services.wlsunset; in { - meta.maintainers = [ hm.maintainers.matrss ]; + meta.maintainers = [ lib.hm.maintainers.matrss ]; options.services.wlsunset = { - enable = mkEnableOption "wlsunset"; + enable = lib.mkEnableOption "wlsunset"; package = mkOption { type = with types; package; @@ -110,7 +112,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.wlsunset" pkgs lib.platforms.linux) { @@ -138,7 +140,7 @@ in Service = { ExecStart = let - args = cli.toGNUCommandLineShell { } { + args = lib.cli.toGNUCommandLineShell { } { t = cfg.temperature.night; T = cfg.temperature.day; g = cfg.gamma; diff --git a/modules/services/xcape.nix b/modules/services/xcape.nix index 666b080ef..8d1d20a36 100644 --- a/modules/services/xcape.nix +++ b/modules/services/xcape.nix @@ -5,21 +5,22 @@ ... }: -with lib; - let + inherit (lib) + types + ; cfg = config.services.xcape; in { - meta.maintainers = [ maintainers.nickhu ]; + meta.maintainers = [ lib.maintainers.nickhu ]; options = { services.xcape = { - enable = mkEnableOption "xcape"; + enable = lib.mkEnableOption "xcape"; - timeout = mkOption { + timeout = lib.mkOption { type = types.nullOr types.int; default = null; example = 500; @@ -29,7 +30,7 @@ in ''; }; - mapExpression = mkOption { + mapExpression = lib.mkOption { type = types.attrsOf types.str; default = { }; example = { @@ -56,19 +57,19 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.xcape" pkgs lib.platforms.linux) ]; systemd.user.services.xcape = { - Unit = mkMerge [ + Unit = lib.mkMerge [ { Description = "xcape"; After = [ "graphical-session.target" ]; PartOf = [ "graphical-session.target" ]; } - (mkIf (config.home.keyboard != null && config.home.keyboard != { }) { + (lib.mkIf (config.home.keyboard != null && config.home.keyboard != { }) { After = [ "graphical-session.target" "setxkbmap.service" @@ -80,11 +81,11 @@ in Type = "forking"; ExecStart = "${pkgs.xcape}/bin/xcape" - + optionalString (cfg.timeout != null) " -t ${toString cfg.timeout}" + + lib.optionalString (cfg.timeout != null) " -t ${toString cfg.timeout}" + - optionalString (cfg.mapExpression != { }) + lib.optionalString (cfg.mapExpression != { }) " -e '${ - builtins.concatStringsSep ";" (attrsets.mapAttrsToList (n: v: "${n}=${v}") cfg.mapExpression) + builtins.concatStringsSep ";" (lib.attrsets.mapAttrsToList (n: v: "${n}=${v}") cfg.mapExpression) }'"; }; diff --git a/modules/services/xembed-sni-proxy.nix b/modules/services/xembed-sni-proxy.nix index c6464e70f..a2c484d67 100644 --- a/modules/services/xembed-sni-proxy.nix +++ b/modules/services/xembed-sni-proxy.nix @@ -5,24 +5,22 @@ ... }: -with lib; - let cfg = config.services.xembed-sni-proxy; in { - meta.maintainers = [ maintainers.rycee ]; + meta.maintainers = [ lib.maintainers.rycee ]; options = { services.xembed-sni-proxy = { - enable = mkEnableOption "XEmbed SNI Proxy"; + enable = lib.mkEnableOption "XEmbed SNI Proxy"; - package = mkOption { - type = types.package; + package = lib.mkOption { + type = lib.types.package; default = pkgs.kdePackages.plasma-workspace; - defaultText = literalExpression "pkgs.kdePackages.plasma-workspace"; + defaultText = lib.literalExpression "pkgs.kdePackages.plasma-workspace"; description = '' Package containing the {command}`xembedsniproxy` program. @@ -31,7 +29,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.xembed-sni-proxy" pkgs lib.platforms.linux) ]; diff --git a/modules/services/xidlehook.nix b/modules/services/xidlehook.nix index 5ab2ebb84..ee53c799d 100644 --- a/modules/services/xidlehook.nix +++ b/modules/services/xidlehook.nix @@ -7,31 +7,37 @@ ... }: -with lib; - let + inherit (lib) + literalExpression + mkEnableOption + mkOption + optionalString + types + ; + cfg = config.services.xidlehook; - notEmpty = list: filter (x: x != "" && x != null) (flatten list); + notEmpty = list: lib.filter (x: x != "" && x != null) (lib.flatten list); timers = let toTimer = timer: "--timer ${toString timer.delay} ${ - escapeShellArgs [ + lib.escapeShellArgs [ timer.command timer.canceller ] }"; in - map toTimer (filter (timer: timer.command != null) cfg.timers); + map toTimer (lib.filter (timer: timer.command != null) cfg.timers); script = pkgs.writeShellScript "xidlehook" '' - ${concatStringsSep "\n" ( - mapAttrsToList (name: value: "export ${name}=${value}") cfg.environment or { } + ${lib.concatStringsSep "\n" ( + lib.mapAttrsToList (name: value: "export ${name}=${value}") cfg.environment or { } )} - ${concatStringsSep " " (notEmpty [ + ${lib.concatStringsSep " " (notEmpty [ "${cfg.package}/bin/xidlehook" (optionalString cfg.once "--once") (optionalString cfg.detect-sleep "--detect-sleep") @@ -43,8 +49,8 @@ let in { meta.maintainers = [ - maintainers.dschrempf - hm.maintainers.bertof + lib.maintainers.dschrempf + lib.hm.maintainers.bertof ]; options.services.xidlehook = { @@ -151,7 +157,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.xidlehook" pkgs lib.platforms.linux) ]; diff --git a/modules/services/xscreensaver.nix b/modules/services/xscreensaver.nix index 07a7d13ee..14343a805 100644 --- a/modules/services/xscreensaver.nix +++ b/modules/services/xscreensaver.nix @@ -5,22 +5,20 @@ ... }: -with lib; - let cfg = config.services.xscreensaver; in { - meta.maintainers = [ maintainers.rycee ]; + meta.maintainers = [ lib.maintainers.rycee ]; options = { services.xscreensaver = { - enable = mkEnableOption "XScreenSaver"; + enable = lib.mkEnableOption "XScreenSaver"; - settings = mkOption { - type = with types; attrsOf (either bool (either int str)); + settings = lib.mkOption { + type = with lib.types; attrsOf (either bool (either int str)); default = { }; example = { mode = "blank"; @@ -32,8 +30,8 @@ in ''; }; - package = mkOption { - type = with types; package; + package = lib.mkOption { + type = with lib.types; package; default = pkgs.xscreensaver; defaultText = lib.literalExpression "pkgs.xscreensaver"; description = "Which xscreensaver package to use."; @@ -41,15 +39,15 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.xscreensaver" pkgs lib.platforms.linux) ]; - # To make the xscreensaver-command tool available. + # To make the lib.xscreensaver-command tool available. home.packages = [ cfg.package ]; - xresources.properties = mapAttrs' (n: nameValuePair "xscreensaver.${n}") cfg.settings; + xresources.properties = lib.mapAttrs' (n: lib.nameValuePair "xscreensaver.${n}") cfg.settings; systemd.user.services.xscreensaver = { Unit = { @@ -63,7 +61,7 @@ in Service = { ExecStart = "${cfg.package}/bin/xscreensaver -no-splash"; - Environment = [ "PATH=${makeBinPath [ cfg.package ]}" ]; + Environment = [ "PATH=${lib.makeBinPath [ cfg.package ]}" ]; }; Install = { diff --git a/modules/services/xsettingsd.nix b/modules/services/xsettingsd.nix index 6378a89f5..e5f9c97a0 100644 --- a/modules/services/xsettingsd.nix +++ b/modules/services/xsettingsd.nix @@ -5,13 +5,16 @@ ... }: -with lib; - let + inherit (lib) + mkOption + literalExpression + types + ; cfg = config.services.xsettingsd; - renderSettings = settings: concatStrings (mapAttrsToList renderSetting settings); + renderSettings = settings: lib.concatStrings (lib.mapAttrsToList renderSetting settings); renderSetting = key: value: '' ${key} ${renderValue value} @@ -28,11 +31,11 @@ let in { - meta.maintainers = [ maintainers.imalison ]; + meta.maintainers = [ lib.maintainers.imalison ]; options = { services.xsettingsd = { - enable = mkEnableOption "xsettingsd"; + enable = lib.mkEnableOption "xsettingsd"; package = mkOption { type = types.package; @@ -80,7 +83,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.xsettingsd" pkgs lib.platforms.linux) ]; @@ -98,7 +101,7 @@ in Environment = [ "PATH=${config.home.profileDirectory}/bin" ]; ExecStart = "${cfg.package}/bin/xsettingsd" - + optionalString (cfg.configFile != null) " -c ${escapeShellArg cfg.configFile}"; + + lib.optionalString (cfg.configFile != null) " -lib.c ${lib.escapeShellArg cfg.configFile}"; Restart = "on-abort"; }; }; diff --git a/modules/services/xsuspender.nix b/modules/services/xsuspender.nix index e9dd308fd..50ff768b2 100644 --- a/modules/services/xsuspender.nix +++ b/modules/services/xsuspender.nix @@ -5,9 +5,8 @@ ... }: -with lib; - let + inherit (lib) mkOption types; cfg = config.services.xsuspender; @@ -114,11 +113,11 @@ let in { - meta.maintainers = [ maintainers.offline ]; + meta.maintainers = [ lib.maintainers.offline ]; options = { services.xsuspender = { - enable = mkEnableOption "XSuspender"; + enable = lib.mkEnableOption "XSuspender"; defaults = mkOption { description = "XSuspender defaults."; @@ -152,7 +151,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "services.xsuspender" pkgs lib.platforms.linux) ]; @@ -161,7 +160,7 @@ in let mkSection = values: - filterAttrs (_: v: v != null) { + lib.filterAttrs (_: v: v != null) { match_wm_class_contains = values.matchWmClassContains; match_wm_class_group_contains = values.matchWmClassGroupContains; match_wm_name_contains = values.matchWmNameContains; @@ -180,7 +179,7 @@ in { Default = mkSection cfg.defaults; } - // mapAttrs (_: mkSection) cfg.rules; + // lib.mapAttrs (_: mkSection) cfg.rules; # To make the xsuspender tool available. home.packages = [ pkgs.xsuspender ]; @@ -197,7 +196,7 @@ in Service = { ExecStart = "${pkgs.xsuspender}/bin/xsuspender"; - Environment = mkIf cfg.debug [ "G_MESSAGES_DEBUG=all" ]; + Environment = lib.mkIf cfg.debug [ "G_MESSAGES_DEBUG=all" ]; }; Install = { diff --git a/tests/modules/services/mpdscribble/basic-configuration.nix b/tests/modules/services/mpdscribble/basic-configuration.nix index 05a14a0a5..b7e7c9c55 100644 --- a/tests/modules/services/mpdscribble/basic-configuration.nix +++ b/tests/modules/services/mpdscribble/basic-configuration.nix @@ -5,8 +5,6 @@ ... }: -with lib; - { services.mpdscribble = { enable = true;