diff --git a/modules/programs/abook.nix b/modules/programs/abook.nix index 68d9ca75..1f0600ff 100644 --- a/modules/programs/abook.nix +++ b/modules/programs/abook.nix @@ -1,17 +1,11 @@ { config, lib, pkgs, ... }: - -with lib; - -let - - cfg = config.programs.abook; - +let cfg = config.programs.abook; in { options.programs.abook = { - enable = mkEnableOption "Abook"; + enable = lib.mkEnableOption "Abook"; - extraConfig = mkOption { - type = types.lines; + extraConfig = lib.mkOption { + type = lib.types.lines; default = ""; example = '' field pager = Pager @@ -26,10 +20,10 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ pkgs.abook ]; - xdg.configFile."abook/abookrc" = mkIf (cfg.extraConfig != "") { + xdg.configFile."abook/abookrc" = lib.mkIf (cfg.extraConfig != "") { text = '' # Generated by Home Manager. # See http://abook.sourceforge.net/ diff --git a/modules/programs/aerc-accounts.nix b/modules/programs/aerc-accounts.nix index 8ebfef0b..331167ad 100644 --- a/modules/programs/aerc-accounts.nix +++ b/modules/programs/aerc-accounts.nix @@ -1,10 +1,9 @@ { config, lib, confSections, confSection, ... }: - -with lib; - let + inherit (lib) literalExpression mkOption types; + mapAttrNames = f: attr: - listToAttrs (attrValues (mapAttrs (k: v: { + lib.listToAttrs (lib.attrValues (lib.mapAttrs (k: v: { name = f k; value = v; }) attr)); @@ -50,7 +49,7 @@ in { type = mkOption { type = types.attrsOf (types.submodule { options.aerc = { - enable = mkEnableOption "aerc"; + enable = lib.mkEnableOption "aerc"; extraAccounts = mkOption { type = confSection; default = { }; @@ -128,7 +127,7 @@ in { if v != null && v != [ ] && v != "" then { ${k} = v; } else { }; optPwCmd = k: p: - optAttr "${k}-cred-cmd" (nullOrMap (concatStringsSep " ") p); + optAttr "${k}-cred-cmd" (nullOrMap (lib.concatStringsSep " ") p); useOauth = auth: builtins.elem auth [ "oauthbearer" "xoauth2" ]; @@ -232,7 +231,7 @@ in { { }; gpgCfg = account: - optionalAttrs (account.gpg != null) { + lib.optionalAttrs (account.gpg != null) { pgp-key-id = account.gpg.key; pgp-auto-sign = account.gpg.signByDefault; pgp-opportunistic-encrypt = account.gpg.encryptByDefault; diff --git a/modules/programs/aerc.nix b/modules/programs/aerc.nix index 477bfddf..132b35d9 100644 --- a/modules/programs/aerc.nix +++ b/modules/programs/aerc.nix @@ -1,7 +1,8 @@ { config, lib, pkgs, ... }: - -with lib; let + inherit (lib) + attrsets generators literalExpression mapAttrs mkIf mkOption types; + cfg = config.programs.aerc; primitive = with types; @@ -36,9 +37,9 @@ in { options.programs.aerc = { - enable = mkEnableOption "aerc"; + enable = lib.mkEnableOption "aerc"; - package = mkPackageOption pkgs "aerc" { nullable = true; }; + package = lib.mkPackageOption pkgs "aerc" { nullable = true; }; extraAccounts = mkOption { type = sectionsOrLines; @@ -103,15 +104,16 @@ in { }; config = let - joinCfg = cfgs: concatStringsSep "\n" (filter (v: v != "") cfgs); + joinCfg = cfgs: lib.concatStringsSep "\n" (lib.filter (v: v != "") cfgs); toINI = conf: # quirk: global section is prepended w/o section heading let global = conf.global or { }; local = removeAttrs conf [ "global" ]; mkValueString = v: - if isList v then # join with comma - concatStringsSep "," (map (generators.mkValueStringDefault { }) v) + if lib.isList v then # join with comma + lib.concatStringsSep "," + (map (generators.mkValueStringDefault { }) v) else generators.mkValueStringDefault { } v; mkKeyValue = @@ -121,10 +123,10 @@ in { (generators.toINI { inherit mkKeyValue; } local) ]; - mkINI = conf: if isString conf then conf else toINI conf; + mkINI = conf: if lib.isString conf then conf else toINI conf; mkStyleset = attrsets.mapAttrs' (k: v: - let value = if isString v then v else toINI { global = v; }; + let value = if lib.isString v then v else toINI { global = v; }; in { name = "${configDir}/stylesets/${k}"; value.text = joinCfg [ header value ]; @@ -146,11 +148,12 @@ in { accountsExtraBinds = mapAttrs accounts.mkAccountBinds aerc-accounts; - joinContextual = contextual: joinCfg (map mkINI (attrValues contextual)); + joinContextual = contextual: + joinCfg (map mkINI (lib.attrValues contextual)); isRecursivelyEmpty = x: - if isAttrs x then - all (x: x == { } || isRecursivelyEmpty x) (attrValues x) + if lib.isAttrs x then + lib.all (x: x == { } || isRecursivelyEmpty x) (lib.attrValues x) else false; @@ -183,8 +186,9 @@ in { assertions = [{ assertion = let - extraConfigSections = (unique (flatten - (mapAttrsToList (_: v: attrNames v.aerc.extraConfig) aerc-accounts))); + extraConfigSections = (lib.unique (lib.flatten + (lib.mapAttrsToList (_: v: lib.attrNames v.aerc.extraConfig) + aerc-accounts))); in extraConfigSections == [ ] || extraConfigSections == [ "ui" ]; message = '' Only the ui section of $XDG_CONFIG_HOME/aerc.conf supports contextual (per-account) configuration. diff --git a/modules/programs/afew.nix b/modules/programs/afew.nix index e0bb2604..da2d9528 100644 --- a/modules/programs/afew.nix +++ b/modules/programs/afew.nix @@ -1,17 +1,11 @@ { config, lib, pkgs, ... }: - -with lib; - -let - - cfg = config.programs.afew; - +let cfg = config.programs.afew; in { options.programs.afew = { - enable = mkEnableOption "the afew initial tagging script for Notmuch"; + enable = lib.mkEnableOption "the afew initial tagging script for Notmuch"; - extraConfig = mkOption { - type = types.lines; + extraConfig = lib.mkOption { + type = lib.types.lines; default = '' [SpamFilter] [KillThreadsFilter] @@ -37,7 +31,7 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ pkgs.afew ]; xdg.configFile."afew/config".text = '' diff --git a/modules/programs/alacritty.nix b/modules/programs/alacritty.nix index 140e68e7..e095f0ca 100644 --- a/modules/programs/alacritty.nix +++ b/modules/programs/alacritty.nix @@ -1,21 +1,18 @@ { config, lib, pkgs, ... }: - -with lib; - let cfg = config.programs.alacritty; tomlFormat = pkgs.formats.toml { }; in { options = { programs.alacritty = { - enable = mkEnableOption "Alacritty"; + enable = lib.mkEnableOption "Alacritty"; package = lib.mkPackageOption pkgs "alacritty" { }; - settings = mkOption { + settings = lib.mkOption { type = tomlFormat.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { window.dimensions = { lines = 3; @@ -42,7 +39,7 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; xdg.configFile."alacritty/alacritty.toml" = lib.mkIf (cfg.settings != { }) { diff --git a/modules/programs/alot-accounts.nix b/modules/programs/alot-accounts.nix index 0a51bfde..d4df3bfc 100644 --- a/modules/programs/alot-accounts.nix +++ b/modules/programs/alot-accounts.nix @@ -1,9 +1,7 @@ pkgs: { config, lib, ... }: - -with lib; - -{ +let inherit (lib) mkOption types; +in { options.alot = { sendMailCommand = mkOption { type = types.nullOr types.str; @@ -25,7 +23,7 @@ with lib; + "}[,\\]]?'"; shellcommand_external_filtering = "False"; }; - example = literalExpression '' + example = lib.literalExpression '' { type = "shellcommand"; command = "abook --mutt-query"; @@ -49,8 +47,8 @@ with lib; }; }; - config = mkIf config.notmuch.enable { - alot.sendMailCommand = mkOptionDefault (if config.msmtp.enable then + config = lib.mkIf config.notmuch.enable { + alot.sendMailCommand = lib.mkOptionDefault (if config.msmtp.enable then "msmtpq --read-envelope-from --read-recipients" else null); diff --git a/modules/programs/alot.nix b/modules/programs/alot.nix index 24321574..7217b77f 100644 --- a/modules/programs/alot.nix +++ b/modules/programs/alot.nix @@ -1,22 +1,21 @@ # alot config loader is sensitive to leading space ! { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) + concatStringsSep mapAttrsToList mkOption optionalAttrs optionalString types; cfg = config.programs.alot; - enabledAccounts = - filter (a: a.notmuch.enable) (attrValues config.accounts.email.accounts); + enabledAccounts = lib.filter (a: a.notmuch.enable) + (lib.attrValues config.accounts.email.accounts); # sorted: primary first - alotAccounts = sort (a: b: !(a.primary -> b.primary)) enabledAccounts; + alotAccounts = lib.sort (a: b: !(a.primary -> b.primary)) enabledAccounts; boolStr = v: if v then "True" else "False"; mkKeyValue = key: value: - let value' = if isBool value then boolStr value else toString value; + let value' = if lib.isBool value then boolStr value else toString value; in "${key} = ${value'}"; mk2ndLevelSectionName = name: "[" + name + "]"; @@ -61,8 +60,10 @@ let }; accountStr = account: - with account; - concatStringsSep "\n" ([ "[[${name}]]" ] + let + inherit (account) + alot maildir name address realName folders aliases gpg signature; + in concatStringsSep "\n" ([ "[[${name}]]" ] ++ mapAttrsToList (n: v: n + "=" + v) ({ address = address; realname = realName; @@ -91,14 +92,14 @@ let # Generated by Home Manager. # See http://alot.readthedocs.io/en/latest/configuration/config_options.html - ${generators.toKeyValue { inherit mkKeyValue; } cfg.settings} + ${lib.generators.toKeyValue { inherit mkKeyValue; } cfg.settings} ${cfg.extraConfig} [tags] '' + (let submoduleToAttrs = m: - filterAttrs (name: v: name != "_module" && v != null) m; - in generators.toINI { mkSectionName = mk2ndLevelSectionName; } - (mapAttrs (name: x: submoduleToAttrs x) cfg.tags)) + '' + lib.filterAttrs (name: v: name != "_module" && v != null) m; + in lib.generators.toINI { mkSectionName = mk2ndLevelSectionName; } + (lib.mapAttrs (name: x: submoduleToAttrs x) cfg.tags)) + '' [bindings] ${bindingsToStr cfg.bindings.global} @@ -115,7 +116,7 @@ let [accounts] - ${concatStringsSep "\n\n" (map accountStr alotAccounts)} + ${lib.concatStringsSep "\n\n" (map accountStr alotAccounts)} ''; in { @@ -132,7 +133,7 @@ in { ''; }; - package = mkPackageOption pkgs "alot" { nullable = true; }; + package = lib.mkPackageOption pkgs "alot" { nullable = true; }; hooks = mkOption { type = types.lines; @@ -204,7 +205,7 @@ in { handle_mouse = true; prefer_plaintext = true; }; - example = literalExpression '' + example = lib.literalExpression '' { auto_remove_unread = true; ask_subject = false; @@ -230,12 +231,12 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; xdg.configFile."alot/config".text = configFile; - xdg.configFile."alot/hooks.py" = mkIf (cfg.hooks != "") { + xdg.configFile."alot/hooks.py" = lib.mkIf (cfg.hooks != "") { text = '' # Generated by Home Manager. '' + cfg.hooks; diff --git a/modules/programs/antidote.nix b/modules/programs/antidote.nix index 8cf3d5a4..a97e7bb9 100644 --- a/modules/programs/antidote.nix +++ b/modules/programs/antidote.nix @@ -1,45 +1,43 @@ { config, lib, pkgs, ... }: - -with lib; let cfg = config.programs.zsh.antidote; zPluginStr = (pluginNames: - optionalString (pluginNames != [ ]) "${concatStrings (map (name: '' + lib.optionalString (pluginNames != [ ]) "${lib.concatStrings (map (name: '' ${name} '') pluginNames)}"); parseHashId = path: - elemAt (builtins.match "${builtins.storeDir}/([a-zA-Z0-9]+)-.*" path) 0; + lib.elemAt (builtins.match "${builtins.storeDir}/([a-zA-Z0-9]+)-.*" path) 0; in { - meta.maintainers = [ maintainers.hitsmaxft ]; + meta.maintainers = [ lib.maintainers.hitsmaxft ]; options.programs.zsh.antidote = { - enable = mkEnableOption "antidote - a zsh plugin manager"; + enable = lib.mkEnableOption "antidote - a zsh plugin manager"; - plugins = mkOption { - type = types.listOf types.str; + plugins = lib.mkOption { + type = lib.types.listOf lib.types.str; default = [ ]; example = [ "zsh-users/zsh-autosuggestions" ]; description = "List of antidote plugins."; }; - useFriendlyNames = mkEnableOption "friendly names"; + useFriendlyNames = lib.mkEnableOption "friendly names"; - package = mkPackageOption pkgs "antidote" { }; + package = lib.mkPackageOption pkgs "antidote" { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; programs.zsh.initContent = let configFiles = pkgs.runCommand "hm_antidote-files" { } '' echo "${zPluginStr cfg.plugins}" > $out ''; hashId = parseHashId "${configFiles}"; - in (mkOrder 550 '' + in (lib.mkOrder 550 '' ## home-manager/antidote begin : source ${cfg.package}/share/antidote/antidote.zsh - ${optionalString cfg.useFriendlyNames + ${lib.optionalString cfg.useFriendlyNames "zstyle ':antidote:bundle' use-friendly-names 'yes'"} bundlefile=${configFiles} diff --git a/modules/programs/aria2.nix b/modules/programs/aria2.nix index 549e6baf..a689dd15 100644 --- a/modules/programs/aria2.nix +++ b/modules/programs/aria2.nix @@ -1,7 +1,4 @@ { config, lib, pkgs, ... }: - -with lib; - let cfg = config.programs.aria2; @@ -14,13 +11,13 @@ let toString v; in "${n}=${formatValue v}"; in { - meta.maintainers = [ hm.maintainers.justinlovinger ]; + meta.maintainers = [ lib.hm.maintainers.justinlovinger ]; options.programs.aria2 = { - enable = mkEnableOption "aria2"; + enable = lib.mkEnableOption "aria2"; - settings = mkOption { - type = with types; attrsOf (oneOf [ bool float int str ]); + settings = lib.mkOption { + type = with lib.types; attrsOf (oneOf [ bool float int str ]); default = { }; description = '' Options to add to {file}`aria2.conf` file. @@ -28,7 +25,7 @@ in { {manpage}`aria2c(1)` for options. ''; - example = literalExpression '' + example = lib.literalExpression '' { listen-port = 60000; dht-listen-port = 60000; @@ -39,8 +36,8 @@ in { ''; }; - extraConfig = mkOption { - type = types.lines; + extraConfig = lib.mkOption { + type = lib.types.lines; default = ""; description = '' Extra lines added to {file}`aria2.conf` file. @@ -48,11 +45,11 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ pkgs.aria2 ]; - xdg.configFile."aria2/aria2.conf".text = concatStringsSep "\n" ([ ] - ++ mapAttrsToList formatLine cfg.settings - ++ optional (cfg.extraConfig != "") cfg.extraConfig); + xdg.configFile."aria2/aria2.conf".text = lib.concatStringsSep "\n" ([ ] + ++ lib.mapAttrsToList formatLine cfg.settings + ++ lib.optional (cfg.extraConfig != "") cfg.extraConfig); }; } diff --git a/modules/programs/astroid-accounts.nix b/modules/programs/astroid-accounts.nix index b9b1fac0..50154608 100644 --- a/modules/programs/astroid-accounts.nix +++ b/modules/programs/astroid-accounts.nix @@ -1,13 +1,9 @@ -{ config, lib, ... }: - -with lib; - -{ +{ config, lib, ... }: { options.astroid = { - enable = mkEnableOption "Astroid"; + enable = lib.mkEnableOption "Astroid"; - sendMailCommand = mkOption { - type = types.str; + sendMailCommand = lib.mkOption { + type = lib.types.str; description = '' Command to send a mail. If msmtp is enabled for the account, then this is set to @@ -15,8 +11,8 @@ with lib; ''; }; - extraConfig = mkOption { - type = types.attrsOf types.anything; + extraConfig = lib.mkOption { + type = lib.types.attrsOf lib.types.anything; default = { }; example = { select_query = ""; }; description = '' @@ -25,8 +21,8 @@ with lib; }; }; - config = mkIf config.notmuch.enable { - astroid.sendMailCommand = mkIf config.msmtp.enable - (mkOptionDefault "msmtpq --read-envelope-from --read-recipients"); + config = lib.mkIf config.notmuch.enable { + astroid.sendMailCommand = lib.mkIf config.msmtp.enable + (lib.mkOptionDefault "msmtpq --read-envelope-from --read-recipients"); }; } diff --git a/modules/programs/astroid.nix b/modules/programs/astroid.nix index 911ce491..da1c4f72 100644 --- a/modules/programs/astroid.nix +++ b/modules/programs/astroid.nix @@ -1,16 +1,13 @@ { config, lib, pkgs, ... }: - -with lib; -with builtins; - let + inherit (lib) mkOption types; cfg = config.programs.astroid; jsonFormat = pkgs.formats.json { }; astroidAccounts = - filterAttrs (n: v: v.astroid.enable) config.accounts.email.accounts; + lib.filterAttrs (n: v: v.astroid.enable) config.accounts.email.accounts; boolOpt = b: if b then "true" else "false"; @@ -26,25 +23,25 @@ let save_sent = "true"; save_sent_to = "${maildir.absPath}/${folders.sent}/cur/"; select_query = ""; - } // optionalAttrs (signature.showSignature != "none") { + } // lib.optionalAttrs (signature.showSignature != "none") { signature_attach = boolOpt (signature.showSignature == "attach"); signature_default_on = boolOpt (signature.showSignature != "none"); signature_file = pkgs.writeText "signature.txt" signature.text; signature_file_markdown = "false"; signature_separate = "true"; # prepends '--\n' to the signature - } // optionalAttrs (gpg != null) { + } // lib.optionalAttrs (gpg != null) { always_gpg_sign = boolOpt gpg.signByDefault; gpgkey = gpg.key; } // astroid.extraConfig; # See https://github.com/astroidmail/astroid/wiki/Configuration-Reference finalConfig = let - template = fromJSON (readFile ./astroid-config-template.json); - astroidConfig = foldl' recursiveUpdate template [ + template = lib.fromJSON (lib.readFile ./astroid-config-template.json); + astroidConfig = lib.foldl' lib.recursiveUpdate template [ { astroid.notmuch_config = "${config.xdg.configHome}/notmuch/default/config"; - accounts = mapAttrs (n: accountAttr) astroidAccounts; + accounts = lib.mapAttrs (n: accountAttr) astroidAccounts; crypto.gpg.path = "${pkgs.gnupg}/bin/gpg"; } cfg.extraConfig @@ -55,7 +52,7 @@ let in { options = { programs.astroid = { - enable = mkEnableOption "Astroid"; + enable = lib.mkEnableOption "Astroid"; pollScript = mkOption { type = types.str; @@ -71,7 +68,7 @@ in { default = null; # Converts it into JSON that can be merged into the configuration. apply = cmd: - optionalAttrs (cmd != null) { + lib.optionalAttrs (cmd != null) { editor = { "external_editor" = "true"; "cmd" = cmd; @@ -99,7 +96,7 @@ in { extraConfig = mkOption { type = jsonFormat.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { poll.interval = 0; } @@ -115,7 +112,7 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ pkgs.astroid ]; xdg.configFile."astroid/config".source = diff --git a/modules/programs/atuin.nix b/modules/programs/atuin.nix index ccb4347f..097cf701 100644 --- a/modules/programs/atuin.nix +++ b/modules/programs/atuin.nix @@ -1,25 +1,22 @@ { config, pkgs, lib, ... }: - -with lib; - let - cfg = config.programs.atuin; daemonCfg = cfg.daemon; tomlFormat = pkgs.formats.toml { }; + inherit (lib) mkIf mkOption types; inherit (pkgs.stdenv) isLinux isDarwin; in { - meta.maintainers = [ maintainers.hawkw maintainers.water-sucks ]; + meta.maintainers = with lib.maintainers; [ hawkw water-sucks ]; options.programs.atuin = { - enable = mkEnableOption "atuin"; + enable = lib.mkEnableOption "atuin"; package = mkOption { type = types.package; default = pkgs.atuin; - defaultText = literalExpression "pkgs.atuin"; + defaultText = lib.literalExpression "pkgs.atuin"; description = "The package to use for atuin."; }; @@ -65,7 +62,7 @@ in { entries = entryOrAttrsOf (entryOrAttrsOf entry); in attrsOf entries // { description = "Atuin configuration"; }; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { auto_sync = true; sync_frequency = "5m"; @@ -83,7 +80,7 @@ in { }; daemon = { - enable = mkEnableOption "Atuin daemon"; + enable = lib.mkEnableOption "Atuin daemon"; logLevel = mkOption { default = null; @@ -96,8 +93,8 @@ in { }; }; - config = let flagsStr = escapeShellArgs cfg.flags; - in mkIf cfg.enable (mkMerge [ + config = let flagsStr = lib.escapeShellArgs cfg.flags; + in mkIf cfg.enable (lib.mkMerge [ { # Always add the configured `atuin` package. home.packages = [ cfg.package ]; @@ -140,11 +137,11 @@ in { }; } - (mkIf daemonCfg.enable (mkMerge [ + (mkIf daemonCfg.enable (lib.mkMerge [ { assertions = [ { - assertion = versionAtLeast cfg.package.version "18.2.0"; + assertion = lib.versionAtLeast cfg.package.version "18.2.0"; message = '' The Atuin daemon requires at least version 18.2.0 or later. ''; @@ -181,7 +178,7 @@ in { }; systemd.user.sockets.atuin-daemon = let - socket_dir = if versionAtLeast cfg.package.version "18.4.0" then + socket_dir = if lib.versionAtLeast cfg.package.version "18.4.0" then "%t" else "%D/atuin"; diff --git a/modules/programs/autojump.nix b/modules/programs/autojump.nix index 3d7f1ad9..87740c51 100644 --- a/modules/programs/autojump.nix +++ b/modules/programs/autojump.nix @@ -1,17 +1,14 @@ { config, lib, pkgs, ... }: - -with lib; - let - cfg = config.programs.autojump; package = pkgs.autojump; + inherit (lib) mkIf; in { - meta.maintainers = [ maintainers.evanjs ]; + meta.maintainers = [ lib.maintainers.evanjs ]; options.programs.autojump = { - enable = mkEnableOption "autojump"; + enable = lib.mkEnableOption "autojump"; enableBashIntegration = lib.hm.shell.mkBashIntegrationOption { inherit config; }; @@ -26,7 +23,7 @@ in { config = mkIf cfg.enable { home.packages = [ package ]; - programs.bash.initExtra = mkIf cfg.enableBashIntegration (mkBefore '' + programs.bash.initExtra = mkIf cfg.enableBashIntegration (lib.mkBefore '' . ${package}/share/autojump/autojump.bash ''); diff --git a/modules/programs/autorandr.nix b/modules/programs/autorandr.nix index ab59d8d9..ae10c5ac 100644 --- a/modules/programs/autorandr.nix +++ b/modules/programs/autorandr.nix @@ -1,25 +1,25 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) + literalExpression listToAttrs mapAttrs' mapAttrsToList mkIf mkOption + optional types; cfg = config.programs.autorandr; matrixOf = n: m: elemType: - mkOptionType rec { + lib.mkOptionType rec { name = "matrixOf"; description = "${toString n}×${toString m} matrix of ${elemType.description}s"; check = xss: - let listOfSize = l: xs: isList xs && length xs == l; + let listOfSize = l: xs: lib.isList xs && lib.length xs == l; in listOfSize n xss - && all (xs: listOfSize m xs && all elemType.check xs) xss; - merge = mergeOneOption; + && lib.all (xs: listOfSize m xs && lib.all elemType.check xs) xss; + merge = lib.mergeOneOption; getSubOptions = prefix: elemType.getSubOptions (prefix ++ [ "*" "*" ]); getSubModules = elemType.getSubModules; substSubModules = mod: matrixOf n m (elemType.substSubModules mod); - functor = (defaultFunctor name) // { wrapped = elemType; }; + functor = (lib.defaultFunctor name) // { wrapped = elemType; }; }; profileModule = types.submodule { @@ -243,17 +243,17 @@ let }; hookToFile = folder: name: hook: - nameValuePair "autorandr/${folder}/${name}" { + lib.nameValuePair "autorandr/${folder}/${name}" { source = "${pkgs.writeShellScriptBin "hook" hook}/bin/hook"; }; profileToFiles = name: profile: - with profile; - mkMerge ([ + let inherit (profile) hooks; + in lib.mkMerge [ { - "autorandr/${name}/setup".text = concatStringsSep "\n" - (mapAttrsToList fingerprintToString fingerprint); - "autorandr/${name}/config".text = - concatStringsSep "\n" (mapAttrsToList configToString profile.config); + "autorandr/${name}/setup".text = lib.concatStringsSep "\n" + (mapAttrsToList fingerprintToString profile.fingerprint); + "autorandr/${name}/config".text = lib.concatStringsSep "\n" + (mapAttrsToList configToString profile.config); } (mkIf (hooks.postswitch != "") (listToAttrs [ (hookToFile name "postswitch" hooks.postswitch) ])) @@ -261,11 +261,11 @@ let (listToAttrs [ (hookToFile name "preswitch" hooks.preswitch) ])) (mkIf (hooks.predetect != "") (listToAttrs [ (hookToFile name "predetect" hooks.predetect) ])) - ]); + ]; fingerprintToString = name: edid: "${name} ${edid}"; configToString = name: config: if config.enable then - concatStringsSep "\n" ([ "output ${name}" ] + lib.concatStringsSep "\n" ([ "output ${name}" ] ++ optional (config.position != "") "pos ${config.position}" ++ optional (config.crtc != null) "crtc ${toString config.crtc}" ++ optional config.primary "primary" @@ -276,7 +276,7 @@ let ++ optional (config.rotate != null) "rotate ${config.rotate}" ++ optional (config.filter != null) "filter ${config.filter}" ++ optional (config.transform != null) ("transform " - + concatMapStringsSep "," toString (flatten config.transform)) + + lib.concatMapStringsSep "," toString (lib.flatten config.transform)) ++ optional (config.scale != null) ((if config.scale.method == "factor" then "scale" else "scale-from") + " ${toString config.scale.x}x${toString config.scale.y}") @@ -289,7 +289,7 @@ let in { options = { programs.autorandr = { - enable = mkEnableOption "Autorandr"; + enable = lib.mkEnableOption "Autorandr"; hooks = mkOption { type = globalHooksModule; @@ -355,8 +355,8 @@ in { }; }; - config = mkIf cfg.enable { - assertions = flatten (mapAttrsToList (profile: + config = lib.mkIf cfg.enable { + assertions = lib.flatten (mapAttrsToList (profile: { config, ... }: mapAttrsToList (output: opts: { assertion = opts.scale == null || opts.transform == null; @@ -367,13 +367,13 @@ in { }) config) cfg.profiles); home.packages = [ pkgs.autorandr ]; - xdg.configFile = mkMerge ([ + xdg.configFile = lib.mkMerge [ (mapAttrs' (hookToFile "postswitch.d") cfg.hooks.postswitch) (mapAttrs' (hookToFile "preswitch.d") cfg.hooks.preswitch) (mapAttrs' (hookToFile "predetect.d") cfg.hooks.predetect) - (mkMerge (mapAttrsToList profileToFiles cfg.profiles)) - ]); + (lib.mkMerge (mapAttrsToList profileToFiles cfg.profiles)) + ]; }; - meta.maintainers = [ maintainers.uvnikita ]; + meta.maintainers = [ lib.maintainers.uvnikita ]; } diff --git a/modules/programs/bacon.nix b/modules/programs/bacon.nix index 528be2a0..47c00c83 100644 --- a/modules/programs/bacon.nix +++ b/modules/programs/bacon.nix @@ -1,7 +1,4 @@ { config, lib, pkgs, ... }: - -with lib; - let cfg = config.programs.bacon; @@ -14,14 +11,14 @@ let "${config.xdg.configHome}/bacon"; in { - meta.maintainers = [ hm.maintainers.shimunn ]; + meta.maintainers = [ lib.hm.maintainers.shimunn ]; options.programs.bacon = { - enable = mkEnableOption "bacon, a background rust code checker"; + enable = lib.mkEnableOption "bacon, a background rust code checker"; - package = mkPackageOption pkgs "bacon" { nullable = true; }; + package = lib.mkPackageOption pkgs "bacon" { nullable = true; }; - settings = mkOption { + settings = lib.mkOption { type = settingsFormat.type; default = { }; example = { @@ -37,10 +34,10 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; - home.file."${configDir}/prefs.toml" = mkIf (cfg.settings != { }) { + home.file."${configDir}/prefs.toml" = lib.mkIf (cfg.settings != { }) { source = settingsFormat.generate "prefs.toml" cfg.settings; }; }; diff --git a/modules/programs/bash.nix b/modules/programs/bash.nix index e9cf983d..ccdf5c11 100644 --- a/modules/programs/bash.nix +++ b/modules/programs/bash.nix @@ -1,8 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkIf mkOption optionalAttrs types; cfg = config.programs.bash; @@ -15,10 +13,10 @@ let }; in { - meta.maintainers = [ maintainers.rycee ]; + meta.maintainers = [ lib.maintainers.rycee ]; imports = [ - (mkRenamedOptionModule [ "programs" "bash" "enableAutojump" ] [ + (lib.mkRenamedOptionModule [ "programs" "bash" "enableAutojump" ] [ "programs" "autojump" "enable" @@ -27,9 +25,9 @@ in { options = { programs.bash = { - enable = mkEnableOption "GNU Bourne-Again SHell"; + enable = lib.mkEnableOption "GNU Bourne-Again SHell"; - package = mkPackageOption pkgs "bash" { + package = lib.mkPackageOption pkgs "bash" { nullable = true; default = "bashInteractive"; }; @@ -122,7 +120,7 @@ in { shellAliases = mkOption { default = { }; type = types.attrsOf types.str; - example = literalExpression '' + example = lib.literalExpression '' { ll = "ls -l"; ".." = "cd .."; @@ -173,18 +171,18 @@ in { }; config = let - aliasesStr = concatStringsSep "\n" - (mapAttrsToList (k: v: "alias ${k}=${escapeShellArg v}") + aliasesStr = lib.concatStringsSep "\n" + (lib.mapAttrsToList (k: v: "alias ${k}=${lib.escapeShellArg v}") cfg.shellAliases); - shoptsStr = let switch = v: if hasPrefix "-" v then "-u" else "-s"; - in concatStringsSep "\n" - (map (v: "shopt ${switch v} ${removePrefix "-" v}") cfg.shellOptions); + shoptsStr = let switch = v: if lib.hasPrefix "-" v then "-u" else "-s"; + in lib.concatStringsSep "\n" + (map (v: "shopt ${switch v} ${lib.removePrefix "-" v}") cfg.shellOptions); sessionVarsStr = config.lib.shell.exportAll cfg.sessionVariables; - historyControlStr = (concatStringsSep "\n" - (mapAttrsToList (n: v: "${n}=${v}") + historyControlStr = (lib.concatStringsSep "\n" + (lib.mapAttrsToList (n: v: "${n}=${v}") (optionalAttrs (cfg.historyFileSize != null) { HISTFILESIZE = toString cfg.historyFileSize; } // optionalAttrs (cfg.historySize != null) { @@ -192,10 +190,11 @@ in { } // optionalAttrs (cfg.historyFile != null) { HISTFILE = ''"${cfg.historyFile}"''; } // optionalAttrs (cfg.historyControl != [ ]) { - HISTCONTROL = concatStringsSep ":" cfg.historyControl; + HISTCONTROL = lib.concatStringsSep ":" cfg.historyControl; } // optionalAttrs (cfg.historyIgnore != [ ]) { - HISTIGNORE = escapeShellArg (concatStringsSep ":" cfg.historyIgnore); - }) ++ optional (cfg.historyFile != null) + HISTIGNORE = + lib.escapeShellArg (lib.concatStringsSep ":" cfg.historyIgnore); + }) ++ lib.optional (cfg.historyFile != null) ''mkdir -p "$(dirname "$HISTFILE")"'')); in mkIf cfg.enable { home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; @@ -211,7 +210,7 @@ in { # If completion is enabled then make sure it is sourced very early. This # is to avoid problems if any other initialization code attempts to set up # completion. - programs.bash.initExtra = mkIf cfg.enableCompletion (mkOrder 100 '' + programs.bash.initExtra = mkIf cfg.enableCompletion (lib.mkOrder 100 '' if [[ ! -v BASH_COMPLETION_VERSINFO ]]; then . "${pkgs.bash-completion}/etc/profile.d/bash_completion.sh" fi diff --git a/modules/programs/bashmount.nix b/modules/programs/bashmount.nix index 66c5809b..0ad3a397 100644 --- a/modules/programs/bashmount.nix +++ b/modules/programs/bashmount.nix @@ -1,19 +1,13 @@ { config, lib, pkgs, ... }: - -with lib; - -let - - cfg = config.programs.bashmount; - +let cfg = config.programs.bashmount; in { - meta.maintainers = [ maintainers.AndersonTorres ]; + meta.maintainers = [ lib.maintainers.AndersonTorres ]; options.programs.bashmount = { - enable = mkEnableOption "bashmount"; + enable = lib.mkEnableOption "bashmount"; - extraConfig = mkOption { - type = types.lines; + extraConfig = lib.mkOption { + type = lib.types.lines; default = ""; description = '' Configuration written to @@ -25,10 +19,10 @@ in { }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ pkgs.bashmount ]; xdg.configFile."bashmount/config" = - mkIf (cfg.extraConfig != "") { text = cfg.extraConfig; }; + lib.mkIf (cfg.extraConfig != "") { text = cfg.extraConfig; }; }; } diff --git a/modules/programs/beets.nix b/modules/programs/beets.nix index 5a2b97f3..e05db217 100644 --- a/modules/programs/beets.nix +++ b/modules/programs/beets.nix @@ -1,21 +1,19 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) literalExpression mkIf mkOption types; cfg = config.programs.beets; yamlFormat = pkgs.formats.yaml { }; in { - meta.maintainers = with maintainers; [ rycee Scrumplex ]; + meta.maintainers = with lib.maintainers; [ rycee Scrumplex ]; options = { programs.beets = { enable = mkOption { type = types.bool; - default = if versionAtLeast config.home.stateVersion "19.03" then + default = if lib.versionAtLeast config.home.stateVersion "19.03" then false else cfg.settings != { }; @@ -50,9 +48,9 @@ in { }; mpdIntegration = { - enableStats = mkEnableOption "mpdstats plugin and service"; + enableStats = lib.mkEnableOption "mpdstats plugin and service"; - enableUpdate = mkEnableOption "mpdupdate plugin"; + enableUpdate = lib.mkEnableOption "mpdupdate plugin"; host = mkOption { type = types.str; @@ -72,7 +70,7 @@ in { }; }; - config = mkMerge [ + config = lib.mkMerge [ (mkIf cfg.enable { home.packages = [ cfg.package ]; @@ -99,8 +97,8 @@ in { systemd.user.services."beets-mpdstats" = { Unit = { Description = "Beets MPDStats daemon"; - After = optional config.services.mpd.enable "mpd.service"; - Requires = optional config.services.mpd.enable "mpd.service"; + After = lib.optional config.services.mpd.enable "mpd.service"; + Requires = lib.optional config.services.mpd.enable "mpd.service"; }; Service.ExecStart = "${cfg.package}/bin/beet mpdstats"; Install.WantedBy = [ "default.target" ]; diff --git a/modules/programs/bemenu.nix b/modules/programs/bemenu.nix index 6c6e793f..959aa49e 100644 --- a/modules/programs/bemenu.nix +++ b/modules/programs/bemenu.nix @@ -1,23 +1,17 @@ { config, lib, pkgs, ... }: - -with lib; - -let - - cfg = config.programs.bemenu; - +let cfg = config.programs.bemenu; in { meta.maintainers = [ ]; options.programs.bemenu = { - enable = mkEnableOption "bemenu"; + enable = lib.mkEnableOption "bemenu"; - package = mkPackageOption pkgs "bemenu" { nullable = true; }; + package = lib.mkPackageOption pkgs "bemenu" { nullable = true; }; - settings = mkOption { - type = with types; attrsOf (oneOf [ str number bool ]); + settings = lib.mkOption { + type = with lib.types; attrsOf (oneOf [ str number bool ]); default = { }; - example = literalExpression '' + example = lib.literalExpression '' { line-height = 28; prompt = "open"; @@ -40,14 +34,16 @@ in { }; }; - config = mkIf cfg.enable { - assertions = - [ (hm.assertions.assertPlatform "programs.bemenu" pkgs platforms.linux) ]; + config = lib.mkIf cfg.enable { + assertions = [ + (lib.hm.assertions.assertPlatform "programs.bemenu" pkgs + lib.platforms.linux) + ]; home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; - home.sessionVariables = mkIf (cfg.settings != { }) { - BEMENU_OPTS = cli.toGNUCommandLineShell { } cfg.settings; + home.sessionVariables = lib.mkIf (cfg.settings != { }) { + BEMENU_OPTS = lib.cli.toGNUCommandLineShell { } cfg.settings; }; }; } diff --git a/modules/programs/borgmatic.nix b/modules/programs/borgmatic.nix index 92f171c2..67d36956 100644 --- a/modules/programs/borgmatic.nix +++ b/modules/programs/borgmatic.nix @@ -1,8 +1,7 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) literalExpression mkOption types; + cfg = config.programs.borgmatic; yamlFormat = pkgs.formats.yaml { }; @@ -72,8 +71,8 @@ let configModule = types.submodule ({ config, ... }: { config.location.extraConfig.exclude_from = - mkIf config.location.excludeHomeManagerSymlinks - (mkAfter [ (toString hmExcludeFile) ]); + lib.mkIf config.location.excludeHomeManagerSymlinks + (lib.mkAfter [ (toString hmExcludeFile) ]); options = { location = { sourceDirectories = mkNullableOption { @@ -208,7 +207,8 @@ let }; }); - removeNullValues = attrSet: filterAttrs (key: value: value != null) attrSet; + removeNullValues = attrSet: + lib.filterAttrs (key: value: value != null) attrSet; hmFiles = builtins.attrValues config.home.file; hmSymlinks = (lib.filter (file: !file.recursive) hmFiles); @@ -219,7 +219,7 @@ let hmExcludeFile = pkgs.writeText "hm-symlinks.txt" hmExcludePatterns; writeConfig = config: - generators.toYAML { } (removeNullValues ({ + lib.generators.toYAML { } (removeNullValues ({ source_directories = config.location.sourceDirectories; patterns = config.location.patterns; repositories = config.location.repositories; @@ -237,13 +237,13 @@ let // config.retention.extraConfig // config.consistency.extraConfig // config.output.extraConfig // config.hooks.extraConfig)); in { - meta.maintainers = [ maintainers.DamienCassou ]; + meta.maintainers = [ lib.maintainers.DamienCassou ]; options = { programs.borgmatic = { - enable = mkEnableOption "Borgmatic"; + enable = lib.mkEnableOption "Borgmatic"; - package = mkPackageOption pkgs "borgmatic" { nullable = true; }; + package = lib.mkPackageOption pkgs "borgmatic" { nullable = true; }; backups = mkOption { type = types.attrsOf configModule; @@ -271,14 +271,14 @@ in { }; }; - config = mkIf cfg.enable { - assertions = (mapAttrsToList (backup: opts: { + config = lib.mkIf cfg.enable { + assertions = (lib.mapAttrsToList (backup: opts: { assertion = opts.location.sourceDirectories == null || opts.location.patterns == null; message = '' Borgmatic backup configuration "${backup}" cannot specify both 'location.sourceDirectories' and 'location.patterns'. ''; - }) cfg.backups) ++ (mapAttrsToList (backup: opts: { + }) cfg.backups) ++ (lib.mapAttrsToList (backup: opts: { assertion = !(opts.location.sourceDirectories == null && opts.location.patterns == null); message = '' diff --git a/modules/programs/bottom.nix b/modules/programs/bottom.nix index fd18fe0d..3e82cbd8 100644 --- a/modules/programs/bottom.nix +++ b/modules/programs/bottom.nix @@ -1,7 +1,4 @@ { config, lib, pkgs, ... }: - -with lib; - let cfg = config.programs.bottom; @@ -11,18 +8,18 @@ let in { options = { programs.bottom = { - enable = mkEnableOption '' + enable = lib.mkEnableOption '' bottom, a cross-platform graphical process/system monitor with a customizable interface''; - package = mkOption { - type = types.package; + package = lib.mkOption { + type = lib.types.package; default = pkgs.bottom; - defaultText = literalExpression "pkgs.bottom"; + defaultText = lib.literalExpression "pkgs.bottom"; description = "Package providing {command}`bottom`."; }; - settings = mkOption { + settings = lib.mkOption { type = tomlFormat.type; default = { }; description = '' @@ -32,7 +29,7 @@ in { See for the default configuration. ''; - example = literalExpression '' + example = lib.literalExpression '' { flags = { avg_cpu = true; @@ -48,10 +45,10 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; - xdg.configFile."bottom/bottom.toml" = mkIf (cfg.settings != { }) { + xdg.configFile."bottom/bottom.toml" = lib.mkIf (cfg.settings != { }) { source = tomlFormat.generate "bottom.toml" cfg.settings; }; }; diff --git a/modules/programs/boxxy.nix b/modules/programs/boxxy.nix index dc6c1cbd..983282c2 100644 --- a/modules/programs/boxxy.nix +++ b/modules/programs/boxxy.nix @@ -1,6 +1,7 @@ { config, lib, pkgs, ... }: -with lib; let + inherit (lib) literalExpression mkOption types; + cfg = config.programs.boxxy; configPath = "${config.xdg.configHome}/boxxy/boxxy.yaml"; @@ -82,9 +83,9 @@ let }; in { options.programs.boxxy = { - enable = mkEnableOption "boxxy: Boxes in badly behaving applications"; + enable = lib.mkEnableOption "boxxy: Boxes in badly behaving applications"; - package = mkPackageOption pkgs "boxxy" { nullable = true; }; + package = lib.mkPackageOption pkgs "boxxy" { nullable = true; }; rules = mkOption { type = types.listOf boxxyRulesOpts; @@ -93,11 +94,13 @@ in { }; }; - config = mkIf cfg.enable { - assertions = - [ (hm.assertions.assertPlatform "programs.boxxy" pkgs platforms.linux) ]; + config = lib.mkIf cfg.enable { + assertions = [ + (lib.hm.assertions.assertPlatform "programs.boxxy" pkgs + lib.platforms.linux) + ]; - home.file = mkIf (cfg.rules != [ ]) { + home.file = lib.mkIf (cfg.rules != [ ]) { "${configPath}".source = settingsFormat.generate "boxxy-config.yaml" { rules = cfg.rules; }; }; diff --git a/modules/programs/broot.nix b/modules/programs/broot.nix index 8cc6338c..7449bc87 100644 --- a/modules/programs/broot.nix +++ b/modules/programs/broot.nix @@ -1,8 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) literalExpression mkIf mkOption mkRenamedOptionModule types; cfg = config.programs.broot; @@ -12,7 +10,7 @@ let freeformType = tomlFormat.type; options = { - modal = mkEnableOption "modal (vim) mode"; + modal = lib.mkEnableOption "modal (vim) mode"; verbs = mkOption { type = with types; listOf (attrsOf (oneOf [ bool str (listOf str) ])); @@ -121,14 +119,14 @@ let shellInit = shell: # Using mkAfter to make it more likely to appear after other # manipulations of the prompt. - mkAfter '' + lib.mkAfter '' source ${ pkgs.runCommand "br.${shell}" { nativeBuildInputs = [ cfg.package ]; } "broot --print-shell-function ${shell} > $out" } ''; in { - meta.maintainers = [ hm.maintainers.aheaume maintainers.dermetfan ]; + meta.maintainers = [ lib.hm.maintainers.aheaume lib.maintainers.dermetfan ]; imports = [ (mkRenamedOptionModule [ "programs" "broot" "modal" ] [ @@ -152,7 +150,7 @@ in { ]; options.programs.broot = { - enable = mkEnableOption "Broot, a better way to navigate directories"; + enable = lib.mkEnableOption "Broot, a better way to navigate directories"; enableBashIntegration = lib.hm.shell.mkBashIntegrationOption { inherit config; }; diff --git a/modules/programs/browserpass.nix b/modules/programs/browserpass.nix index fd3c5ad5..ea78f0a8 100644 --- a/modules/programs/browserpass.nix +++ b/modules/programs/browserpass.nix @@ -1,17 +1,14 @@ { config, lib, pkgs, ... }: - -with lib; - let cfg = config.programs.browserpass; browsers = [ "brave" "chrome" "chromium" "firefox" "librewolf" "vivaldi" ]; in { options = { programs.browserpass = { - enable = mkEnableOption "the browserpass extension host application"; + enable = lib.mkEnableOption "the browserpass extension host application"; - browsers = mkOption { - type = types.listOf (types.enum browsers); + browsers = lib.mkOption { + type = lib.types.listOf (lib.types.enum browsers); default = browsers; example = [ "firefox" ]; description = "Which browsers to install browserpass for"; @@ -19,8 +16,8 @@ in { }; }; - config = mkIf cfg.enable { - home.file = foldl' (a: b: a // b) { } (concatMap (x: + config = lib.mkIf cfg.enable { + home.file = lib.foldl' (a: b: a // b) { } (lib.concatMap (x: with pkgs.stdenv; if x == "brave" then let diff --git a/modules/programs/cava.nix b/modules/programs/cava.nix index 946656b0..f267ac24 100644 --- a/modules/programs/cava.nix +++ b/modules/programs/cava.nix @@ -1,25 +1,20 @@ { pkgs, config, lib, ... }: - -with lib; - let - cfg = config.programs.cava; iniFmt = pkgs.formats.ini { }; - in { - meta.maintainers = [ maintainers.bddvlpr ]; + meta.maintainers = [ lib.maintainers.bddvlpr ]; options.programs.cava = { - enable = mkEnableOption "Cava audio visualizer"; + enable = lib.mkEnableOption "Cava audio visualizer"; - package = mkPackageOption pkgs "cava" { nullable = true; }; + package = lib.mkPackageOption pkgs "cava" { nullable = true; }; - settings = mkOption { + settings = lib.mkOption { type = iniFmt.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { general.framerate = 60; input.method = "alsa"; @@ -38,14 +33,14 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; - xdg.configFile."cava/config" = mkIf (cfg.settings != { }) { + xdg.configFile."cava/config" = lib.mkIf (cfg.settings != { }) { text = '' ; Generated by Home Manager - ${generators.toINI { } cfg.settings} + ${lib.generators.toINI { } cfg.settings} ''; }; }; diff --git a/modules/programs/cavalier.nix b/modules/programs/cavalier.nix index 8ba05de9..6724ca15 100644 --- a/modules/programs/cavalier.nix +++ b/modules/programs/cavalier.nix @@ -1,8 +1,6 @@ { pkgs, config, lib, ... }: - -with lib; - let + inherit (lib) mkIf mkOption; cfg = config.programs.cavalier; @@ -11,18 +9,18 @@ let jsonFmt = pkgs.formats.json { }; in { - meta.maintainers = [ hm.maintainers.bricked ]; + meta.maintainers = [ lib.hm.maintainers.bricked ]; options.programs.cavalier = { - enable = mkEnableOption "Cava audio visualizer GUI"; + enable = lib.mkEnableOption "Cava audio visualizer GUI"; - package = mkPackageOption pkgs "cavalier" { nullable = true; }; + package = lib.mkPackageOption pkgs "cavalier" { nullable = true; }; settings = { general = mkOption { type = jsonFmt.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { ShowControls = true; ColorProfiles = [ @@ -55,7 +53,7 @@ in { cava = mkOption { type = iniFmt.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { general.framerate = 60; input.method = "alsa"; @@ -86,7 +84,7 @@ in { xdg.configFile = { "Nickvision Cavalier/config.json" = mkIf (cfg.settings.general != { }) { text = '' - ${generators.toJSON { } cfg.settings.general} + ${lib.generators.toJSON { } cfg.settings.general} ''; }; @@ -94,7 +92,7 @@ in { text = '' ; Generated by Home Manager - ${generators.toINI { } cfg.settings.cava} + ${lib.generators.toINI { } cfg.settings.cava} ''; }; }; diff --git a/modules/programs/chromium.nix b/modules/programs/chromium.nix index ffb488fc..2ef8571f 100644 --- a/modules/programs/chromium.nix +++ b/modules/programs/chromium.nix @@ -1,8 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) literalExpression mkOption types; supportedBrowsers = [ "chromium" @@ -16,7 +14,7 @@ let browserModule = defaultPkg: name: visible: let browser = (builtins.parseDrvName defaultPkg.name).name; - isProprietaryChrome = hasPrefix "Google Chrome" name; + isProprietaryChrome = lib.hasPrefix "Google Chrome" name; in { enable = mkOption { inherit visible; @@ -49,7 +47,7 @@ let [Chromium codesearch](https://source.chromium.org/search?q=file:switches.cc&ss=chromium%2Fchromium%2Fsrc). ''; }; - } // optionalAttrs (!isProprietaryChrome) { + } // lib.optionalAttrs (!isProprietaryChrome) { # Extensions do not work with Google Chrome # see https://github.com/nix-community/home-manager/issues/1383 extensions = mkOption { @@ -156,7 +154,7 @@ let drvName = (builtins.parseDrvName cfg.package.name).name; browser = if drvName == "ungoogled-chromium" then "chromium" else drvName; - isProprietaryChrome = hasPrefix "google-chrome" drvName; + isProprietaryChrome = lib.hasPrefix "google-chrome" drvName; darwinDirs = { chromium = "Chromium"; @@ -197,14 +195,14 @@ let package = if cfg.commandLineArgs != [ ] then cfg.package.override { - commandLineArgs = concatStringsSep " " cfg.commandLineArgs; + commandLineArgs = lib.concatStringsSep " " cfg.commandLineArgs; } else cfg.package; - in mkIf cfg.enable { + in lib.mkIf cfg.enable { home.packages = [ package ]; - home.file = optionalAttrs (!isProprietaryChrome) (listToAttrs + home.file = lib.optionalAttrs (!isProprietaryChrome) (lib.listToAttrs ((map extensionJson cfg.extensions) ++ (map dictionary cfg.dictionaries)) // { "${configDir}/NativeMessagingHosts" = @@ -219,7 +217,7 @@ let in { # Extensions do not work with the proprietary Google Chrome version # see https://github.com/nix-community/home-manager/issues/1383 - imports = map (flip mkRemovedOptionModule + imports = map (lib.flip lib.mkRemovedOptionModule "The `extensions` option does not work on Google Chrome anymore.") [ [ "programs" "google-chrome" "extensions" ] [ "programs" "google-chrome-beta" "extensions" ] @@ -237,6 +235,6 @@ in { vivaldi = browserModule pkgs.vivaldi "Vivaldi Browser" false; }; - config = mkMerge + config = lib.mkMerge (map (browser: browserConfig config.programs.${browser}) supportedBrowsers); } diff --git a/modules/programs/cmus.nix b/modules/programs/cmus.nix index ac3e46ee..a1a407f0 100644 --- a/modules/programs/cmus.nix +++ b/modules/programs/cmus.nix @@ -1,19 +1,13 @@ { config, lib, pkgs, ... }: - -with lib; - -let - - cfg = config.programs.cmus; - +let cfg = config.programs.cmus; in { - meta.maintainers = [ hm.maintainers.joygnu ]; + meta.maintainers = [ lib.hm.maintainers.joygnu ]; options.programs.cmus = { - enable = mkEnableOption "Enable cmus, the music player."; + enable = lib.mkEnableOption "Enable cmus, the music player."; - theme = mkOption { - type = types.lines; + theme = lib.mkOption { + type = lib.types.lines; default = ""; example = "gruvbox"; description = '' @@ -22,8 +16,8 @@ in { ''; }; - extraConfig = mkOption { - type = types.lines; + extraConfig = lib.mkOption { + type = lib.types.lines; default = ""; example = '' set audio_backend = "mpd" @@ -33,11 +27,11 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ pkgs.cmus ]; home.file.".config/cmus/rc".text = '' - ${optionalString (cfg.theme != "") "colorscheme ${cfg.theme}"} + ${lib.optionalString (cfg.theme != "") "colorscheme ${cfg.theme}"} ${cfg.extraConfig} ''; }; diff --git a/modules/programs/command-not-found/command-not-found.nix b/modules/programs/command-not-found/command-not-found.nix index c539e6e2..735944c9 100644 --- a/modules/programs/command-not-found/command-not-found.nix +++ b/modules/programs/command-not-found/command-not-found.nix @@ -1,9 +1,6 @@ # Adapted from Nixpkgs. { config, lib, pkgs, ... }: - -with lib; - let cfg = config.programs.command-not-found; commandNotFound = pkgs.substituteAll { @@ -31,9 +28,9 @@ let in { options.programs.command-not-found = { - enable = mkEnableOption "command-not-found hook for interactive shell"; + enable = lib.mkEnableOption "command-not-found hook for interactive shell"; - dbPath = mkOption { + dbPath = lib.mkOption { default = "/nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite"; description = '' @@ -41,11 +38,11 @@ in { default this file will be provided by your channel (nixexprs.tar.xz). ''; - type = types.path; + type = lib.types.path; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { programs.bash.initExtra = shInit "command_not_found_handle"; programs.zsh.initContent = shInit "command_not_found_handler"; diff --git a/modules/programs/darcs.nix b/modules/programs/darcs.nix index 263d668f..87917d82 100644 --- a/modules/programs/darcs.nix +++ b/modules/programs/darcs.nix @@ -1,22 +1,16 @@ { config, lib, pkgs, ... }: - -with lib; - -let - - cfg = config.programs.darcs; - +let cfg = config.programs.darcs; in { - meta.maintainers = with maintainers; [ chris-martin ]; + meta.maintainers = with lib.maintainers; [ chris-martin ]; options = { programs.darcs = { - enable = mkEnableOption "darcs"; + enable = lib.mkEnableOption "darcs"; - package = mkPackageOption pkgs "darcs" { nullable = true; }; + package = lib.mkPackageOption pkgs "darcs" { nullable = true; }; - author = mkOption { - type = types.listOf types.str; + author = lib.mkOption { + type = lib.types.listOf lib.types.str; default = [ ]; example = [ "Fred Bloggs " ]; description = '' @@ -26,8 +20,8 @@ in { ''; }; - boring = mkOption { - type = types.listOf types.str; + boring = lib.mkOption { + type = lib.types.listOf lib.types.str; default = [ ]; example = [ "^.idea$" ".iml$" "^.stack-work$" ]; description = "File patterns to ignore"; @@ -35,17 +29,17 @@ in { }; }; - config = mkIf cfg.enable (mkMerge [ + config = lib.mkIf cfg.enable (lib.mkMerge [ { home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; } - (mkIf (cfg.author != [ ]) { + (lib.mkIf (cfg.author != [ ]) { home.file.".darcs/author".text = - concatMapStrings (x: x + "\n") cfg.author; + lib.concatMapStrings (x: x + "\n") cfg.author; }) - (mkIf (cfg.boring != [ ]) { + (lib.mkIf (cfg.boring != [ ]) { home.file.".darcs/boring".text = - concatMapStrings (x: x + "\n") cfg.boring; + lib.concatMapStrings (x: x + "\n") cfg.boring; }) ]); diff --git a/modules/programs/dircolors.nix b/modules/programs/dircolors.nix index 85c1b433..99aac6ef 100644 --- a/modules/programs/dircolors.nix +++ b/modules/programs/dircolors.nix @@ -1,13 +1,11 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkDefault mkIf mkOption types; cfg = config.programs.dircolors; formatLine = n: v: "${n} ${toString v}"; in { - meta.maintainers = [ hm.maintainers.justinlovinger ]; + meta.maintainers = [ lib.hm.maintainers.justinlovinger ]; options.programs.dircolors = { enable = mkOption { @@ -36,7 +34,7 @@ in { See {command}`dircolors --print-database` for options. ''; - example = literalExpression '' + example = lib.literalExpression '' { OTHER_WRITABLE = "30;46"; ".sh" = "01;32"; @@ -60,10 +58,10 @@ in { else "~/.dir_colors"; - dircolorsConfig = concatStringsSep "\n" ([ ] - ++ mapAttrsToList formatLine cfg.settings ++ [ "" ] - ++ optional (cfg.extraConfig != "") cfg.extraConfig); - in mkIf cfg.enable (mkMerge [ + dircolorsConfig = lib.concatStringsSep "\n" ([ ] + ++ lib.mapAttrsToList formatLine cfg.settings ++ [ "" ] + ++ lib.optional (cfg.extraConfig != "") cfg.extraConfig); + in mkIf cfg.enable (lib.mkMerge [ { # Add default settings from `dircolors --print-database`. programs.dircolors.settings = { @@ -207,9 +205,10 @@ in { ''; # Set `LS_COLORS` before Oh My Zsh and `initExtra`. - programs.zsh.initContent = mkIf cfg.enableZshIntegration (mkOrder 550 '' - eval $(${pkgs.coreutils}/bin/dircolors -b ${dircolorsPath}) - ''); + programs.zsh.initContent = mkIf cfg.enableZshIntegration + (lib.mkOrder 550 '' + eval $(${pkgs.coreutils}/bin/dircolors -b ${dircolorsPath}) + ''); } (mkIf (!config.home.preferXdgDirectories) { home.file.".dir_colors".text = dircolorsConfig; diff --git a/modules/programs/discocss.nix b/modules/programs/discocss.nix index 7fa2c796..365d1a88 100644 --- a/modules/programs/discocss.nix +++ b/modules/programs/discocss.nix @@ -1,38 +1,36 @@ { config, lib, pkgs, ... }: - -with lib; - let cfg = config.programs.discocss; in { - meta.maintainers = with maintainers; [ kranzes ]; + meta.maintainers = with lib.maintainers; [ kranzes ]; options = { programs.discocss = { - enable = mkEnableOption + enable = lib.mkEnableOption "discocss, a tiny Discord CSS injector for Linux and MacOS"; - package = mkPackageOption pkgs "discocss" { nullable = true; }; + package = lib.mkPackageOption pkgs "discocss" { nullable = true; }; - discordPackage = mkPackageOption pkgs "discord" { nullable = true; }; + discordPackage = lib.mkPackageOption pkgs "discord" { nullable = true; }; - discordAlias = mkOption { - type = types.bool; + discordAlias = lib.mkOption { + type = lib.types.bool; default = true; description = "Whether to alias discocss to discord."; }; - css = mkOption { - type = types.str; + css = lib.mkOption { + type = lib.types.str; default = ""; description = "The custom CSS for discocss to use."; }; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [{ assertion = cfg.discordAlias - -> !(any (p: p.name == cfg.discordPackage.name) config.home.packages); + -> !(lib.any (p: p.name == cfg.discordPackage.name) + config.home.packages); message = "To use discocss with discordAlias you have to remove discord from home.packages, or set discordAlias to false."; }]; diff --git a/modules/programs/eclipse.nix b/modules/programs/eclipse.nix index 7d4b2806..8bc495be 100644 --- a/modules/programs/eclipse.nix +++ b/modules/programs/eclipse.nix @@ -1,17 +1,14 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkIf mkOption types; cfg = config.programs.eclipse; - in { - meta.maintainers = [ maintainers.rycee ]; + meta.maintainers = [ lib.maintainers.rycee ]; options = { programs.eclipse = { - enable = mkEnableOption "Eclipse"; + enable = lib.mkEnableOption "Eclipse"; package = lib.mkPackageOption pkgs "eclipse" { default = [ "eclipses" "eclipse-platform" ]; @@ -46,7 +43,7 @@ in { home.packages = [ (pkgs.eclipses.eclipseWithPlugins { eclipse = cfg.package; - jvmArgs = cfg.jvmArgs ++ optional cfg.enableLombok + jvmArgs = cfg.jvmArgs ++ lib.optional cfg.enableLombok "-javaagent:${pkgs.lombok}/share/java/lombok.jar"; plugins = cfg.plugins; }) diff --git a/modules/programs/emacs.nix b/modules/programs/emacs.nix index d6372149..bbeb2fca 100644 --- a/modules/programs/emacs.nix +++ b/modules/programs/emacs.nix @@ -1,8 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) literalExpression mkIf mkOption types; cfg = config.programs.emacs; @@ -22,14 +20,14 @@ let version = "0.1.0"; packageRequires = packages; }; - in packages ++ optional (cfg.extraConfig != "") userConfig; + in packages ++ lib.optional (cfg.extraConfig != "") userConfig; in { - meta.maintainers = [ maintainers.rycee ]; + meta.maintainers = [ lib.maintainers.rycee ]; options = { programs.emacs = { - enable = mkEnableOption "Emacs"; + enable = lib.mkEnableOption "Emacs"; package = mkOption { type = types.package; @@ -62,7 +60,7 @@ in { extraPackages = mkOption { default = self: [ ]; - type = hm.types.selectorFunction; + type = lib.hm.types.selectorFunction; defaultText = "epkgs: []"; example = literalExpression "epkgs: [ epkgs.emms epkgs.magit ]"; description = '' @@ -74,7 +72,7 @@ in { overrides = mkOption { default = self: super: { }; - type = hm.types.overlayFunction; + type = lib.hm.types.overlayFunction; defaultText = "self: super: {}"; example = literalExpression '' self: super: rec { diff --git a/modules/programs/eww.nix b/modules/programs/eww.nix index e9280d95..d84644a4 100644 --- a/modules/programs/eww.nix +++ b/modules/programs/eww.nix @@ -1,24 +1,20 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkIf; cfg = config.programs.eww; - ewwCmd = "${cfg.package}/bin/eww"; - in { - meta.maintainers = [ hm.maintainers.mainrs ]; + meta.maintainers = [ lib.hm.maintainers.mainrs ]; options.programs.eww = { - enable = mkEnableOption "eww"; + enable = lib.mkEnableOption "eww"; package = lib.mkPackageOption pkgs "eww" { }; - configDir = mkOption { - type = types.nullOr types.path; + configDir = lib.mkOption { + type = lib.types.nullOr lib.types.path; default = null; - example = literalExpression "./eww-config-dir"; + example = lib.literalExpression "./eww-config-dir"; description = '' The directory that gets symlinked to {file}`$XDG_CONFIG_HOME/eww`. @@ -35,7 +31,8 @@ in { lib.hm.shell.mkZshIntegrationOption { inherit config; }; }; - config = mkIf cfg.enable { + config = let ewwCmd = lib.getExe cfg.package; + in mkIf cfg.enable { home.packages = [ cfg.package ]; xdg = mkIf (cfg.configDir != null) { configFile."eww".source = cfg.configDir; }; diff --git a/modules/programs/eza.nix b/modules/programs/eza.nix index 14547d73..b3071016 100644 --- a/modules/programs/eza.nix +++ b/modules/programs/eza.nix @@ -1,8 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; - -{ +let inherit (lib) mkOption optionalAttrs types; +in { imports = let msg = '' 'programs.eza.enableAliases' has been deprecated and replaced with integration @@ -12,14 +10,18 @@ with lib; aliases you can simply remove 'programs.eza.enableAliases' from your configuration.''; mkRenamed = opt: - mkRenamedOptionModule [ "programs" "exa" opt ] [ "programs" "eza" opt ]; + lib.mkRenamedOptionModule [ "programs" "exa" opt ] [ + "programs" + "eza" + opt + ]; in (map mkRenamed [ "enable" "extraOptions" "icons" "git" ]) - ++ [ (mkRemovedOptionModule [ "programs" "eza" "enableAliases" ] msg) ]; + ++ [ (lib.mkRemovedOptionModule [ "programs" "eza" "enableAliases" ] msg) ]; - meta.maintainers = [ maintainers.cafkafk ]; + meta.maintainers = [ lib.maintainers.cafkafk ]; options.programs.eza = { - enable = mkEnableOption "eza, a modern replacement for {command}`ls`"; + enable = lib.mkEnableOption "eza, a modern replacement for {command}`ls`"; enableBashIntegration = lib.hm.shell.mkBashIntegrationOption { inherit config; }; @@ -72,22 +74,22 @@ with lib; ''; }; - package = mkPackageOption pkgs "eza" { nullable = true; }; + package = lib.mkPackageOption pkgs "eza" { nullable = true; }; }; config = let cfg = config.programs.eza; iconsOption = let - v = if isBool cfg.icons then + v = if lib.isBool cfg.icons then (if cfg.icons then "auto" else null) else cfg.icons; - in optionals (v != null) [ "--icons" v ]; + in lib.optionals (v != null) [ "--icons" v ]; - args = escapeShellArgs (iconsOption - ++ optionals (cfg.colors != null) [ "--color" cfg.colors ] - ++ optional cfg.git "--git" ++ cfg.extraOptions); + args = lib.escapeShellArgs (iconsOption + ++ lib.optionals (cfg.colors != null) [ "--color" cfg.colors ] + ++ lib.optional cfg.git "--git" ++ cfg.extraOptions); optionsAlias = optionalAttrs (args != "") { eza = "eza ${args}"; }; @@ -98,8 +100,8 @@ with lib; lt = "eza --tree"; lla = "eza -la"; }; - in mkIf cfg.enable { - warnings = optional (isBool cfg.icons) '' + in lib.mkIf cfg.enable { + warnings = lib.optional (lib.isBool cfg.icons) '' Setting programs.eza.icons to a Boolean is deprecated. Please update your configuration so that @@ -113,13 +115,13 @@ with lib; programs.zsh.shellAliases = optionsAlias // optionalAttrs cfg.enableZshIntegration aliases; - programs.fish = mkMerge [ - (mkIf (!config.programs.fish.preferAbbrs) { + programs.fish = lib.mkMerge [ + (lib.mkIf (!config.programs.fish.preferAbbrs) { shellAliases = optionsAlias // optionalAttrs cfg.enableFishIntegration aliases; }) - (mkIf config.programs.fish.preferAbbrs { + (lib.mkIf config.programs.fish.preferAbbrs { shellAliases = optionsAlias; shellAbbrs = optionalAttrs cfg.enableFishIntegration aliases; }) diff --git a/modules/programs/fd.nix b/modules/programs/fd.nix index 17911ebe..603c0405 100644 --- a/modules/programs/fd.nix +++ b/modules/programs/fd.nix @@ -1,9 +1,10 @@ { config, lib, pkgs, ... }: -with lib; { - meta.maintainers = [ maintainers.uncenter ]; +let inherit (lib) mkOption types; +in { + meta.maintainers = [ lib.maintainers.uncenter ]; options.programs.fd = { - enable = mkEnableOption + enable = lib.mkEnableOption "fd, a simple, fast and user-friendly alternative to {command}`find`"; ignores = mkOption { @@ -30,16 +31,17 @@ with lib; { ''; }; - package = mkPackageOption pkgs "fd" { nullable = true; }; + package = lib.mkPackageOption pkgs "fd" { nullable = true; }; }; config = let cfg = config.programs.fd; - args = escapeShellArgs (optional cfg.hidden "--hidden" ++ cfg.extraOptions); + args = lib.escapeShellArgs + (lib.optional cfg.hidden "--hidden" ++ cfg.extraOptions); - optionsAlias = optionalAttrs (args != "") { fd = "fd ${args}"; }; - in mkIf cfg.enable { + optionsAlias = lib.optionalAttrs (args != "") { fd = "fd ${args}"; }; + in lib.mkIf cfg.enable { home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; programs.bash.shellAliases = optionsAlias; @@ -52,8 +54,8 @@ with lib; { programs.nushell.shellAliases = optionsAlias; - xdg.configFile."fd/ignore" = mkIf (cfg.ignores != [ ]) { - text = concatStringsSep "\n" cfg.ignores + "\n"; + xdg.configFile."fd/ignore" = lib.mkIf (cfg.ignores != [ ]) { + text = lib.concatStringsSep "\n" cfg.ignores + "\n"; }; }; } diff --git a/modules/programs/feh.nix b/modules/programs/feh.nix index b96c9a27..661a2fe9 100644 --- a/modules/programs/feh.nix +++ b/modules/programs/feh.nix @@ -1,8 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) filterAttrs mapAttrsToList mkOption types; cfg = config.programs.feh; @@ -10,30 +8,30 @@ let renderThemes = options: let - render = - mapAttrsToList (theme: options: "${theme} ${escapeShellArgs options}"); - in concatStringsSep "\n" (render options); + render = mapAttrsToList + (theme: options: "${theme} ${lib.escapeShellArgs options}"); + in lib.concatStringsSep "\n" (render options); renderBindings = bindings: let enabled = filterAttrs (n: v: v != null) bindings; disabled = filterAttrs (n: v: v == null) bindings; render = mapAttrsToList renderBinding; - in concatStringsSep "\n" (render disabled ++ render enabled); + in lib.concatStringsSep "\n" (render disabled ++ render enabled); renderBinding = func: key: if key == null then func - else if isList key then - concatStringsSep " " ([ func ] ++ map toString key) + else if lib.isList key then + lib.concatStringsSep " " ([ func ] ++ map toString key) else "${func} ${toString key}"; in { options.programs.feh = { - enable = mkEnableOption "feh - a fast and light image viewer"; + enable = lib.mkEnableOption "feh - a fast and light image viewer"; - package = mkPackageOption pkgs "feh" { nullable = true; }; + package = lib.mkPackageOption pkgs "feh" { nullable = true; }; buttons = mkOption { default = { }; @@ -97,7 +95,7 @@ in { }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [{ assertion = ((filterAttrs (n: v: v == "") cfg.keybindings) == { }); message = @@ -106,14 +104,15 @@ in { home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; - xdg.configFile."feh/buttons" = - mkIf (cfg.buttons != { }) { text = renderBindings cfg.buttons + "\n"; }; + xdg.configFile."feh/buttons" = lib.mkIf (cfg.buttons != { }) { + text = renderBindings cfg.buttons + "\n"; + }; - xdg.configFile."feh/keys" = mkIf (cfg.keybindings != { }) { + xdg.configFile."feh/keys" = lib.mkIf (cfg.keybindings != { }) { text = renderBindings cfg.keybindings + "\n"; }; xdg.configFile."feh/themes" = - mkIf (cfg.themes != { }) { text = renderThemes cfg.themes + "\n"; }; + lib.mkIf (cfg.themes != { }) { text = renderThemes cfg.themes + "\n"; }; }; } diff --git a/modules/programs/firefox.nix b/modules/programs/firefox.nix index 01cab9bd..0b8a80ef 100644 --- a/modules/programs/firefox.nix +++ b/modules/programs/firefox.nix @@ -1,14 +1,18 @@ { lib, ... }: -with lib; let + inherit (lib) mkRemovedOptionModule; + modulePath = [ "programs" "firefox" ]; - moduleName = concatStringsSep "." modulePath; + moduleName = lib.concatStringsSep "." modulePath; mkFirefoxModule = import ./firefox/mkFirefoxModule.nix; in { - meta.maintainers = - [ maintainers.rycee hm.maintainers.bricked hm.maintainers.HPsaucii ]; + meta.maintainers = [ + lib.maintainers.rycee + lib.hm.maintainers.bricked + lib.hm.maintainers.HPsaucii + ]; imports = [ (mkFirefoxModule { @@ -18,7 +22,7 @@ in { unwrappedPackageName = "firefox-unwrapped"; visible = true; - platforms.linux = rec { configPath = ".mozilla/firefox"; }; + platforms.linux = { configPath = ".mozilla/firefox"; }; platforms.darwin = { configPath = "Library/Application Support/Firefox"; }; diff --git a/modules/programs/firefox/mkFirefoxModule.nix b/modules/programs/firefox/mkFirefoxModule.nix index 341c8ba1..6440d816 100644 --- a/modules/programs/firefox/mkFirefoxModule.nix +++ b/modules/programs/firefox/mkFirefoxModule.nix @@ -2,21 +2,24 @@ , unwrappedPackageName ? null, platforms, visible ? false , enableBookmarks ? true, }: { config, lib, pkgs, ... }: -with lib; let + inherit (lib) + attrValues concatStringsSep length literalExpression mapAttrsToList mkIf + mkMerge mkOption optionalString optional setAttrByPath types; inherit (pkgs.stdenv.hostPlatform) isDarwin; appName = name; moduleName = concatStringsSep "." modulePath; - cfg = getAttrFromPath modulePath config; + cfg = lib.getAttrFromPath modulePath config; jsonFormat = pkgs.formats.json { }; - supportedPlatforms = flatten (attrVals (attrNames platforms) lib.platforms); + supportedPlatforms = + lib.flatten (lib.attrVals (lib.attrNames platforms) lib.platforms); - isWrapped = versionAtLeast config.home.stateVersion "19.09" + isWrapped = lib.versionAtLeast config.home.stateVersion "19.09" && wrappedPackageName != null; defaultPackageName = @@ -34,8 +37,8 @@ let # by future browser versions. extensionPath = "extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"; - profiles = flip mapAttrs' cfg.profiles (_: profile: - nameValuePair "Profile${toString profile.id}" { + profiles = lib.flip lib.mapAttrs' cfg.profiles (_: profile: + lib.nameValuePair "Profile${toString profile.id}" { Name = profile.name; Path = if isDarwin then "Profiles/${profile.path}" else profile.path; IsRelative = 1; @@ -48,10 +51,11 @@ let }; }; - profilesIni = generators.toINI { } profiles; + profilesIni = lib.generators.toINI { } profiles; userPrefValue = pref: - builtins.toJSON (if isBool pref || isInt pref || isString pref then + builtins.toJSON + (if lib.isBool pref || lib.isInt pref || lib.isString pref then pref else builtins.toJSON pref); @@ -69,7 +73,7 @@ let ${prePrefs} - ${concatStrings (mapAttrsToList (name: value: '' + ${lib.concatStrings (mapAttrsToList (name: value: '' user_pref("${name}", ${userPrefValue value}); '') prefs')} @@ -88,8 +92,8 @@ let in '' ${builtins.toJSON { version = 5; - lastUserContextId = - foldlAttrs (acc: _: value: if value.id > acc then value.id else acc) 0 + lastUserContextId = lib.foldlAttrs + (acc: _: value: if value.id > acc then value.id else acc) 0 containers; identities = mapAttrsToList containerToIdentity containers ++ [ { @@ -119,8 +123,8 @@ let # the result only if more than one entity has it. The argument # entities is a list of AttrSet of one id/name pair. findDuplicateIds = entities: - filterAttrs (_entityId: entityNames: length entityNames != 1) - (zipAttrs entities); + lib.filterAttrs (_entityId: entityNames: length entityNames != 1) + (lib.zipAttrs entities); duplicates = findDuplicateIds (mapAttrsToList (entityName: entity: { "${toString entity.id}" = entityName; }) @@ -261,7 +265,7 @@ in { description = "Resulting ${appName} package."; }; - policies = optionalAttrs (wrappedPackageName != null) (mkOption { + policies = lib.optionalAttrs (wrappedPackageName != null) (mkOption { inherit visible; type = types.attrsOf jsonFormat.type; default = { }; @@ -528,7 +532,7 @@ in { }; extensions = mkOption { type = types.coercedTo (types.listOf types.package) (packages: { - packages = mkIf (builtins.length packages > 0) (warn '' + packages = mkIf (builtins.length packages > 0) (lib.warn '' In order to support declarative extension configuration, extension installation has been moved from ${moduleName}.profiles..extensions @@ -694,11 +698,11 @@ in { config = mkIf cfg.enable ({ assertions = [ - (hm.assertions.assertPlatform moduleName pkgs supportedPlatforms) + (lib.hm.assertions.assertPlatform moduleName pkgs supportedPlatforms) (let - defaults = - catAttrs "name" (filter (a: a.isDefault) (attrValues cfg.profiles)); + defaults = lib.catAttrs "name" + (lib.filter (a: a.isDefault) (attrValues cfg.profiles)); in { assertion = cfg.profiles == { } || length defaults == 1; message = "Must have exactly one default ${appName} profile but found " @@ -708,11 +712,11 @@ in { (let getContainers = profiles: - flatten + lib.flatten (mapAttrsToList (_: value: (attrValues value.containers)) profiles); findInvalidContainerIds = profiles: - filter (container: container.id >= 4294967294) + lib.filter (container: container.id >= 4294967294) (getContainers profiles); in { assertion = cfg.profiles == { } @@ -729,7 +733,8 @@ in { } (mkNoDuplicateAssertion cfg.profiles "profile") - ] ++ (concatMap (profile: profile.assertions) (attrValues cfg.profiles)); + ] ++ (lib.concatMap (profile: profile.assertions) + (attrValues cfg.profiles)); warnings = optional (cfg.enableGnomeExtensions or false) '' Using '${moduleName}.enableGnomeExtensions' has been deprecated and @@ -750,7 +755,7 @@ in { home.file = mkMerge ([{ "${cfg.configPath}/profiles.ini" = mkIf (cfg.profiles != { }) { text = profilesIni; }; - }] ++ flip mapAttrsToList cfg.profiles (_: profile: + }] ++ lib.flip mapAttrsToList cfg.profiles (_: profile: # Merge the regular profile settings with extension settings mkMerge ([{ "${profilesPath}/${profile.path}/.keep".text = ""; @@ -808,16 +813,16 @@ in { "${profilesPath}/${profile.path}/browser-extension-data/${name}/storage.js" = { force = settingConfig.force || profile.extensions.force; - text = generators.toJSON { } settingConfig.settings; + text = lib.generators.toJSON { } settingConfig.settings; }; }) profile.extensions.settings))))); } // setAttrByPath modulePath { finalPackage = wrapPackage cfg.package; policies = { - ExtensionSettings = lib.mkIf (cfg.languagePacks != [ ]) (listToAttrs (map - (lang: - nameValuePair "langpack-${lang}@firefox.mozilla.org" { + ExtensionSettings = lib.mkIf (cfg.languagePacks != [ ]) (lib.listToAttrs + (map (lang: + lib.nameValuePair "langpack-${lang}@firefox.mozilla.org" { installation_mode = "normal_installed"; install_url = "https://releases.mozilla.org/pub/firefox/releases/${cfg.package.version}/linux-x86_64/xpi/${lang}.xpi"; diff --git a/modules/programs/firefox/profiles/search.nix b/modules/programs/firefox/profiles/search.nix index 5b56aba1..df4be28e 100644 --- a/modules/programs/firefox/profiles/search.nix +++ b/modules/programs/firefox/profiles/search.nix @@ -1,14 +1,13 @@ { config, lib, pkgs, appName, package, modulePath, profilePath }: - -with lib; - let + inherit (lib) mapAttrs mapAttrs' mkOption optionalAttrs types warn; + jsonFormat = pkgs.formats.json { }; # Map of nice field names to internal field names. # This is intended to be exhaustive and should be # updated at every version bump. - internalFieldNames = (genAttrs [ + internalFieldNames = (lib.genAttrs [ "name" "isAppProvided" "loadPath" @@ -25,7 +24,10 @@ let # Convenience to specify absolute path to icon iconUrl = icon: - if isPath icon || hasPrefix "/" icon then "file://${icon}" else icon; + if lib.isPath icon || lib.hasPrefix "/" icon then + "file://${icon}" + else + icon; processCustomEngineInput = input: { @@ -56,7 +58,7 @@ let in if requiredInput.isAppProvided then requiredInput else - pipe (input // requiredInput) [ + lib.pipe (input // requiredInput) [ migrateEngineToV11 migrateEngineToV12 processCustomEngineInput @@ -79,9 +81,10 @@ let }; in config // { _metaData = config._metaData // { inherit order; }; }; - engineConfigsWithoutOrder = attrValues (removeAttrs configs config.order); + engineConfigsWithoutOrder = + lib.attrValues (removeAttrs configs config.order); - sortedEngineConfigs = (imap buildEngineConfigWithOrder config.order) + sortedEngineConfigs = (lib.imap buildEngineConfigWithOrder config.order) ++ engineConfigsWithoutOrder; in sortedEngineConfigs; @@ -330,7 +333,7 @@ let migrateEngineToV11 = engine: engine // lib.optionalAttrs (engine ? iconMapObj) { iconMapObj = mapAttrs' (name: value: - let nameToIntResult = builtins.tryEval (toInt name); + let nameToIntResult = builtins.tryEval (lib.toInt name); in { name = if nameToIntResult.success then name @@ -348,20 +351,21 @@ let let iconMapObj = optionalAttrs (engine ? iconURL) { "16" = warn "'iconURL' is deprecated, use 'icon = ${ - strings.escapeNixString engine.iconURL + lib.strings.escapeNixString engine.iconURL }' instead" engine.iconURL; } // optionalAttrs (engine ? iconUpdateURL) { "16" = warn "'iconUpdateURL' is deprecated, use 'icon = ${ - strings.escapeNixString engine.iconUpdateURL + lib.strings.escapeNixString engine.iconUpdateURL }' instead" engine.iconUpdateURL; } // (engine.iconMapObj or { }); - in throwIf (engine ? hasPreferredIcon) "hasPreferredIcon has been removed" + in lib.throwIf (engine ? hasPreferredIcon) + "hasPreferredIcon has been removed" (removeAttrs engine [ "iconURL" "iconUpdateURL" ]) // lib.optionalAttrs (iconMapObj != { }) { inherit iconMapObj; }; in { imports = [ (pkgs.path + "/nixos/modules/misc/meta.nix") ]; - meta.maintainers = with maintainers; [ kira-bruneau ]; + meta.maintainers = with lib.maintainers; [ kira-bruneau ]; options = { enable = mkOption { @@ -427,7 +431,7 @@ in { }); default = { }; - example = literalExpression '' + example = lib.literalExpression '' { nix-packages = { name = "Nix Packages"; diff --git a/modules/programs/fish.nix b/modules/programs/fish.nix index aff95613..987b8f28 100644 --- a/modules/programs/fish.nix +++ b/modules/programs/fish.nix @@ -1,8 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) isAttrs literalExpression mkIf mkOption optional types; cfg = config.programs.fish; @@ -115,7 +113,7 @@ let example = [ "SIGHUP" "HUP" 1 ]; description = '' Tells fish to run this function when the specified signal is - delievered. The signal can be a signal number or signal name. + delivered. The signal can be a signal number or signal name. ''; }; @@ -197,31 +195,31 @@ let }; }; - abbrsStr = concatStringsSep "\n" (mapAttrsToList (name: def: + abbrsStr = lib.concatStringsSep "\n" (lib.mapAttrsToList (name: def: let - mods = with def; - cli.toGNUCommandLineShell { - mkOption = k: v: - if v == null then - [ ] - else if k == "set-cursor" then - [ "--${k}=${lib.generators.mkValueStringDefault { } v}" ] - else [ - "--${k}" - (lib.generators.mkValueStringDefault { } v) - ]; - } { - inherit position regex command function; - set-cursor = setCursor; - }; + mods = lib.cli.toGNUCommandLineShell { + mkOption = k: v: + if v == null then + [ ] + else if k == "set-cursor" then + [ "--${k}=${lib.generators.mkValueStringDefault { } v}" ] + else [ + "--${k}" + (lib.generators.mkValueStringDefault { } v) + ]; + } { + inherit (def) position regex command function; + set-cursor = def.setCursor; + }; modifiers = if isAttrs def then mods else ""; expansion = if isAttrs def then def.expansion else def; in "abbr --add ${modifiers} -- ${name}" - + optionalString (expansion != null) " ${escapeShellArg expansion}") + + lib.optionalString (expansion != null) " ${lib.escapeShellArg expansion}") cfg.shellAbbrs); - aliasesStr = concatStringsSep "\n" - (mapAttrsToList (k: v: "alias ${k} ${escapeShellArg v}") cfg.shellAliases); + aliasesStr = lib.concatStringsSep "\n" + (lib.mapAttrsToList (k: v: "alias ${k} ${lib.escapeShellArg v}") + cfg.shellAliases); fishIndent = name: text: pkgs.runCommand name { @@ -241,7 +239,7 @@ let in { imports = [ - (mkRemovedOptionModule [ "programs" "fish" "promptInit" ] '' + (lib.mkRemovedOptionModule [ "programs" "fish" "promptInit" ] '' Prompt is now configured through the programs.fish.interactiveShellInit @@ -252,11 +250,11 @@ in { options = { programs.fish = { - enable = mkEnableOption "fish, the friendly interactive shell"; + enable = lib.mkEnableOption "fish, the friendly interactive shell"; package = lib.mkPackageOption pkgs "fish" { }; - generateCompletions = mkEnableOption + generateCompletions = lib.mkEnableOption "the automatic generation of completions based upon installed man pages" // { default = true; @@ -398,15 +396,15 @@ in { }; }; - config = mkIf cfg.enable (mkMerge [ + config = mkIf cfg.enable (lib.mkMerge [ { home.packages = [ cfg.package ]; } (mkIf cfg.generateCompletions { # Support completion for `man` by building a cache for `apropos`. - programs.man.generateCaches = mkDefault true; + programs.man.generateCaches = lib.mkDefault true; xdg.dataFile."fish/home-manager_generated_completions".source = let - # paths later in the list will overwrite those already linked + # Paths later in the list will overwrite those already linked destructiveSymlinkJoin = args_@{ name, paths, preferLocalBuild ? true , allowSubstitutes ? false, postBuild ? "", ... }: let @@ -431,7 +429,7 @@ in { }"; in package: pkgs.runCommand "${getName package}-fish-completions" { - srcs = [ package ] ++ filter (p: p != null) + srcs = [ package ] ++ lib.filter (p: p != null) (builtins.map (outName: package.${outName} or null) config.home.extraOutputsToInstall); nativeBuildInputs = [ pkgs.python3 ]; @@ -451,7 +449,7 @@ in { name = "${config.home.username}-fish-completions"; paths = let cmp = (a: b: (a.meta.priority or 0) > (b.meta.priority or 0)); - in map generateCompletions (sort cmp config.home.packages); + in map generateCompletions (lib.sort cmp config.home.packages); }; programs.fish.interactiveShellInit = '' @@ -504,7 +502,7 @@ in { ''; } { - xdg.configFile = mapAttrs' (name: def: { + xdg.configFile = lib.mapAttrs' (name: def: { name = "fish/functions/${name}.fish"; value = { source = let @@ -536,8 +534,8 @@ in { # Each plugin gets a corresponding conf.d/plugin-NAME.fish file to load # in the paths and any initialization scripts. - (mkIf (length cfg.plugins > 0) { - xdg.configFile = mkMerge ((map (plugin: { + (mkIf (lib.length cfg.plugins > 0) { + xdg.configFile = lib.mkMerge (map (plugin: { "fish/conf.d/plugin-${plugin.name}.fish".source = fishIndent "${plugin.name}.fish" '' # Plugin ${plugin.name} @@ -567,7 +565,7 @@ in { source $plugin_dir/init.fish end ''; - }) cfg.plugins)); + }) cfg.plugins); }) ]); } diff --git a/modules/programs/floorp.nix b/modules/programs/floorp.nix index 75616b7e..32cdb446 100644 --- a/modules/programs/floorp.nix +++ b/modules/programs/floorp.nix @@ -1,15 +1,10 @@ { lib, ... }: - -with lib; - let - modulePath = [ "programs" "floorp" ]; mkFirefoxModule = import ./firefox/mkFirefoxModule.nix; - in { - meta.maintainers = [ hm.maintainers.bricked ]; + meta.maintainers = [ lib.hm.maintainers.bricked ]; imports = [ (mkFirefoxModule { diff --git a/modules/programs/foot.nix b/modules/programs/foot.nix index 1485304a..ec7e8dbd 100644 --- a/modules/programs/foot.nix +++ b/modules/programs/foot.nix @@ -1,23 +1,18 @@ { config, lib, pkgs, ... }: - -with lib; - let - cfg = config.programs.foot; iniFormat = pkgs.formats.ini { }; - in { meta.maintainers = with lib.maintainers; [ plabadens ]; options.programs.foot = { - enable = mkEnableOption "Foot terminal"; + enable = lib.mkEnableOption "Foot terminal"; package = lib.mkPackageOption pkgs "foot" { }; - server.enable = mkEnableOption "Foot terminal server"; + server.enable = lib.mkEnableOption "Foot terminal server"; - settings = mkOption { + settings = lib.mkOption { type = iniFormat.type; default = { }; description = '' @@ -25,7 +20,7 @@ in { {file}`$XDG_CONFIG_HOME/foot/foot.ini`. See for a list of available options. ''; - example = literalExpression '' + example = lib.literalExpression '' { main = { term = "xterm-256color"; @@ -42,17 +37,19 @@ in { }; }; - config = mkIf cfg.enable { - assertions = - [ (hm.assertions.assertPlatform "programs.foot" pkgs platforms.linux) ]; + config = lib.mkIf cfg.enable { + assertions = [ + (lib.hm.assertions.assertPlatform "programs.foot" pkgs + lib.platforms.linux) + ]; home.packages = [ cfg.package ]; - xdg.configFile."foot/foot.ini" = mkIf (cfg.settings != { }) { + xdg.configFile."foot/foot.ini" = lib.mkIf (cfg.settings != { }) { source = iniFormat.generate "foot.ini" cfg.settings; }; - systemd.user.services = mkIf cfg.server.enable { + systemd.user.services = lib.mkIf cfg.server.enable { foot = { Unit = { Description = diff --git a/modules/programs/fzf.nix b/modules/programs/fzf.nix index 76c5e2c4..73cff7c3 100644 --- a/modules/programs/fzf.nix +++ b/modules/programs/fzf.nix @@ -1,14 +1,12 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) getExe literalExpression mkIf mkOption mkOrder types; cfg = config.programs.fzf; renderedColors = colors: - concatStringsSep "," - (mapAttrsToList (name: value: "${name}:${value}") colors); + lib.concatStringsSep "," + (lib.mapAttrsToList (name: value: "${name}:${value}") colors); hasShellIntegrationEmbedded = lib.versionAtLeast cfg.package.version "0.48.0"; @@ -41,14 +39,14 @@ let ''; in { imports = [ - (mkRemovedOptionModule [ "programs" "fzf" "historyWidgetCommand" ] + (lib.mkRemovedOptionModule [ "programs" "fzf" "historyWidgetCommand" ] "This option is no longer supported by fzf.") ]; meta.maintainers = with lib.maintainers; [ khaneliman ]; options.programs.fzf = { - enable = mkEnableOption "fzf - a command-line fuzzy finder"; + enable = lib.mkEnableOption "fzf - a command-line fuzzy finder"; package = mkOption { type = types.package; @@ -142,7 +140,7 @@ in { }; tmux = { - enableShellIntegration = mkEnableOption '' + enableShellIntegration = lib.mkEnableOption '' setting `FZF_TMUX=1` which causes shell integration to use fzf-tmux ''; @@ -171,8 +169,8 @@ in { config = mkIf cfg.enable { home.packages = [ cfg.package ]; - home.sessionVariables = mapAttrs (n: v: toString v) - (filterAttrs (n: v: v != [ ] && v != null) { + home.sessionVariables = lib.mapAttrs (n: v: toString v) + (lib.filterAttrs (n: v: v != [ ] && v != null) { FZF_ALT_C_COMMAND = cfg.changeDirWidgetCommand; FZF_ALT_C_OPTS = cfg.changeDirWidgetOptions; FZF_CTRL_R_OPTS = cfg.historyWidgetOptions; diff --git a/modules/programs/gallery-dl.nix b/modules/programs/gallery-dl.nix index 7665d5c0..becd4bf1 100644 --- a/modules/programs/gallery-dl.nix +++ b/modules/programs/gallery-dl.nix @@ -1,25 +1,20 @@ { config, lib, pkgs, ... }: - -with lib; - let - cfg = config.programs.gallery-dl; jsonFormat = pkgs.formats.json { }; - in { meta.maintainers = [ ]; options.programs.gallery-dl = { - enable = mkEnableOption "gallery-dl"; + enable = lib.mkEnableOption "gallery-dl"; - package = mkPackageOption pkgs "gallery-dl" { nullable = true; }; + package = lib.mkPackageOption pkgs "gallery-dl" { nullable = true; }; - settings = mkOption { + settings = lib.mkOption { type = jsonFormat.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { extractor.base-directory = "~/Downloads"; } @@ -33,10 +28,10 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; - xdg.configFile."gallery-dl/config.json" = mkIf (cfg.settings != { }) { + xdg.configFile."gallery-dl/config.json" = lib.mkIf (cfg.settings != { }) { source = jsonFormat.generate "gallery-dl-settings" cfg.settings; }; }; diff --git a/modules/programs/getmail-accounts.nix b/modules/programs/getmail-accounts.nix index e2ff9405..ae538c35 100644 --- a/modules/programs/getmail-accounts.nix +++ b/modules/programs/getmail-accounts.nix @@ -1,10 +1,8 @@ -{ config, lib, ... }: - -with lib; - -{ +{ lib, ... }: +let inherit (lib) mkOption types; +in { options.getmail = { - enable = mkEnableOption "the getmail mail retriever for this account"; + enable = lib.mkEnableOption "the getmail mail retriever for this account"; destinationCommand = mkOption { type = types.nullOr types.str; diff --git a/modules/programs/getmail.nix b/modules/programs/getmail.nix index 53e39b43..aa38c415 100644 --- a/modules/programs/getmail.nix +++ b/modules/programs/getmail.nix @@ -1,17 +1,14 @@ { config, lib, pkgs, ... }: - -with lib; - let - - accounts = - filter (a: a.getmail.enable) (attrValues config.accounts.email.accounts); + accounts = lib.filter (a: a.getmail.enable) + (lib.attrValues config.accounts.email.accounts); renderAccountConfig = account: - with account; let - passCmd = concatMapStringsSep ", " (x: "'${x}'") passwordCommand; - renderedMailboxes = concatMapStrings (x: "'${x}', ") getmail.mailboxes; + inherit (account) getmail imap passwordCommand; + passCmd = lib.concatMapStringsSep ", " (x: "'${x}'") passwordCommand; + renderedMailboxes = + lib.concatMapStrings (x: "'${x}', ") getmail.mailboxes; retrieverType = if imap.tls.enable then "SimpleIMAPSSLRetriever" else @@ -21,7 +18,7 @@ let destinationPath = getmail.destinationCommand; } else { destinationType = "Maildir"; - destinationPath = "${maildir.absPath}/"; + destinationPath = "${account.maildir.absPath}/"; }; renderGetmailBoolean = v: if v then "true" else "false"; in '' @@ -29,8 +26,8 @@ let [retriever] type = ${retrieverType} server = ${imap.host} - ${optionalString (imap.port != null) "port = ${toString imap.port}"} - username = ${userName} + ${lib.optionalString (imap.port != null) "port = ${toString imap.port}"} + username = ${account.userName} password_command = (${passCmd}) mailboxes = ( ${renderedMailboxes} ) @@ -42,24 +39,26 @@ let delete = ${renderGetmailBoolean getmail.delete} read_all = ${renderGetmailBoolean getmail.readAll} ''; - getmailEnabled = length (filter (a: a.getmail.enable) accounts) > 0; + getmailEnabled = lib.length (lib.filter (a: a.getmail.enable) accounts) > 0; # Watch out! This is used by the getmail.service too! renderConfigFilepath = a: ".getmail/getmail${if a.primary then "rc" else a.name}"; in { options = { - accounts.email.accounts = mkOption { - type = with types; attrsOf (submodule (import ./getmail-accounts.nix)); + accounts.email.accounts = lib.mkOption { + type = with lib.types; + attrsOf (submodule (import ./getmail-accounts.nix)); }; }; - config = mkIf getmailEnabled { + config = lib.mkIf getmailEnabled { assertions = [ - (hm.assertions.assertPlatform "programs.getmail" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "programs.getmail" pkgs + lib.platforms.linux) ]; - home.file = foldl' (a: b: a // b) { } + home.file = lib.foldl' (a: b: a // b) { } (map (a: { "${renderConfigFilepath a}".text = renderAccountConfig a; }) accounts); }; diff --git a/modules/programs/gh.nix b/modules/programs/gh.nix index 03e8feab..7d9ab1fe 100644 --- a/modules/programs/gh.nix +++ b/modules/programs/gh.nix @@ -1,8 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) literalExpression mkIf mkOption types; cfg = config.programs.gh; @@ -10,7 +8,7 @@ let settingsType = types.submodule { freeformType = yamlFormat.type; - # These options are only here for the mkRenamedOptionModule support + # These options are only here for the `mkRenamedOptionModule` support options = { aliases = mkOption { type = with types; attrsOf str; @@ -45,31 +43,30 @@ let }; in { - meta.maintainers = [ maintainers.gerschtli maintainers.berbiche ]; + meta.maintainers = with lib.maintainers; [ gerschtli berbiche ]; imports = (map (x: - mkRenamedOptionModule [ "programs" "gh" x ] [ + lib.mkRenamedOptionModule [ "programs" "gh" x ] [ "programs" "gh" "settings" x ]) [ "aliases" "editor" ]) ++ [ - (mkRenamedOptionModule [ "programs" "gh" "gitProtocol" ] [ + (lib.mkRenamedOptionModule [ "programs" "gh" "gitProtocol" ] [ "programs" "gh" "settings" "git_protocol" ]) - (mkRenamedOptionModule [ "programs" "gh" "enableGitCredentialHelper" ] [ + (lib.mkRenamedOptionModule [ "programs" "gh" - "gitCredentialHelper" - "enable" - ]) + "enableGitCredentialHelper" + ] [ "programs" "gh" "gitCredentialHelper" "enable" ]) ]; options.programs.gh = { - enable = mkEnableOption "GitHub CLI tool"; + enable = lib.mkEnableOption "GitHub CLI tool"; package = mkOption { type = types.package; @@ -98,7 +95,7 @@ in { }; gitCredentialHelper = { - enable = mkEnableOption "the gh git credential helper" // { + enable = lib.mkEnableOption "the gh git credential helper" // { default = true; }; @@ -128,7 +125,7 @@ in { xdg.configFile."gh/config.yml".source = yamlFormat.generate "gh-config.yml" ({ version = "1"; } // cfg.settings); - # Version 2.40.0+ of gh needs to migrate account formats, this needs to + # Version 2.40.0+ of `gh` needs to migrate account formats, this needs to # happen before the version = 1 is placed in the configuration file. Running # `gh help` is sufficient to perform the migration. If the migration already # has occurred, then this is a no-op. @@ -136,14 +133,14 @@ in { # See https://github.com/nix-community/home-manager/issues/4744 for details. home.activation.migrateGhAccounts = let ghHosts = "${config.xdg.configHome}/gh/hosts.yml"; - in hm.dag.entryBetween [ "linkGeneration" ] [ "writeBoundary" ] '' + in lib.hm.dag.entryBetween [ "linkGeneration" ] [ "writeBoundary" ] '' if [[ ! -L "${ghHosts}" && -f "${ghHosts}" && $(grep --invert-match --quiet '^version:' ${ghHosts}) ]]; then ( TMP_DIR=$(mktemp -d) trap "rm --force --recursive $TMP_DIR" EXIT cp "${ghHosts}" $TMP_DIR/ export GH_CONFIG_DIR=$TMP_DIR - run --silence ${getExe cfg.package} help + run --silence ${lib.getExe cfg.package} help cp $TMP_DIR/hosts.yml "${ghHosts}" ) fi diff --git a/modules/programs/git-cliff.nix b/modules/programs/git-cliff.nix index ce9e26f3..c417e2d4 100644 --- a/modules/programs/git-cliff.nix +++ b/modules/programs/git-cliff.nix @@ -1,24 +1,19 @@ { config, lib, pkgs, ... }: - -with lib; - let - cfg = config.programs.git-cliff; tomlFormat = pkgs.formats.toml { }; - in { - meta.maintainers = [ hm.maintainers.NateCox ]; + meta.maintainers = [ lib.hm.maintainers.NateCox ]; options.programs.git-cliff = { - enable = mkEnableOption "git-cliff changelog generator"; + enable = lib.mkEnableOption "git-cliff changelog generator"; - package = mkPackageOption pkgs "git-cliff" { nullable = true; }; + package = lib.mkPackageOption pkgs "git-cliff" { nullable = true; }; - settings = mkOption { + settings = lib.mkOption { type = tomlFormat.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { header = "Changelog"; trim = true; @@ -33,11 +28,11 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; xdg.configFile = { - "git-cliff/cliff.toml" = mkIf (cfg.settings != { }) { + "git-cliff/cliff.toml" = lib.mkIf (cfg.settings != { }) { source = tomlFormat.generate "git-cliff-config" cfg.settings; }; }; diff --git a/modules/programs/git.nix b/modules/programs/git.nix index 86388ce9..b4d59446 100644 --- a/modules/programs/git.nix +++ b/modules/programs/git.nix @@ -1,8 +1,8 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) + concatStringsSep literalExpression mkDefault mkEnableOption mkIf mkOption + mkOptionDefault mkPackageOption types; cfg = config.programs.git; @@ -65,8 +65,8 @@ let }; }; config.path = mkIf (config.contents != { }) (mkDefault - (pkgs.writeText (hm.strings.storeFileName config.contentSuffix) - (generators.toGitINI config.contents))); + (pkgs.writeText (lib.hm.strings.storeFileName config.contentSuffix) + (lib.generators.toGitINI config.contents))); }); in { @@ -431,7 +431,7 @@ in { type = types.listOf types.str; default = [ ]; example = literalExpression ''[ "--no-adds-only-special" ]''; - apply = concatStringsSep " "; + apply = lib.concatStringsSep " "; description = '' Command line arguments to include in the RIFF environment variable. @@ -443,7 +443,7 @@ in { }; imports = [ - (mkRenamedOptionModule [ "programs" "git" "signing" "gpgPath" ] [ + (lib.mkRenamedOptionModule [ "programs" "git" "signing" "gpgPath" ] [ "programs" "git" "signing" @@ -451,7 +451,7 @@ in { ]) ]; - config = mkIf cfg.enable (mkMerge [ + config = mkIf cfg.enable (lib.mkMerge [ { home.packages = [ cfg.package ]; @@ -464,7 +464,7 @@ in { cfg.diff-highlight.enable cfg.riff.enable ]; - in count id enabled <= 1; + in lib.count lib.id enabled <= 1; message = "Only one of 'programs.git.delta.enable' or 'programs.git.difftastic.enable' or 'programs.git.diff-so-fancy.enable' or 'programs.git.diff-highlight' can be set to true at the same time."; }]; @@ -475,7 +475,7 @@ in { }; xdg.configFile = { - "git/config".text = generators.toGitINI cfg.iniContent; + "git/config".text = lib.generators.toGitINI cfg.iniContent; "git/ignore" = mkIf (cfg.ignores != [ ]) { text = concatStringsSep "\n" cfg.ignores + "\n"; @@ -492,8 +492,9 @@ in { hasSmtp = name: account: account.smtp != null; genIdentity = name: account: - with account; - nameValuePair "sendemail.${name}" (if account.msmtp.enable then { + let inherit (account) address realName smtp userName; + in lib.nameValuePair "sendemail.${name}" + (if account.msmtp.enable then { sendmailCmd = "${pkgs.msmtp}/bin/msmtp"; envelopeSender = "auto"; from = "${realName} <${address}>"; @@ -501,7 +502,7 @@ in { { smtpEncryption = if smtp.tls.enable then (if smtp.tls.useStartTls - || versionOlder config.home.stateVersion "20.09" then + || lib.versionOlder config.home.stateVersion "20.09" then "tls" else "ssl") @@ -512,31 +513,31 @@ in { smtpServer = smtp.host; smtpUser = userName; from = "${realName} <${address}>"; - } // optionalAttrs (smtp.port != null) { + } // lib.optionalAttrs (smtp.port != null) { smtpServerPort = smtp.port; }); - in mapAttrs' genIdentity - (filterAttrs hasSmtp config.accounts.email.accounts); + in lib.mapAttrs' genIdentity + (lib.filterAttrs hasSmtp config.accounts.email.accounts); } (mkIf (cfg.signing != { }) { programs.git = { signing = { - format = if (versionOlder config.home.stateVersion "25.05") then + format = if (lib.versionOlder config.home.stateVersion "25.05") then (mkOptionDefault "openpgp") else (mkOptionDefault null); signer = let defaultSigners = { - openpgp = getExe config.programs.gpg.package; - ssh = getExe' pkgs.openssh "ssh-keygen"; - x509 = getExe' config.programs.gpg.package "gpgsm"; + openpgp = lib.getExe config.programs.gpg.package; + ssh = lib.getExe' pkgs.openssh "ssh-keygen"; + x509 = lib.getExe' config.programs.gpg.package "gpgsm"; }; in mkIf (cfg.signing.format != null) (mkOptionDefault defaultSigners.${cfg.signing.format}); }; - iniContent = mkMerge [ + iniContent = lib.mkMerge [ (mkIf (cfg.signing.key != null) { user.signingKey = mkDefault cfg.signing.key; }) @@ -558,7 +559,7 @@ in { programs.git.iniContent = { core.hooksPath = let entries = - mapAttrsToList (name: path: { inherit name path; }) cfg.hooks; + lib.mapAttrsToList (name: path: { inherit name path; }) cfg.hooks; in toString (pkgs.linkFarm "git-hooks" entries); }; }) @@ -588,15 +589,15 @@ in { } else { include.path = "${path}"; }; - in mkAfter (concatStringsSep "\n" - (map generators.toGitINI (map include cfg.includes))); + in lib.mkAfter (concatStringsSep "\n" + (map lib.generators.toGitINI (map include cfg.includes))); }) (mkIf cfg.lfs.enable { home.packages = [ pkgs.git-lfs ]; programs.git.iniContent.filter.lfs = - let skipArg = optional cfg.lfs.skipSmudge "--skip"; + let skipArg = lib.optional cfg.lfs.skipSmudge "--skip"; in { clean = "git-lfs clean -- %f"; process = @@ -654,8 +655,8 @@ in { dhCommand = "${cfg.package}/share/git/contrib/diff-highlight/diff-highlight"; in { - core.pager = "${dhCommand} | ${getExe pkgs.less} ${ - escapeShellArgs cfg.diff-highlight.pagerOpts + core.pager = "${dhCommand} | ${lib.getExe pkgs.less} ${ + lib.escapeShellArgs cfg.diff-highlight.pagerOpts }"; interactive.diffFilter = dhCommand; }; @@ -663,7 +664,7 @@ in { (let difftCommand = concatStringsSep " " [ - "${getExe cfg.difftastic.package}" + "${lib.getExe cfg.difftastic.package}" "--color ${cfg.difftastic.color}" "--background ${cfg.difftastic.background}" "--display ${cfg.difftastic.display}" @@ -704,7 +705,7 @@ in { let dsfCommand = "${pkgs.diff-so-fancy}/bin/diff-so-fancy"; in { core.pager = "${dsfCommand} | ${pkgs.less}/bin/less ${ - escapeShellArgs cfg.diff-so-fancy.pagerOpts + lib.escapeShellArgs cfg.diff-so-fancy.pagerOpts }"; interactive.diffFilter = "${dsfCommand} --patch"; diff-so-fancy = { @@ -718,7 +719,7 @@ in { }; }) - (let riffExe = baseNameOf (getExe cfg.riff.package); + (let riffExe = baseNameOf (lib.getExe cfg.riff.package); in mkIf cfg.riff.enable { home.packages = [ cfg.riff.package ]; diff --git a/modules/programs/gitui.nix b/modules/programs/gitui.nix index 029986b9..345cf5a1 100644 --- a/modules/programs/gitui.nix +++ b/modules/programs/gitui.nix @@ -1,17 +1,15 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; cfg = config.programs.gitui; in { - meta.maintainers = [ hm.maintainers.mifom ]; + meta.maintainers = [ lib.hm.maintainers.mifom ]; options.programs.gitui = { - enable = - mkEnableOption "gitui, blazing fast terminal-ui for git written in rust"; + enable = lib.mkEnableOption + "gitui, blazing fast terminal-ui for git written in rust"; package = mkOption { type = types.package; @@ -68,7 +66,7 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; xdg.configFile."gitui/theme.ron".source = diff --git a/modules/programs/gnome-shell.nix b/modules/programs/gnome-shell.nix index a91609bf..934ab64e 100644 --- a/modules/programs/gnome-shell.nix +++ b/modules/programs/gnome-shell.nix @@ -1,7 +1,7 @@ { config, lib, pkgs, ... }: - -with lib; let + inherit (lib) mkOption types; + cfg = config.programs.gnome-shell; extensionOpts = { config, ... }: { @@ -25,8 +25,8 @@ let }; }; - config = mkIf (hasAttr "extensionUuid" config.package) { - id = mkDefault config.package.extensionUuid; + config = lib.mkIf (lib.hasAttr "extensionUuid" config.package) { + id = lib.mkDefault config.package.extensionUuid; }; }; @@ -43,7 +43,7 @@ let package = mkOption { type = types.nullOr types.package; default = null; - example = literalExpression "pkgs.plata-theme"; + example = lib.literalExpression "pkgs.plata-theme"; description = '' Package providing a GNOME Shell theme in `$out/share/themes/''${name}/gnome-shell`. @@ -53,15 +53,15 @@ let }; in { - meta.maintainers = [ maintainers.terlar ]; + meta.maintainers = [ lib.maintainers.terlar ]; options.programs.gnome-shell = { - enable = mkEnableOption "GNOME Shell customization"; + enable = lib.mkEnableOption "GNOME Shell customization"; extensions = mkOption { type = types.listOf (types.submodule extensionOpts); default = [ ]; - example = literalExpression '' + example = lib.literalExpression '' [ { package = pkgs.gnomeExtensions.dash-to-panel; } { @@ -78,7 +78,7 @@ in { theme = mkOption { type = types.nullOr (types.submodule themeOpts); default = null; - example = literalExpression '' + example = lib.literalExpression '' { name = "Plata-Noir"; package = pkgs.plata-theme; @@ -90,17 +90,17 @@ in { }; }; - config = mkIf cfg.enable (mkMerge [ - (mkIf (cfg.extensions != [ ]) { + config = lib.mkIf cfg.enable (lib.mkMerge [ + (lib.mkIf (cfg.extensions != [ ]) { dconf.settings."org/gnome/shell" = { disable-user-extensions = false; - enabled-extensions = catAttrs "id" cfg.extensions; + enabled-extensions = lib.catAttrs "id" cfg.extensions; }; - home.packages = catAttrs "package" cfg.extensions; + home.packages = lib.catAttrs "package" cfg.extensions; }) - (mkIf (cfg.theme != null) { + (lib.mkIf (cfg.theme != null) { dconf.settings."org/gnome/shell/extensions/user-theme".name = cfg.theme.name; diff --git a/modules/programs/gnome-terminal.nix b/modules/programs/gnome-terminal.nix index dafadb7e..297c8942 100644 --- a/modules/programs/gnome-terminal.nix +++ b/modules/programs/gnome-terminal.nix @@ -1,8 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; cfg = config.programs.gnome-terminal; @@ -243,14 +241,14 @@ let foreground-color = pcfg.colors.foregroundColor; background-color = pcfg.colors.backgroundColor; palette = pcfg.colors.palette; - } // optionalAttrs (pcfg.allowBold != null) { + } // lib.optionalAttrs (pcfg.allowBold != null) { allow-bold = pcfg.allowBold; } // (if (pcfg.colors.boldColor == null) then { bold-color-same-as-fg = true; } else { bold-color-same-as-fg = false; bold-color = pcfg.colors.boldColor; - }) // optionalAttrs (pcfg.boldIsBright != null) { + }) // lib.optionalAttrs (pcfg.boldIsBright != null) { bold-is-bright = pcfg.boldIsBright; } // (if (pcfg.colors.cursor != null) then { cursor-colors-set = true; @@ -264,18 +262,18 @@ let highlight-background-color = pcfg.colors.highlight.background; } else { highlight-colors-set = false; - }) // optionalAttrs (pcfg.transparencyPercent != null) { + }) // lib.optionalAttrs (pcfg.transparencyPercent != null) { background-transparency-percent = pcfg.transparencyPercent; use-theme-transparency = false; use-transparent-background = true; })); in { - meta.maintainers = with maintainers; [ kamadorueda rycee ]; + meta.maintainers = with lib.maintainers; [ kamadorueda rycee ]; options = { programs.gnome-terminal = { - enable = mkEnableOption "Gnome Terminal"; + enable = lib.mkEnableOption "Gnome Terminal"; showMenubar = mkOption { default = true; @@ -301,18 +299,18 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (let uuidre = "[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}"; - erroneous = - filter (n: builtins.match uuidre n == null) (attrNames cfg.profile); + erroneous = lib.filter (n: builtins.match uuidre n == null) + (lib.attrNames cfg.profile); in { assertion = erroneous == [ ]; message = '' The attribute name of a Gnome Terminal profile must be a UUID. - Incorrect profile names: ${concatStringsSep ", " erroneous}''; + Incorrect profile names: ${lib.concatStringsSep ", " erroneous}''; }) ]; @@ -327,11 +325,12 @@ in { }; "${dconfPath}/profiles:" = { - default = head (attrNames (filterAttrs (n: v: v.default) cfg.profile)); - list = attrNames cfg.profile; + default = lib.head + (lib.attrNames (lib.filterAttrs (n: v: v.default) cfg.profile)); + list = lib.attrNames cfg.profile; }; - } // mapAttrs' - (n: v: nameValuePair ("${dconfPath}/profiles:/:${n}") (buildProfileSet v)) + } // lib.mapAttrs' + (n: v: lib.nameValuePair "${dconfPath}/profiles:/:${n}" (buildProfileSet v)) cfg.profile; programs.bash.enableVteIntegration = true; diff --git a/modules/programs/go.nix b/modules/programs/go.nix index 19b63eae..0e778296 100644 --- a/modules/programs/go.nix +++ b/modules/programs/go.nix @@ -1,19 +1,17 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) literalExpression mkIf mkOption types; cfg = config.programs.go; modeFileContent = "${cfg.telemetry.mode} ${cfg.telemetry.date}"; in { - meta.maintainers = [ maintainers.rvolosatovs ]; + meta.maintainers = [ lib.maintainers.rvolosatovs ]; options = { programs.go = { - enable = mkEnableOption "Go"; + enable = lib.mkEnableOption "Go"; package = mkOption { type = types.package; @@ -101,19 +99,19 @@ in { }; }; - config = mkIf cfg.enable (mkMerge [ + config = mkIf cfg.enable (lib.mkMerge [ { home.packages = [ cfg.package ]; home.file = let goPath = if cfg.goPath != null then cfg.goPath else "go"; mkSrc = n: v: { "${goPath}/src/${n}".source = v; }; - in foldl' (a: b: a // b) { } (mapAttrsToList mkSrc cfg.packages); + in lib.foldl' (a: b: a // b) { } (lib.mapAttrsToList mkSrc cfg.packages); } (mkIf (cfg.goPath != null) { - home.sessionVariables.GOPATH = concatStringsSep ":" (map builtins.toPath - (map (path: "${config.home.homeDirectory}/${path}") + home.sessionVariables.GOPATH = lib.concatStringsSep ":" + (map builtins.toPath (map (path: "${config.home.homeDirectory}/${path}") ([ cfg.goPath ] ++ cfg.extraGoPaths))); }) @@ -123,7 +121,7 @@ in { }) (mkIf (cfg.goPrivate != [ ]) { - home.sessionVariables.GOPRIVATE = concatStringsSep "," cfg.goPrivate; + home.sessionVariables.GOPRIVATE = lib.concatStringsSep "," cfg.goPrivate; }) (mkIf (cfg.telemetry.mode != null) { diff --git a/modules/programs/gpg.nix b/modules/programs/gpg.nix index 14538921..58b0fd61 100644 --- a/modules/programs/gpg.nix +++ b/modules/programs/gpg.nix @@ -1,19 +1,21 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) literalExpression mkDefault mkIf mkOption optional types; + cfg = config.programs.gpg; mkKeyValue = key: value: - if isString value then "${key} ${value}" else optionalString value key; + if lib.isString value then + "${key} ${value}" + else + lib.optionalString value key; - cfgText = generators.toKeyValue { + cfgText = lib.generators.toKeyValue { inherit mkKeyValue; listsAsDuplicateKeys = true; } cfg.settings; - scdaemonCfgText = generators.toKeyValue { + scdaemonCfgText = lib.generators.toKeyValue { inherit mkKeyValue; listsAsDuplicateKeys = true; } cfg.scdaemonSettings; @@ -52,7 +54,7 @@ let ]); default = null; apply = v: - if isString v then + if lib.isString v then { unknown = 1; never = 2; @@ -118,11 +120,11 @@ let importKey = { source, trust, ... }: '' ${gpg} --import ${source} - ${optionalString (trust != null) + ${lib.optionalString (trust != null) ''importTrust "${source}" ${toString trust}''} ''; - importKeys = concatMapStringsSep "\n" importKey cfg.publicKeys; + importKeys = lib.concatMapStringsSep "\n" importKey cfg.publicKeys; in pkgs.runCommand "gpg-pubring" { buildInputs = [ cfg.package ]; } '' export GNUPGHOME GNUPGHOME=$(mktemp -d) @@ -139,7 +141,7 @@ let in { options.programs.gpg = { - enable = mkEnableOption "GnuPG"; + enable = lib.mkEnableOption "GnuPG"; package = mkOption { type = types.package; @@ -281,8 +283,8 @@ in { home.activation = { createGpgHomedir = - hm.dag.entryBetween [ "linkGeneration" ] [ "writeBoundary" ] '' - run mkdir -m700 -p $VERBOSE_ARG ${escapeShellArg cfg.homedir} + lib.hm.dag.entryBetween [ "linkGeneration" ] [ "writeBoundary" ] '' + run mkdir -m700 -p $VERBOSE_ARG ${lib.escapeShellArg cfg.homedir} ''; importGpgKeys = let @@ -296,14 +298,15 @@ in { ++ optional (trust != null && cfg.mutableTrust) ''run importTrust "${source}" ${toString trust}''; - anyTrust = any (k: k.trust != null) cfg.publicKeys; + anyTrust = lib.any (k: k.trust != null) cfg.publicKeys; - importKeys = concatStringsSep "\n" (concatMap importKey cfg.publicKeys); + importKeys = + lib.concatStringsSep "\n" (lib.concatMap importKey cfg.publicKeys); # If any key/trust should be imported then create the block. Otherwise # leave it empty. - block = concatStringsSep "\n" (optional (importKeys != "") '' - export GNUPGHOME=${escapeShellArg cfg.homedir} + block = lib.concatStringsSep "\n" (optional (importKeys != "") '' + export GNUPGHOME=${lib.escapeShellArg cfg.homedir} if [[ ! -v VERBOSE ]]; then QUIET_ARG="--quiet" else diff --git a/modules/programs/gradle.nix b/modules/programs/gradle.nix index f8bba3e4..a7a153da 100644 --- a/modules/programs/gradle.nix +++ b/modules/programs/gradle.nix @@ -1,8 +1,7 @@ { config, pkgs, lib, ... }: - -with lib; - let + inherit (lib) mkIf mkOption types; + cfg = config.programs.gradle; defaultHomeDirectory = ".gradle"; settingsFormat = pkgs.formats.javaProperties { }; @@ -28,16 +27,17 @@ let }; }; - config.source = mkIf (config.text != null) (mkDefault (pkgs.writeTextFile { - inherit (config) text; - name = hm.strings.storeFileName name; - })); + config.source = mkIf (config.text != null) (lib.mkDefault + (pkgs.writeTextFile { + inherit (config) text; + name = lib.hm.strings.storeFileName name; + })); }); in { - meta.maintainers = [ hm.maintainers.britter ]; + meta.maintainers = [ lib.hm.maintainers.britter ]; options.programs.gradle = { - enable = mkEnableOption "Gradle Build Tool"; + enable = lib.mkEnableOption "Gradle Build Tool"; home = mkOption { type = types.str; @@ -50,7 +50,7 @@ in { ''; }; - package = mkPackageOption pkgs "gradle" { + package = lib.mkPackageOption pkgs "gradle" { nullable = true; example = "pkgs.gradle_7"; }; @@ -58,7 +58,7 @@ in { settings = mkOption { type = types.submodule { freeformType = settingsFormat.type; }; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { "org.gradle.caching" = true; "org.gradle.parallel" = true; @@ -75,7 +75,7 @@ in { initScripts = mkOption { type = with types; attrsOf initScript; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { "maven-local.gradle".text = ''' allProject { @@ -100,13 +100,12 @@ in { in mkIf cfg.enable { home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; - home.file = mkMerge ([{ + home.file = lib.mkMerge ([{ "${cfg.home}/gradle.properties" = mkIf (cfg.settings != { }) { source = settingsFormat.generate "gradle.properties" cfg.settings; }; - }] - ++ mapAttrsToList (k: v: { "${cfg.home}/init.d/${k}".source = v.source; }) - cfg.initScripts); + }] ++ lib.mapAttrsToList + (k: v: { "${cfg.home}/init.d/${k}".source = v.source; }) cfg.initScripts); home.sessionVariables = mkIf (cfg.home != defaultHomeDirectory) { GRADLE_USER_HOME = gradleHome; diff --git a/modules/programs/granted.nix b/modules/programs/granted.nix index 6a4cf928..9295b528 100644 --- a/modules/programs/granted.nix +++ b/modules/programs/granted.nix @@ -1,16 +1,10 @@ { config, lib, pkgs, ... }: - -with lib; - -let - - cfg = config.programs.granted; - +let cfg = config.programs.granted; in { - meta.maintainers = [ hm.maintainers.wcarlsen ]; + meta.maintainers = [ lib.hm.maintainers.wcarlsen ]; options.programs.granted = { - enable = mkEnableOption "granted"; + enable = lib.mkEnableOption "granted"; package = lib.mkPackageOption pkgs "granted" { }; @@ -21,10 +15,10 @@ in { lib.hm.shell.mkFishIntegrationOption { inherit config; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; - programs.zsh.initContent = mkIf cfg.enableZshIntegration '' + programs.zsh.initContent = lib.mkIf cfg.enableZshIntegration '' function assume() { export GRANTED_ALIAS_CONFIGURED="true" source ${cfg.package}/bin/assume "$@" @@ -32,7 +26,7 @@ in { } ''; - programs.fish.functions.assume = mkIf cfg.enableFishIntegration '' + programs.fish.functions.assume = lib.mkIf cfg.enableFishIntegration '' set -x GRANTED_ALIAS_CONFIGURED "true" source ${cfg.package}/share/assume.fish $argv set -e GRANTED_ALIAS_CONFIGURED diff --git a/modules/programs/havoc.nix b/modules/programs/havoc.nix index 5d48fbac..9f903a91 100644 --- a/modules/programs/havoc.nix +++ b/modules/programs/havoc.nix @@ -1,21 +1,16 @@ { config, lib, pkgs, ... }: - -with lib; - let - cfg = config.programs.havoc; iniFormat = pkgs.formats.ini { }; - in { meta.maintainers = with lib.maintainers; [ AndersonTorres ]; options.programs.havoc = { - enable = mkEnableOption "Havoc terminal"; + enable = lib.mkEnableOption "Havoc terminal"; - package = mkPackageOption pkgs "havoc" { nullable = true; }; + package = lib.mkPackageOption pkgs "havoc" { nullable = true; }; - settings = mkOption { + settings = lib.mkOption { type = iniFormat.type; default = { }; description = '' @@ -23,7 +18,7 @@ in { {file}`$XDG_CONFIG_HOME/havoc.cfg`. See for a list of available options. ''; - example = literalExpression '' + example = lib.literalExpression '' { child.program = "bash"; window.opacity = 240; @@ -50,13 +45,15 @@ in { }; }; - config = mkIf cfg.enable { - assertions = - [ (hm.assertions.assertPlatform "programs.havoc" pkgs platforms.linux) ]; + config = lib.mkIf cfg.enable { + assertions = [ + (lib.hm.assertions.assertPlatform "programs.havoc" pkgs + lib.platforms.linux) + ]; home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; - xdg.configFile."havoc.cfg" = mkIf (cfg.settings != { }) { + xdg.configFile."havoc.cfg" = lib.mkIf (cfg.settings != { }) { source = iniFormat.generate "havoc.cfg" cfg.settings; }; }; diff --git a/modules/programs/helix.nix b/modules/programs/helix.nix index 3119a06d..848ddfac 100644 --- a/modules/programs/helix.nix +++ b/modules/programs/helix.nix @@ -1,13 +1,14 @@ { config, lib, pkgs, ... }: -with lib; let + inherit (lib) literalExpression mkIf mkOption types; + cfg = config.programs.helix; tomlFormat = pkgs.formats.toml { }; in { - meta.maintainers = [ hm.maintainers.Philipp-M ]; + meta.maintainers = [ lib.hm.maintainers.Philipp-M ]; options.programs.helix = { - enable = mkEnableOption "helix text editor"; + enable = lib.mkEnableOption "helix text editor"; package = mkOption { type = types.package; @@ -224,12 +225,12 @@ in { source = tomlFormat.generate "helix-languages-config" cfg.languages; }; "helix/ignore" = mkIf (cfg.ignores != [ ]) { - text = concatStringsSep "\n" cfg.ignores + "\n"; + text = lib.concatStringsSep "\n" cfg.ignores + "\n"; }; }; - themes = mapAttrs' (n: v: - nameValuePair "helix/themes/${n}.toml" { + themes = lib.mapAttrs' (n: v: + lib.nameValuePair "helix/themes/${n}.toml" { source = tomlFormat.generate "helix-theme-${n}" v; }) cfg.themes; in settings // themes; diff --git a/modules/programs/hexchat.nix b/modules/programs/hexchat.nix index 01ece4bd..38ee1a69 100644 --- a/modules/programs/hexchat.nix +++ b/modules/programs/hexchat.nix @@ -1,50 +1,48 @@ { config, pkgs, lib, ... }: - -with lib; - let + inherit (lib) literalExpression mkIf mkOption types; + cfg = config.programs.hexchat; - channelOptions = with types; - submodule { - options = { - autoconnect = mkOption { - type = nullOr bool; - default = false; - description = "Autoconnect to network."; - }; + channelOptions = types.submodule { + options = { + autoconnect = mkOption { + type = with types; nullOr bool; + default = false; + description = "Autoconnect to network."; + }; - connectToSelectedServerOnly = mkOption { - type = nullOr bool; - default = true; - description = "Connect to selected server only."; - }; + connectToSelectedServerOnly = mkOption { + type = with types; nullOr bool; + default = true; + description = "Connect to selected server only."; + }; - bypassProxy = mkOption { - type = nullOr bool; - default = true; - description = "Bypass proxy."; - }; + bypassProxy = mkOption { + type = with types; nullOr bool; + default = true; + description = "Bypass proxy."; + }; - forceSSL = mkOption { - type = nullOr bool; - default = false; - description = "Use SSL for all servers."; - }; + forceSSL = mkOption { + type = with types; nullOr bool; + default = false; + description = "Use SSL for all servers."; + }; - acceptInvalidSSLCertificates = mkOption { - type = nullOr bool; - default = false; - description = "Accept invalid SSL certificates."; - }; + acceptInvalidSSLCertificates = mkOption { + type = with types; nullOr bool; + default = false; + description = "Accept invalid SSL certificates."; + }; - useGlobalUserInformation = mkOption { - type = nullOr bool; - default = false; - description = "Use global user information."; - }; + useGlobalUserInformation = mkOption { + type = with types; nullOr bool; + default = false; + description = "Use global user information."; }; }; + }; modChannelOption = with types; submodule { @@ -71,7 +69,7 @@ let }; loginMethod = mkOption { - type = nullOr (enum (attrNames loginMethodMap)); + type = nullOr (enum (lib.attrNames loginMethodMap)); default = null; description = '' The login method. The allowed options are: @@ -166,13 +164,16 @@ let transformField = k: v: if (v != null) then "${k}=${v}" else null; listChar = c: l: - if l != [ ] then concatMapStringsSep "\n" (transformField c) l else null; + if l != [ ] then + lib.concatMapStringsSep "\n" (transformField c) l + else + null; computeFieldsValue = channel: let ifTrue = p: n: if p then n else 0; result = with channel.options; - foldl' (a: b: a + b) 0 [ + lib.foldl' (a: b: a + b) 0 [ (ifTrue (!connectToSelectedServerOnly) 1) (ifTrue useGlobalUserInformation 2) (ifTrue forceSSL 4) @@ -193,14 +194,14 @@ let }; loginMethod = channel: - transformField "L" (optionalString (channel.loginMethod != null) + transformField "L" (lib.optionalString (channel.loginMethod != null) (toString loginMethodMap.${channel.loginMethod})); # Note: Missing option `D=`. transformChannel = channelName: let channel = cfg.channels.${channelName}; - in concatStringsSep "\n" (remove null [ - "" # leave a space between one server and another + in lib.concatStringsSep "\n" (lib.remove null [ + "" # Leave a space between one server and another (transformField "N" channelName) (loginMethod channel) (transformField "E" channel.charset) @@ -216,13 +217,13 @@ let ]); in { - meta.maintainers = with maintainers; [ thiagokokada ]; + meta.maintainers = with lib.maintainers; [ thiagokokada ]; - options.programs.hexchat = with types; { - enable = mkEnableOption "HexChat, a graphical IRC client"; + options.programs.hexchat = { + enable = lib.mkEnableOption "HexChat, a graphical IRC client"; channels = mkOption { - type = attrsOf modChannelOption; + type = types.attrsOf modChannelOption; default = { }; example = literalExpression '' { @@ -261,7 +262,7 @@ in { settings = mkOption { default = null; - type = nullOr (attrsOf str); + type = types.nullOr (types.attrsOf types.str); example = literalExpression '' { irc_nick1 = "mynick"; @@ -278,7 +279,7 @@ in { }; overwriteConfigFiles = mkOption { - type = nullOr bool; + type = types.nullOr types.bool; default = false; description = '' Enables overwriting HexChat configuration files @@ -298,7 +299,7 @@ in { }; theme = mkOption { - type = nullOr package; + type = types.nullOr types.package; default = null; example = literalExpression '' source = pkgs.fetchzip { @@ -317,7 +318,8 @@ in { config = mkIf cfg.enable { assertions = [ - (hm.assertions.assertPlatform "programs.hexchat" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "programs.hexchat" pkgs + lib.platforms.linux) ]; home.packages = [ pkgs.hexchat ]; @@ -329,15 +331,15 @@ in { xdg.configFile."hexchat/hexchat.conf" = mkIf (cfg.settings != null) { force = cfg.overwriteConfigFiles; - text = concatMapStringsSep "\n" (x: x + " = " + cfg.settings.${x}) - (attrNames cfg.settings); + text = lib.concatMapStringsSep "\n" (x: x + " = " + cfg.settings.${x}) + (lib.attrNames cfg.settings); }; xdg.configFile."hexchat/servlist.conf" = mkIf (cfg.channels != { }) { force = cfg.overwriteConfigFiles; # Final line breaks is required to avoid cropping last field value. - text = concatMapStringsSep "\n" transformChannel (attrNames cfg.channels) - + "\n\n"; + text = lib.concatMapStringsSep "\n" transformChannel + (lib.attrNames cfg.channels) + "\n\n"; }; }; } diff --git a/modules/programs/himalaya.nix b/modules/programs/himalaya.nix index 5cba5a2f..08bdb3f1 100644 --- a/modules/programs/himalaya.nix +++ b/modules/programs/himalaya.nix @@ -1,16 +1,15 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkOption optionalAttrs types; + # aliases inherit (config.programs) himalaya; tomlFormat = pkgs.formats.toml { }; # attrs util that removes entries containing a null value - compactAttrs = filterAttrs (_: val: !isNull val); + compactAttrs = lib.filterAttrs (_: val: !isNull val); - # needed for notmuch config, because the DB is here, and not in each + # Needed for notmuch config, because the DB is here, and not in each # account's dir maildirBasePath = config.accounts.email.maildirBasePath; @@ -89,10 +88,10 @@ let sendmailConfig = optionalAttrs (isNull account.smtp && !isNull account.msmtp) { message.send.backend.type = "sendmail"; - message.send.backend.cmd = getExe pkgs.msmtp; + message.send.backend.cmd = lib.getExe pkgs.msmtp; }; - config = attrsets.mergeAttrsList [ + config = lib.attrsets.mergeAttrsList [ globalConfig signatureConfig imapConfig @@ -102,13 +101,13 @@ let sendmailConfig ]; - in recursiveUpdate config account.himalaya.settings; + in lib.recursiveUpdate config account.himalaya.settings; in { - meta.maintainers = with hm.maintainers; [ soywod toastal ]; + meta.maintainers = with lib.hm.maintainers; [ soywod toastal ]; imports = [ - (mkRemovedOptionModule [ "services" "himalaya-watch" "enable" ] '' + (lib.mkRemovedOptionModule [ "services" "himalaya-watch" "enable" ] '' services.himalaya-watch has been removed. The watch feature moved away from Himalaya scope, and resides @@ -121,8 +120,8 @@ in { options = { programs.himalaya = { - enable = mkEnableOption "the email client Himalaya CLI"; - package = mkPackageOption pkgs "himalaya" { nullable = true; }; + enable = lib.mkEnableOption "the email client Himalaya CLI"; + package = lib.mkPackageOption pkgs "himalaya" { nullable = true; }; settings = mkOption { type = types.submodule { freeformType = tomlFormat.type; }; default = { }; @@ -136,7 +135,7 @@ in { accounts.email.accounts = mkOption { type = types.attrsOf (types.submodule { options.himalaya = { - enable = mkEnableOption + enable = lib.mkEnableOption "the email client Himalaya CLI for this email account"; settings = mkOption { @@ -152,20 +151,20 @@ in { }; }; - config = mkIf himalaya.enable { + config = lib.mkIf himalaya.enable { home.packages = lib.mkIf (himalaya.package != null) [ himalaya.package ]; xdg = { configFile."himalaya/config.toml".source = let - enabledAccounts = filterAttrs (_: account: account.himalaya.enable) + enabledAccounts = lib.filterAttrs (_: account: account.himalaya.enable) config.accounts.email.accounts; - accountsConfig = mapAttrs mkAccountConfig enabledAccounts; + accountsConfig = lib.mapAttrs mkAccountConfig enabledAccounts; globalConfig = compactAttrs himalaya.settings; allConfig = globalConfig // { accounts = accountsConfig; }; in tomlFormat.generate "himalaya.config.toml" allConfig; - desktopEntries.himalaya = - mkIf (pkgs.stdenv.hostPlatform.isLinux && (himalaya.package != null)) { + desktopEntries.himalaya = lib.mkIf + (pkgs.stdenv.hostPlatform.isLinux && (himalaya.package != null)) { type = "Application"; name = "himalaya"; genericName = "Email Client"; diff --git a/modules/programs/home-manager.nix b/modules/programs/home-manager.nix index 8ea37017..2962f44d 100644 --- a/modules/programs/home-manager.nix +++ b/modules/programs/home-manager.nix @@ -1,20 +1,14 @@ { config, lib, pkgs, ... }: - -with lib; - -let - - cfg = config.programs.home-manager; - +let cfg = config.programs.home-manager; in { - meta.maintainers = [ maintainers.rycee ]; + meta.maintainers = [ lib.maintainers.rycee ]; options = { programs.home-manager = { - enable = mkEnableOption "Home Manager"; + enable = lib.mkEnableOption "Home Manager"; - path = mkOption { - type = types.nullOr types.str; + path = lib.mkOption { + type = lib.types.nullOr lib.types.str; default = null; example = "$HOME/devel/home-manager"; description = '' @@ -27,7 +21,7 @@ in { }; }; - config = mkIf (cfg.enable && !config.submoduleSupport.enable) { + config = lib.mkIf (cfg.enable && !config.submoduleSupport.enable) { home.packages = [ (pkgs.callPackage ../../home-manager { inherit (cfg) path; }) ]; }; diff --git a/modules/programs/hstr.nix b/modules/programs/hstr.nix index 1af2fa0e..26a929c4 100644 --- a/modules/programs/hstr.nix +++ b/modules/programs/hstr.nix @@ -1,20 +1,14 @@ { config, lib, pkgs, ... }: - -with lib; - -let - - cfg = config.programs.hstr; - +let cfg = config.programs.hstr; in { - meta.maintainers = [ hm.maintainers.Dines97 ]; + meta.maintainers = [ lib.hm.maintainers.Dines97 ]; options.programs.hstr = { - enable = mkEnableOption '' + enable = lib.mkEnableOption '' Bash And Zsh shell history suggest box - easily view, navigate, search and manage your command history''; - package = mkPackageOption pkgs "hstr" { }; + package = lib.mkPackageOption pkgs "hstr" { }; enableBashIntegration = lib.hm.shell.mkBashIntegrationOption { inherit config; }; @@ -23,14 +17,14 @@ in { lib.hm.shell.mkZshIntegrationOption { inherit config; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; - programs.bash.initExtra = mkIf cfg.enableBashIntegration '' + programs.bash.initExtra = lib.mkIf cfg.enableBashIntegration '' eval "$(${cfg.package}/bin/hstr --show-configuration)" ''; - programs.zsh.initContent = mkIf cfg.enableZshIntegration '' + programs.zsh.initContent = lib.mkIf cfg.enableZshIntegration '' eval "$(${cfg.package}/bin/hstr --show-zsh-configuration)" ''; }; diff --git a/modules/programs/htop.nix b/modules/programs/htop.nix index 28699e4a..cf263ebc 100644 --- a/modules/programs/htop.nix +++ b/modules/programs/htop.nix @@ -1,19 +1,16 @@ { config, lib, pkgs, ... }: - -with lib; - let inherit (pkgs.stdenv.hostPlatform) isDarwin; cfg = config.programs.htop; formatOption = n: v: - let v' = if isBool v then (if v then "1" else "0") else toString v; + let v' = if lib.isBool v then (if v then "1" else "0") else toString v; in "${n}=${v'}"; formatMeters = side: meters: { - "${side}_meters" = concatMap (mapAttrsToList (x: _: x)) meters; - "${side}_meter_modes" = concatMap (mapAttrsToList (_: y: y)) meters; + "${side}_meters" = lib.concatMap (lib.mapAttrsToList (x: _: x)) meters; + "${side}_meter_modes" = lib.concatMap (lib.mapAttrsToList (_: y: y)) meters; }; leftMeters = formatMeters "left"; rightMeters = formatMeters "right"; @@ -107,16 +104,16 @@ let blank = text "Blank"; in { - meta.maintainers = [ hm.maintainers.bjpbakker ]; + meta.maintainers = [ lib.hm.maintainers.bjpbakker ]; options.programs.htop = { - enable = mkEnableOption "htop"; + enable = lib.mkEnableOption "htop"; - settings = mkOption { - type = with types; + settings = lib.mkOption { + type = with lib.types; attrsOf (oneOf [ bool int str (listOf (oneOf [ int str ])) ]); default = { }; - example = literalExpression '' + example = lib.literalExpression '' { color_scheme = 6; cpu_count_from_one = 0; @@ -156,15 +153,15 @@ in { ''; }; - package = mkOption { - type = types.package; + package = lib.mkOption { + type = lib.types.package; default = pkgs.htop; - defaultText = literalExpression "pkgs.htop"; + defaultText = lib.literalExpression "pkgs.htop"; description = "Package containing the {command}`htop` program."; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { lib.htop = { inherit fields defaultFields modes leftMeters rightMeters bar text graph led blank; @@ -175,23 +172,22 @@ in { xdg.configFile."htop" = let defaults = { fields = if isDarwin then - remove fields.M_SHARE defaultFields + lib.remove fields.M_SHARE defaultFields else defaultFields; }; - before = optionalAttrs (cfg.settings ? header_layout) { + before = lib.optionalAttrs (cfg.settings ? header_layout) { inherit (cfg.settings) header_layout; }; - settings = defaults // (removeAttrs cfg.settings (attrNames before)); + settings = defaults // (removeAttrs cfg.settings (lib.attrNames before)); - formatOptions = mapAttrsToList formatOption; + formatOptions = lib.mapAttrsToList formatOption; - in mkIf (cfg.settings != { }) { - source = pkgs.writeTextDir "htoprc" - (concatStringsSep "\n" (formatOptions before ++ formatOptions settings) - + "\n"); + in lib.mkIf (cfg.settings != { }) { + source = pkgs.writeTextDir "htoprc" (lib.concatStringsSep "\n" + (formatOptions before ++ formatOptions settings) + "\n"); }; }; } diff --git a/modules/programs/hyfetch.nix b/modules/programs/hyfetch.nix index 485ceb04..a5e45797 100644 --- a/modules/programs/hyfetch.nix +++ b/modules/programs/hyfetch.nix @@ -1,28 +1,25 @@ { config, lib, pkgs, ... }: - -with lib; - let cfg = config.programs.hyfetch; jsonFormat = pkgs.formats.json { }; in { - meta.maintainers = [ hm.maintainers.lilyinstarlight ]; + meta.maintainers = [ lib.hm.maintainers.lilyinstarlight ]; options.programs.hyfetch = { - enable = mkEnableOption "hyfetch"; + enable = lib.mkEnableOption "hyfetch"; - package = mkOption { - type = types.package; + package = lib.mkOption { + type = lib.types.package; default = pkgs.hyfetch; - defaultText = literalExpression "pkgs.hyfetch"; + defaultText = lib.literalExpression "pkgs.hyfetch"; description = "The hyfetch package to use."; }; - settings = mkOption { + settings = lib.mkOption { type = jsonFormat.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { preset = "rainbow"; mode = "rgb"; @@ -35,9 +32,9 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; - xdg.configFile."hyfetch.json" = mkIf (cfg.settings != { }) { + xdg.configFile."hyfetch.json" = lib.mkIf (cfg.settings != { }) { source = jsonFormat.generate "hyfetch.json" cfg.settings; }; }; diff --git a/modules/programs/i3blocks.nix b/modules/programs/i3blocks.nix index e3d8d681..6c03e184 100644 --- a/modules/programs/i3blocks.nix +++ b/modules/programs/i3blocks.nix @@ -1,8 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) types; cfg = config.programs.i3blocks; @@ -23,25 +21,25 @@ let configType = types.attrsOf configAtomType; # The INI generator - mkIni = generators.toINI { }; + mkIni = lib.generators.toINI { }; in { - meta.maintainers = [ maintainers.noodlez1232 ]; + meta.maintainers = [ lib.maintainers.noodlez1232 ]; options.programs.i3blocks = { - enable = mkEnableOption "i3blocks i3 status command scheduler"; + enable = lib.mkEnableOption "i3blocks i3 status command scheduler"; - package = mkOption { + package = lib.mkOption { type = types.package; default = pkgs.i3blocks; - defaultText = literalExpression "pkgs.i3blocks"; + defaultText = lib.literalExpression "pkgs.i3blocks"; description = "Package providing {command}`i3blocks`."; }; - bars = mkOption { - type = with types; attrsOf (hm.types.dagOf configType); + bars = lib.mkOption { + type = with types; attrsOf (lib.hm.types.dagOf configType); description = "Configuration written to i3blocks config"; - example = literalExpression '' + example = lib.literalExpression '' { top = { # The title block @@ -77,10 +75,10 @@ in { # Takes a singular name value pair and turns it into an attrset nameValuePairToAttr = value: (builtins.listToAttrs [ value ]); # Converts a dag entry to a name-value pair - dagEntryToNameValue = entry: (nameValuePair entry.name entry.data); + dagEntryToNameValue = entry: (lib.nameValuePair entry.name entry.data); # Try to sort the blocks - trySortedBlocks = hm.dag.topoSort config; + trySortedBlocks = lib.hm.dag.topoSort config; # Get the blocks if successful, abort if not blocks = if trySortedBlocks ? result then @@ -95,11 +93,12 @@ in { blocks); in { # We create an "INI" file for each bar, then append them all in order - text = concatStringsSep "\n" (map (value: (mkIni value)) orderedBlocks); + text = + lib.concatStringsSep "\n" (map (value: (mkIni value)) orderedBlocks); }; # Make our config (if enabled - in mkIf cfg.enable { + in lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "programs.i3blocks" pkgs lib.platforms.linux) @@ -107,8 +106,8 @@ in { home.packages = [ cfg.package ]; - xdg.configFile = (mapAttrs' - (name: value: nameValuePair "i3blocks/${name}" (makeFile value)) + xdg.configFile = (lib.mapAttrs' + (name: value: lib.nameValuePair "i3blocks/${name}" (makeFile value)) cfg.bars); }; } diff --git a/modules/programs/i3status-rust.nix b/modules/programs/i3status-rust.nix index d9894f62..c9dc5e57 100644 --- a/modules/programs/i3status-rust.nix +++ b/modules/programs/i3status-rust.nix @@ -1,8 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) literalExpression mkOption types; cfg = config.programs.i3status-rust; @@ -12,7 +10,7 @@ in { meta.maintainers = with lib.maintainers; [ farlion thiagokokada ]; options.programs.i3status-rust = { - enable = mkEnableOption "a replacement for i3-status written in Rust"; + enable = lib.mkEnableOption "a replacement for i3-status written in Rust"; bars = mkOption { type = types.attrsOf (types.submodule { @@ -230,10 +228,10 @@ in { }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ - (hm.assertions.assertPlatform "programs.i3status-rust" pkgs - platforms.linux) + (lib.hm.assertions.assertPlatform "programs.i3status-rust" pkgs + lib.platforms.linux) { assertion = lib.versionOlder cfg.package.version "0.31.0" || lib.versionAtLeast cfg.package.version "0.31.2"; @@ -244,13 +242,13 @@ in { home.packages = [ cfg.package ]; - xdg.configFile = mapAttrs' (cfgFileSuffix: cfgBar: - nameValuePair ("i3status-rust/config-${cfgFileSuffix}.toml") ({ + xdg.configFile = lib.mapAttrs' (cfgFileSuffix: cfgBar: + lib.nameValuePair "i3status-rust/config-${cfgFileSuffix}.toml" { onChange = '' ${pkgs.procps}/bin/pkill -u $USER -USR2 i3status-rs || true ''; - source = settingsFormat.generate ("config-${cfgFileSuffix}.toml") ({ + source = settingsFormat.generate "config-${cfgFileSuffix}.toml" ({ theme = if lib.versionAtLeast cfg.package.version "0.30.0" then { theme = cfgBar.theme; } else @@ -261,6 +259,6 @@ in { cfgBar.icons; block = cfgBar.blocks; } // cfgBar.settings); - })) cfg.bars; + }) cfg.bars; }; } diff --git a/modules/programs/i3status.nix b/modules/programs/i3status.nix index 343418dc..f36b01a2 100644 --- a/modules/programs/i3status.nix +++ b/modules/programs/i3status.nix @@ -1,11 +1,10 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) literalExpression mkDefault mkOption types; + cfg = config.programs.i3status; - enabledModules = filterAttrs (n: v: v.enable) cfg.modules; + enabledModules = lib.filterAttrs (n: v: v.enable) cfg.modules; formatOrder = n: ''order += "${n}"''; @@ -14,16 +13,16 @@ let formatLine = n: v: let formatValue = v: - if isBool v then + if lib.isBool v then (if v then "true" else "false") - else if isString v then + else if lib.isString v then ''"${v}"'' else toString v; in "${n} = ${formatValue v}"; in '' ${n} { - ${concatStringsSep "\n " (mapAttrsToList formatLine v)} + ${lib.concatStringsSep "\n " (lib.mapAttrsToList formatLine v)} } ''; @@ -31,12 +30,12 @@ let sortAttrNamesByPosition = comparator: set: let pos = n: set."${n}".position; - in sort (a: b: comparator (pos a) (pos b)) (attrNames set); + in lib.sort (a: b: comparator (pos a) (pos b)) (lib.attrNames set); in { - meta.maintainers = [ hm.maintainers.justinlovinger ]; + meta.maintainers = [ lib.hm.maintainers.justinlovinger ]; options.programs.i3status = { - enable = mkEnableOption "i3status"; + enable = lib.mkEnableOption "i3status"; enableDefault = mkOption { type = types.bool; @@ -130,11 +129,11 @@ in { ''; }; - package = mkPackageOption pkgs "i3status" { nullable = true; }; + package = lib.mkPackageOption pkgs "i3status" { nullable = true; }; }; - config = mkIf cfg.enable { - programs.i3status = mkIf cfg.enableDefault { + config = lib.mkIf cfg.enable { + programs.i3status = lib.mkIf cfg.enableDefault { general = { colors = mkDefault true; interval = mkDefault 5; @@ -192,10 +191,10 @@ in { home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; - xdg.configFile."i3status/config".text = concatStringsSep "\n" ([ ] - ++ optional (cfg.general != { }) (formatModule "general" cfg.general) - ++ map formatOrder (sortAttrNamesByPosition lessThan enabledModules) - ++ mapAttrsToList formatModule - (mapAttrs (n: v: v.settings) enabledModules)); + xdg.configFile."i3status/config".text = lib.concatStringsSep "\n" ([ ] + ++ lib.optional (cfg.general != { }) (formatModule "general" cfg.general) + ++ map formatOrder (sortAttrNamesByPosition lib.lessThan enabledModules) + ++ lib.mapAttrsToList formatModule + (lib.mapAttrs (n: v: v.settings) enabledModules)); }; } diff --git a/modules/programs/imv.nix b/modules/programs/imv.nix index 2cad3813..aa3a4906 100644 --- a/modules/programs/imv.nix +++ b/modules/programs/imv.nix @@ -1,31 +1,28 @@ { config, lib, pkgs, ... }: - -with lib; - let cfg = config.programs.imv; toConfig = attrs: '' # Generated by Home Manager. - '' + generators.toINI { } attrs; + '' + lib.generators.toINI { } attrs; in { - meta.maintainers = [ maintainers.christoph-heiss ]; + meta.maintainers = [ lib.maintainers.christoph-heiss ]; options.programs.imv = { - enable = mkEnableOption + enable = lib.mkEnableOption "imv: a command line image viewer intended for use with tiling window managers"; - package = mkPackageOption pkgs "imv" { nullable = true; }; + package = lib.mkPackageOption pkgs "imv" { nullable = true; }; - settings = mkOption { + settings = lib.mkOption { default = { }; - type = with types; attrsOf (attrsOf (oneOf [ bool int str ])); + type = with lib.types; attrsOf (attrsOf (oneOf [ bool int str ])); description = '' Configuration options for imv. See {manpage}`imv(5)`. ''; - example = literalExpression '' + example = lib.literalExpression '' { options.background = "ffffff"; aliases.x = "close"; @@ -34,13 +31,15 @@ in { }; }; - config = mkIf cfg.enable { - assertions = - [ (hm.assertions.assertPlatform "programs.imv" pkgs platforms.linux) ]; + config = lib.mkIf cfg.enable { + assertions = [ + (lib.hm.assertions.assertPlatform "programs.imv" pkgs lib.platforms.linux) + ]; home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; - xdg.configFile = - mkIf (cfg.settings != { }) { "imv/config".text = toConfig cfg.settings; }; + xdg.configFile = lib.mkIf (cfg.settings != { }) { + "imv/config".text = toConfig cfg.settings; + }; }; } diff --git a/modules/programs/info.nix b/modules/programs/info.nix index a7d2692b..61fbca5a 100644 --- a/modules/programs/info.nix +++ b/modules/programs/info.nix @@ -18,9 +18,6 @@ # This is really nice. { config, lib, pkgs, ... }: - -with lib; - let cfg = config.programs.info; @@ -32,15 +29,15 @@ let in { imports = [ - (mkRemovedOptionModule [ "programs" "info" "homeInfoDirLocation" ] '' + (lib.mkRemovedOptionModule [ "programs" "info" "homeInfoDirLocation" ] '' The `dir` file is now generated as part of the Home Manager profile and will no longer be placed in your home directory. '') ]; - options.programs.info.enable = mkEnableOption "GNU Info"; + options.programs.info.enable = lib.mkEnableOption "GNU Info"; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ infoPkg diff --git a/modules/programs/ion.nix b/modules/programs/ion.nix index b4d770b0..626786ab 100644 --- a/modules/programs/ion.nix +++ b/modules/programs/ion.nix @@ -1,18 +1,18 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; + cfg = config.programs.ion; - aliasesStr = concatStringsSep "\n" - (mapAttrsToList (k: v: "alias ${k} = ${escapeShellArg v}") + aliasesStr = lib.concatStringsSep "\n" + (lib.mapAttrsToList (k: v: "alias ${k} = ${lib.escapeShellArg v}") cfg.shellAliases); in { - meta.maintainers = [ maintainers.jo1gi ]; + meta.maintainers = [ lib.maintainers.jo1gi ]; options.programs.ion = { - enable = mkEnableOption "the Ion Shell. Compatible with Redox and Linux"; + enable = + lib.mkEnableOption "the Ion Shell. Compatible with Redox and Linux"; package = lib.mkPackageOption pkgs "ion" { }; @@ -27,7 +27,7 @@ in { shellAliases = mkOption { type = with types; attrsOf str; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { g = "git"; } @@ -39,7 +39,7 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; xdg.configFile."ion/initrc".text = '' diff --git a/modules/programs/irssi.nix b/modules/programs/irssi.nix index bcce6cfa..34dd7d31 100644 --- a/modules/programs/irssi.nix +++ b/modules/programs/irssi.nix @@ -1,12 +1,10 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) concatStringsSep flip mapAttrsToList mkOption types; cfg = config.programs.irssi; - quoteStr = s: escape [ ''"'' ] s; + quoteStr = s: lib.escape [ ''"'' ] s; # Comma followed by newline. cnl = '' @@ -22,7 +20,7 @@ let ${k} = { type = "${v.type}"; nick = "${quoteStr v.nick}"; - autosendcmd = "${concatMapStringsSep ";" quoteStr v.autoCommands}"; + autosendcmd = "${lib.concatMapStringsSep ";" quoteStr v.autoCommands}"; ${ lib.optionalString (v.saslExternal) '' sasl_username = "${quoteStr v.nick}"; @@ -41,14 +39,14 @@ let ssl_verify = "${lib.hm.booleans.yesNo v.server.ssl.verify}"; autoconnect = "${lib.hm.booleans.yesNo v.server.autoConnect}"; ${ - optionalString (v.server.ssl.certificateFile != null) '' + lib.optionalString (v.server.ssl.certificateFile != null) '' ssl_cert = "${v.server.ssl.certificateFile}"; '' } } '')); - channelString = concatStringsSep cnl (concatLists + channelString = concatStringsSep cnl (lib.concatLists (flip mapAttrsToList cfg.networks (k: v: (flip mapAttrsToList v.channels (c: cv: '' { @@ -163,7 +161,7 @@ in { options = { programs.irssi = { - enable = mkEnableOption "the Irssi chat client"; + enable = lib.mkEnableOption "the Irssi chat client"; extraConfig = mkOption { default = ""; @@ -183,7 +181,7 @@ in { networks = mkOption { default = { }; - example = literalExpression '' + example = lib.literalExpression '' { liberachat = { nick = "hmuser"; @@ -204,7 +202,7 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ pkgs.irssi ]; home.file.".irssi/config".text = '' diff --git a/modules/programs/java.nix b/modules/programs/java.nix index fb3c70ec..e8280e3e 100644 --- a/modules/programs/java.nix +++ b/modules/programs/java.nix @@ -1,20 +1,16 @@ # This module provides JAVA_HOME, with a different way to install java locally. # This module is modified from the NixOS module `programs.java` - { config, lib, pkgs, ... }: - -with lib; - let cfg = config.programs.java; in { - meta.maintainers = with maintainers; [ ShamrockLee ]; + meta.maintainers = with lib.maintainers; [ ShamrockLee ]; options = { programs.java = { - enable = mkEnableOption "" // { + enable = lib.mkEnableOption "" // { description = '' Install the Java development kit and set the {env}`JAVA_HOME` variable. @@ -28,7 +24,7 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; # some instances of `jdk-linux-base.nix` pass through `result` without turning it onto a path-string. diff --git a/modules/programs/jetbrains-remote.nix b/modules/programs/jetbrains-remote.nix index 917fe87c..fdd42547 100644 --- a/modules/programs/jetbrains-remote.nix +++ b/modules/programs/jetbrains-remote.nix @@ -1,21 +1,15 @@ -{ config, lib, pkgs, ... }: - -with lib; - -let - - cfg = config.programs.jetbrains-remote; - +{ config, lib, ... }: +let cfg = config.programs.jetbrains-remote; in { meta.maintainers = with lib.maintainers; [ genericnerdyusername ]; options.programs.jetbrains-remote = { - enable = mkEnableOption "JetBrains remote development system"; + enable = lib.mkEnableOption "JetBrains remote development system"; - ides = mkOption { - type = types.listOf types.package; + ides = lib.mkOption { + type = lib.types.listOf lib.types.package; default = [ ]; - example = literalExpression '' + example = lib.literalExpression '' with pkgs.jetbrains; [ clion pycharm-professional ]; ''; description = '' @@ -24,7 +18,7 @@ in { }; }; - config = mkIf (cfg.enable && cfg.ides != [ ]) { + config = lib.mkIf (cfg.enable && cfg.ides != [ ]) { home.activation.jetBrainsRemote = let mkLine = ide: # Errors out if the symlink already exists @@ -32,7 +26,7 @@ in { lines = map mkLine cfg.ides; linesStr = '' rm $HOME/.cache/JetBrains/RemoteDev/userProvidedDist/_nix_store* || true - '' + concatStringsSep "\n" lines; - in hm.dag.entryAfter [ "writeBoundary" ] linesStr; + '' + lib.concatStringsSep "\n" lines; + in lib.hm.dag.entryAfter [ "writeBoundary" ] linesStr; }; } diff --git a/modules/programs/joshuto.nix b/modules/programs/joshuto.nix index 6f87277d..41534cea 100644 --- a/modules/programs/joshuto.nix +++ b/modules/programs/joshuto.nix @@ -1,20 +1,19 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkIf mkOption types; + cfg = config.programs.joshuto; tomlFormat = pkgs.formats.toml { }; in { - meta.maintainers = [ hm.maintainers.rasmus-kirk ]; + meta.maintainers = [ lib.hm.maintainers.rasmus-kirk ]; options.programs.joshuto = { - enable = mkEnableOption "joshuto file manager"; + enable = lib.mkEnableOption "joshuto file manager"; package = mkOption { type = types.package; default = pkgs.joshuto; - defaultText = literalExpression "pkgs.joshuto"; + defaultText = lib.literalExpression "pkgs.joshuto"; description = "The package to use for joshuto."; }; diff --git a/modules/programs/jq.nix b/modules/programs/jq.nix index f4ec5334..3bd522d6 100644 --- a/modules/programs/jq.nix +++ b/modules/programs/jq.nix @@ -1,8 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkIf mkOption types; cfg = config.programs.jq; @@ -28,12 +26,12 @@ let in { options = { programs.jq = { - enable = mkEnableOption "the jq command-line JSON processor"; + enable = lib.mkEnableOption "the jq command-line JSON processor"; package = mkOption { type = types.package; default = pkgs.jq; - defaultText = literalExpression "pkgs.jq"; + defaultText = lib.literalExpression "pkgs.jq"; description = "jq package to use."; }; @@ -45,7 +43,7 @@ in { of the jq manual. ''; - example = literalExpression '' + example = lib.literalExpression '' { null = "1;30"; false = "0;31"; diff --git a/modules/programs/jujutsu.nix b/modules/programs/jujutsu.nix index 7ba71acb..88c93be0 100644 --- a/modules/programs/jujutsu.nix +++ b/modules/programs/jujutsu.nix @@ -1,8 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkIf mkOption types; cfg = config.programs.jujutsu; tomlFormat = pkgs.formats.toml { }; @@ -13,24 +11,27 @@ let config.xdg.configHome; in { - meta.maintainers = [ maintainers.shikanime ]; + meta.maintainers = [ lib.maintainers.shikanime ]; imports = let mkRemovedShellIntegration = name: - mkRemovedOptionModule [ "programs" "jujutsu" "enable${name}Integration" ] - "This option is no longer necessary."; + lib.mkRemovedOptionModule [ + "programs" + "jujutsu" + "enable${name}Integration" + ] "This option is no longer necessary."; in map mkRemovedShellIntegration [ "Bash" "Fish" "Zsh" ]; options.programs.jujutsu = { - enable = - mkEnableOption "a Git-compatible DVCS that is both simple and powerful"; + enable = lib.mkEnableOption + "a Git-compatible DVCS that is both simple and powerful"; - package = mkPackageOption pkgs "jujutsu" { nullable = true; }; + package = lib.mkPackageOption pkgs "jujutsu" { nullable = true; }; ediff = mkOption { type = types.bool; default = config.programs.emacs.enable; - defaultText = literalExpression "config.programs.emacs.enable"; + defaultText = lib.literalExpression "config.programs.emacs.enable"; description = '' Enable ediff as a merge tool ''; @@ -54,18 +55,18 @@ in { }; config = mkIf cfg.enable { - home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; + home.packages = mkIf (cfg.package != null) [ cfg.package ]; home.file."${configDir}/jj/config.toml" = mkIf (cfg.settings != { }) { source = tomlFormat.generate "jujutsu-config" (cfg.settings - // optionalAttrs (cfg.ediff) (let + // lib.optionalAttrs (cfg.ediff) (let emacsDiffScript = pkgs.writeShellScriptBin "emacs-ediff" '' set -euxo pipefail ${config.programs.emacs.package}/bin/emacsclient -c --eval "(ediff-merge-files-with-ancestor \"$1\" \"$2\" \"$3\" nil \"$4\")" ''; in { merge-tools.ediff = { - program = getExe emacsDiffScript; + program = lib.getExe emacsDiffScript; merge-args = [ "$left" "$right" "$base" "$output" ]; }; })); diff --git a/modules/programs/k9s.nix b/modules/programs/k9s.nix index b0d66982..7bc62e93 100644 --- a/modules/programs/k9s.nix +++ b/modules/programs/k9s.nix @@ -1,18 +1,19 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) literalExpression mkIf mkOption types; cfg = config.programs.k9s; yamlFormat = pkgs.formats.yaml { }; inherit (pkgs.stdenv.hostPlatform) isDarwin; in { - meta.maintainers = with maintainers; [ liyangau hm.maintainers.LucasWagler ]; + meta.maintainers = with lib.maintainers; [ + liyangau + lib.hm.maintainers.LucasWagler + ]; imports = [ - (mkRenamedOptionModule [ "programs" "k9s" "skin" ] [ + (lib.mkRenamedOptionModule [ "programs" "k9s" "skin" ] [ "programs" "k9s" "skins" @@ -21,10 +22,10 @@ in { ]; options.programs.k9s = { - enable = - mkEnableOption "k9s - Kubernetes CLI To Manage Your Clusters In Style"; + enable = lib.mkEnableOption + "k9s - Kubernetes CLI To Manage Your Clusters In Style"; - package = mkPackageOption pkgs "k9s" { nullable = true; }; + package = lib.mkPackageOption pkgs "k9s" { nullable = true; }; settings = mkOption { type = yamlFormat.type; @@ -168,8 +169,8 @@ in { } else { }; - skinFiles = mapAttrs' (name: value: - nameValuePair (if !(isDarwin && !config.xdg.enable) then + skinFiles = lib.mapAttrs' (name: value: + lib.nameValuePair (if !(isDarwin && !config.xdg.enable) then "k9s/skins/${name}.yaml" else "Library/Application Support/k9s/skins/${name}.yaml") { diff --git a/modules/programs/kakoune.nix b/modules/programs/kakoune.nix index 7aed4125..dba1e0af 100644 --- a/modules/programs/kakoune.nix +++ b/modules/programs/kakoune.nix @@ -1,8 +1,8 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) + concatStrings concatStringsSep mkIf mkOption mkEnableOption optional + optionalString types; cfg = config.programs.kakoune; @@ -559,7 +559,7 @@ let ]) "try %{declare-user-mode ${mode}}"; userModeStrings = map userModeString - (lists.unique (map (km: km.mode) cfg.config.keyMappings)); + (lib.lists.unique (map (km: km.mode) cfg.config.keyMappings)); keyMappingString = km: concatStringsSep " " [ @@ -588,7 +588,7 @@ let ++ optional (indentWidth != null) "set-option global indentwidth ${toString indentWidth}" ++ optional (!incrementalSearch) "set-option global incsearch false" - ++ optional (alignWithTabs) "set-option global aligntab true" + ++ optional alignWithTabs "set-option global aligntab true" ++ optional (autoInfo != null) "set-option global autoinfo ${concatStringsSep "|" autoInfo}" ++ optional (autoComplete != null) @@ -622,7 +622,8 @@ in { programs.kakoune = { enable = mkEnableOption "the kakoune text editor"; - package = mkPackageOption pkgs "kakoune-unwrapped" { nullable = true; }; + package = + lib.mkPackageOption pkgs "kakoune-unwrapped" { nullable = true; }; config = mkOption { type = types.nullOr configModule; @@ -651,7 +652,7 @@ in { plugins = mkOption { type = with types; listOf package; default = [ ]; - example = literalExpression "[ pkgs.kakounePlugins.kak-fzf ]"; + example = lib.literalExpression "[ pkgs.kakounePlugins.kak-fzf ]"; description = '' List of kakoune plugins to install. To get a list of supported plugins run: @@ -664,7 +665,8 @@ in { colorSchemePackage = mkOption { type = with types; nullOr package; default = null; - example = literalExpression "pkgs.kakounePlugins.kakoune-catppuccin"; + example = + lib.literalExpression "pkgs.kakounePlugins.kakoune-catppuccin"; description = '' A kakoune color schemes to add to your colors folder. This works because kakoune recursively checks @@ -676,7 +678,7 @@ in { }; config = mkIf cfg.enable { - warnings = optional (cfg.package == null && cfg.plugins != [ ]) '' + warnings = lib.optional (cfg.package == null && cfg.plugins != [ ]) '' You have configured `plugins` for `kakoune` but have not set `package`. The listed plugins will not be installed. @@ -684,7 +686,7 @@ in { home.packages = lib.mkIf (cfg.package != null) [ kakouneWithPlugins ]; home.sessionVariables = mkIf cfg.defaultEditor { EDITOR = "kak"; }; - xdg.configFile = mkMerge [ + xdg.configFile = lib.mkMerge [ { "kak/kakrc".source = configFile; } (mkIf (cfg.colorSchemePackage != null) { "kak/colors/${cfg.colorSchemePackage.name}".source = diff --git a/modules/programs/keychain.nix b/modules/programs/keychain.nix index 05bf3f13..4a598a73 100644 --- a/modules/programs/keychain.nix +++ b/modules/programs/keychain.nix @@ -1,25 +1,23 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkIf mkOption types; cfg = config.programs.keychain; - flags = cfg.extraFlags ++ optional (cfg.agents != [ ]) - "--agents ${concatStringsSep "," cfg.agents}" - ++ optional (cfg.inheritType != null) "--inherit ${cfg.inheritType}"; + flags = cfg.extraFlags ++ lib.optional (cfg.agents != [ ]) + "--agents ${lib.concatStringsSep "," cfg.agents}" + ++ lib.optional (cfg.inheritType != null) "--inherit ${cfg.inheritType}"; shellCommand = - "${cfg.package}/bin/keychain --eval ${concatStringsSep " " flags} ${ - concatStringsSep " " cfg.keys + "${cfg.package}/bin/keychain --eval ${lib.concatStringsSep " " flags} ${ + lib.concatStringsSep " " cfg.keys }"; in { meta.maintainers = [ ]; options.programs.keychain = { - enable = mkEnableOption "keychain"; + enable = lib.mkEnableOption "keychain"; package = lib.mkPackageOption pkgs "keychain" { }; diff --git a/modules/programs/khal-accounts.nix b/modules/programs/khal-accounts.nix index bbf222d9..da3bdf11 100644 --- a/modules/programs/khal-accounts.nix +++ b/modules/programs/khal-accounts.nix @@ -1,8 +1,6 @@ -{ config, lib, ... }: - -with lib; - -{ +{ lib, ... }: +let inherit (lib) mkOption types; +in { options.khal = { enable = lib.mkEnableOption "khal access"; diff --git a/modules/programs/khal-calendar-accounts.nix b/modules/programs/khal-calendar-accounts.nix index 3aa2494e..7131ca3c 100644 --- a/modules/programs/khal-calendar-accounts.nix +++ b/modules/programs/khal-calendar-accounts.nix @@ -1,19 +1,15 @@ -{ config, lib, ... }: - -with lib; - -{ +{ lib, ... }: { options.khal = { - type = mkOption { - type = types.enum [ "calendar" "discover" ]; + type = lib.mkOption { + type = lib.types.enum [ "calendar" "discover" ]; default = "calendar"; description = '' Either a single calendar (calendar which is the default) or a directory with multiple calendars (discover). ''; }; - glob = mkOption { - type = types.str; + glob = lib.mkOption { + type = lib.types.str; default = "*"; description = '' The glob expansion to be searched for events or birthdays when diff --git a/modules/programs/khal-contact-accounts.nix b/modules/programs/khal-contact-accounts.nix index c58ed4d6..7cb463e4 100644 --- a/modules/programs/khal-contact-accounts.nix +++ b/modules/programs/khal-contact-accounts.nix @@ -1,11 +1,7 @@ -{ config, lib, ... }: - -with lib; - -{ +{ lib, ... }: { options.khal = { - collections = mkOption { - type = types.nullOr (types.listOf types.str); + collections = lib.mkOption { + type = with lib.types; nullOr (listOf str); default = null; description = '' VCARD collections to be searched for contact birthdays. diff --git a/modules/programs/khal.nix b/modules/programs/khal.nix index 96879c52..17144ab7 100644 --- a/modules/programs/khal.nix +++ b/modules/programs/khal.nix @@ -1,9 +1,7 @@ # khal config loader is sensitive to leading space ! { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkOption optional optionalString filterAttrs recursiveUpdate; cfg = config.programs.khal; @@ -15,7 +13,7 @@ let # a contact account may have multiple collections, each a separate calendar expandContactAccount = name: acct: if acct.khal.collections != null then - listToAttrs (map (c: { + lib.listToAttrs (map (c: { name = "${name}-${c}"; value = recursiveUpdate acct { khal.thisCollection = c; }; }) acct.khal.collections) @@ -23,21 +21,22 @@ let ${name} = acct; }; - khalContactAccounts = concatMapAttrs expandContactAccount - (mapAttrs (_: v: recursiveUpdate v { khal.type = "birthdays"; }) + khalContactAccounts = lib.concatMapAttrs expandContactAccount + (lib.mapAttrs (_: v: recursiveUpdate v { khal.type = "birthdays"; }) (filterAttrs (_: a: a.khal.enable) config.accounts.contact.accounts)); khalAccounts = khalCalendarAccounts // khalContactAccounts; - primaryAccount = findSingle (a: a.primary) null null - (mapAttrsToList (n: v: v // { name = n; }) khalCalendarAccounts); + primaryAccount = lib.findSingle (a: a.primary) null null + (lib.mapAttrsToList (n: v: v // { name = n; }) khalCalendarAccounts); definedAttrs = filterAttrs (_: v: !isNull v); - toKeyValueIfDefined = attrs: generators.toKeyValue { } (definedAttrs attrs); + toKeyValueIfDefined = attrs: + lib.generators.toKeyValue { } (definedAttrs attrs); genCalendarStr = name: value: - concatStringsSep "\n" ([ + lib.concatStringsSep "\n" ([ "[[${name}]]" "path = ${ value.local.path + "/" @@ -50,8 +49,9 @@ let ++ optional (value.khal.addresses != [ ]) "addresses= ${lib.concatStringsSep ", " value.khal.addresses}" ++ optional (value.khal.color != null) "color = '${value.khal.color}'" - ++ [ (toKeyValueIfDefined (getAttrs [ "type" "priority" ] value.khal)) ] - ++ [ "\n" ]); + ++ [ + (toKeyValueIfDefined (lib.getAttrs [ "type" "priority" ] value.khal)) + ] ++ [ "\n" ]); localeFormatOptions = let T = lib.types; @@ -166,9 +166,9 @@ let in { options.programs.khal = { - enable = mkEnableOption "khal, a CLI calendar application"; + enable = lib.mkEnableOption "khal, a CLI calendar application"; - package = mkPackageOption pkgs "khal" { nullable = true; }; + package = lib.mkPackageOption pkgs "khal" { nullable = true; }; locale = mkOption { type = lib.types.submodule { options = localeOptions; }; @@ -181,7 +181,7 @@ in { settings = mkOption { type = iniFormat.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { default = { default_calendar = "Calendar"; @@ -198,15 +198,15 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; - xdg.configFile."khal/config".text = concatStringsSep "\n" ([ "[calendars]" ] - ++ mapAttrsToList genCalendarStr khalAccounts ++ [ - (generators.toINI { } (recursiveUpdate cfg.settings { + xdg.configFile."khal/config".text = lib.concatStringsSep "\n" + ([ "[calendars]" ] ++ lib.mapAttrsToList genCalendarStr khalAccounts ++ [ + (lib.generators.toINI { } (recursiveUpdate cfg.settings { locale = definedAttrs (cfg.locale // { _module = null; }); - default = optionalAttrs (!isNull primaryAccount) { + default = lib.optionalAttrs (!isNull primaryAccount) { highlight_event_days = true; default_calendar = if isNull primaryAccount.primaryCollection then primaryAccount.name diff --git a/modules/programs/kodi.nix b/modules/programs/kodi.nix index f6776b9e..ea81a574 100644 --- a/modules/programs/kodi.nix +++ b/modules/programs/kodi.nix @@ -1,8 +1,7 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) literalExpression mkIf mkOption types; + cfg = config.programs.kodi; stylesheetCommonHeader = '' @@ -122,10 +121,10 @@ let in attrsetToXml attrs name stylesheet; in { - meta.maintainers = [ hm.maintainers.dwagenk ]; + meta.maintainers = [ lib.hm.maintainers.dwagenk ]; options.programs.kodi = { - enable = mkEnableOption "Kodi"; + enable = lib.mkEnableOption "Kodi"; package = mkOption { type = types.package; @@ -222,7 +221,7 @@ in { }; }; - config = mkIf cfg.enable (mkMerge [ + config = mkIf cfg.enable (lib.mkMerge [ { assertions = [ (lib.hm.assertions.assertPlatform "programs.kodi" pkgs @@ -244,9 +243,9 @@ in { }) (mkIf (cfg.addonSettings != null) { - home.file = mapAttrs' (k: v: - attrsets.nameValuePair - ("${cfg.datadir}/userdata/addon_data/${k}/settings.xml") { + home.file = lib.mapAttrs' (k: v: + lib.attrsets.nameValuePair + "${cfg.datadir}/userdata/addon_data/${k}/settings.xml" { source = attrsetToAddonSettingsXml v "kodi-addon-${k}-settings.xml"; }) cfg.addonSettings; }) diff --git a/modules/programs/kubecolor.nix b/modules/programs/kubecolor.nix index 807a5555..25f5f824 100644 --- a/modules/programs/kubecolor.nix +++ b/modules/programs/kubecolor.nix @@ -1,20 +1,18 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkIf mkOption types; cfg = config.programs.kubecolor; yamlFormat = pkgs.formats.yaml { }; inherit (pkgs.stdenv.hostPlatform) isDarwin; in { - meta.maintainers = with maintainers; [ ajgon ]; + meta.maintainers = with lib.maintainers; [ ajgon ]; options.programs.kubecolor = { - enable = mkEnableOption "kubecolor - Colorize your kubectl output"; + enable = lib.mkEnableOption "kubecolor - Colorize your kubectl output"; - package = mkPackageOption pkgs "kubecolor" { }; + package = lib.mkPackageOption pkgs "kubecolor" { }; enableAlias = mkOption { type = types.bool; @@ -31,7 +29,7 @@ in { settings = mkOption { type = yamlFormat.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' kubectl = lib.getExe pkgs.kubectl preset = "dark"; paging = "auto"; @@ -58,7 +56,7 @@ in { "kube/color.yaml"; in mkIf cfg.enable { - warnings = optional (cfg.package == null && cfg.plugins != [ ]) '' + warnings = lib.optional (cfg.package == null && cfg.plugins != [ ]) '' You have configured `enableAlias` for `kubecolor` but have not set `package`. The alias will not be created. diff --git a/modules/programs/lapce.nix b/modules/programs/lapce.nix index baf6f240..2354f293 100644 --- a/modules/programs/lapce.nix +++ b/modules/programs/lapce.nix @@ -1,13 +1,12 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) literalExpression mkIf mkOption types; + cfg = config.programs.lapce; options = { - enable = mkEnableOption "lapce"; - package = mkPackageOption pkgs "lapce" { nullable = true; }; + enable = lib.mkEnableOption "lapce"; + package = lib.mkPackageOption pkgs "lapce" { nullable = true; }; channel = mkOption { type = types.enum [ "stable" "nightly" ]; default = "stable"; @@ -141,7 +140,7 @@ let outputHashAlgo = "sha256"; outputHashMode = "flat"; outputHash = hash; - inherit meta; + inherit (lib) meta; }); pluginFromRegistry = { author, name, version, hash }@args: pkgs.stdenvNoCC.mkDerivation { @@ -166,7 +165,7 @@ let value = pluginFromRegistry plugin; }) plugins)); in { - meta.maintainers = [ hm.maintainers.timon-schelling ]; + meta.maintainers = [ lib.hm.maintainers.timon-schelling ]; options.programs.lapce = options; diff --git a/modules/programs/lazygit.nix b/modules/programs/lazygit.nix index 0c355c6d..ea64dfc4 100644 --- a/modules/programs/lazygit.nix +++ b/modules/programs/lazygit.nix @@ -1,8 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkIf; cfg = config.programs.lazygit; @@ -14,15 +12,16 @@ in { meta.maintainers = [ lib.hm.maintainers.kalhauge lib.maintainers.khaneliman ]; options.programs.lazygit = { - enable = mkEnableOption "lazygit, a simple terminal UI for git commands"; + enable = + lib.mkEnableOption "lazygit, a simple terminal UI for git commands"; - package = mkPackageOption pkgs "lazygit" { nullable = true; }; + package = lib.mkPackageOption pkgs "lazygit" { nullable = true; }; - settings = mkOption { + settings = lib.mkOption { type = yamlFormat.type; default = { }; - defaultText = literalExpression "{ }"; - example = literalExpression '' + defaultText = lib.literalExpression "{ }"; + example = lib.literalExpression '' { gui.theme = { lightTheme = true; @@ -45,7 +44,7 @@ in { }; config = mkIf cfg.enable { - home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; + home.packages = mkIf (cfg.package != null) [ cfg.package ]; home.file."Library/Application Support/lazygit/config.yml" = mkIf (cfg.settings != { } && (isDarwin && !config.xdg.enable)) { diff --git a/modules/programs/ledger.nix b/modules/programs/ledger.nix index 441fc157..3b067b5a 100644 --- a/modules/programs/ledger.nix +++ b/modules/programs/ledger.nix @@ -1,15 +1,13 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkIf mkOption types; cfg = config.programs.ledger; - cfgText = generators.toKeyValue { + cfgText = lib.generators.toKeyValue { mkKeyValue = key: value: - if isBool value then - optionalString value "--${key}" + if lib.isBool value then + lib.optionalString value "--${key}" else "--${key} ${toString value}"; listsAsDuplicateKeys = true; @@ -19,9 +17,9 @@ in { meta.maintainers = [ ]; options.programs.ledger = { - enable = mkEnableOption "ledger, a double-entry accounting system"; + enable = lib.mkEnableOption "ledger, a double-entry accounting system"; - package = mkPackageOption pkgs "ledger" { nullable = true; }; + package = lib.mkPackageOption pkgs "ledger" { nullable = true; }; settings = mkOption { type = with types; attrsOf (oneOf [ bool int str (listOf str) ]); @@ -46,7 +44,7 @@ in { extraConfig = mkOption { type = types.lines; default = ""; - example = literalExpression '' + example = lib.literalExpression '' --sort date --effective --date-format %Y-%m-%d @@ -59,7 +57,7 @@ in { }; config = mkIf cfg.enable { - home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; + home.packages = mkIf (cfg.package != null) [ cfg.package ]; xdg.configFile."ledger/ledgerrc" = mkIf (cfg.settings != { } || cfg.extraConfig != "") { diff --git a/modules/programs/less.nix b/modules/programs/less.nix index 7249f9bb..0867b9a4 100644 --- a/modules/programs/less.nix +++ b/modules/programs/less.nix @@ -1,17 +1,14 @@ { config, lib, pkgs, ... }: - -with lib; - let cfg = config.programs.less; in { - meta.maintainers = [ maintainers.pamplemousse ]; + meta.maintainers = [ lib.maintainers.pamplemousse ]; options = { programs.less = { - enable = mkEnableOption "less, opposite of more"; + enable = lib.mkEnableOption "less, opposite of more"; - keys = mkOption { - type = types.lines; + keys = lib.mkOption { + type = lib.types.lines; default = ""; example = '' s back-line @@ -25,7 +22,7 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ pkgs.less ]; xdg.configFile."lesskey".text = cfg.keys; }; diff --git a/modules/programs/lesspipe.nix b/modules/programs/lesspipe.nix index a9bca279..062aa707 100644 --- a/modules/programs/lesspipe.nix +++ b/modules/programs/lesspipe.nix @@ -1,23 +1,17 @@ { config, lib, pkgs, ... }: - -with lib; - -let - - cfg = config.programs.lesspipe; - +let cfg = config.programs.lesspipe; in { - meta.maintainers = [ maintainers.rycee ]; + meta.maintainers = [ lib.maintainers.rycee ]; options = { programs.lesspipe = { - enable = mkEnableOption "lesspipe preprocessor for less"; + enable = lib.mkEnableOption "lesspipe preprocessor for less"; - package = mkPackageOption pkgs "lesspipe" { }; + package = lib.mkPackageOption pkgs "lesspipe" { }; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.sessionVariables = { LESSOPEN = "|${cfg.package}/bin/lesspipe.sh %s"; }; diff --git a/modules/programs/lf.nix b/modules/programs/lf.nix index 995b926f..31094716 100644 --- a/modules/programs/lf.nix +++ b/modules/programs/lf.nix @@ -1,14 +1,16 @@ { config, lib, pkgs, ... }: +let + inherit (lib) + concatStringsSep literalExpression mapAttrsToList mkOption optionalString + types; -with lib; - -let cfg = config.programs.lf; + cfg = config.programs.lf; in { - meta.maintainers = [ hm.maintainers.owm111 ]; + meta.maintainers = [ lib.hm.maintainers.owm111 ]; options = { programs.lf = { - enable = mkEnableOption "lf"; + enable = lib.mkEnableOption "lf"; package = mkOption { type = types.package; @@ -117,22 +119,22 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; xdg.configFile."lf/lfrc".text = let fmtSetting = k: v: optionalString (v != null) "set ${ - if isBool v then + if lib.isBool v then "${optionalString (!v) "no"}${k}" - else if isList v then + else if lib.isList v then ''${k} "${concatStringsSep ":" (map (w: toString w) v)}"'' else - "${k} ${if isInt v then toString v else ''"${v}"''}" + "${k} ${if lib.isInt v then toString v else ''"${v}"''}" }"; settingsStr = concatStringsSep "\n" - (remove "" (mapAttrsToList fmtSetting cfg.settings)); + (lib.remove "" (mapAttrsToList fmtSetting cfg.settings)); fmtCmdMap = before: k: v: "${before} ${k}${optionalString (v != null && v != "") " ${v}"}"; diff --git a/modules/programs/librewolf.nix b/modules/programs/librewolf.nix index 86f640c8..d8ca21c6 100644 --- a/modules/programs/librewolf.nix +++ b/modules/programs/librewolf.nix @@ -1,7 +1,4 @@ -{ config, lib, pkgs, ... }: - -with lib; - +{ config, lib, ... }: let cfg = config.programs.librewolf; @@ -9,7 +6,7 @@ let mkOverridesFile = prefs: '' // Generated by Home Manager. - ${concatStrings (mapAttrsToList (name: value: '' + ${lib.concatStrings (lib.mapAttrsToList (name: value: '' defaultPref("${name}", ${builtins.toJSON value}); '') prefs)} ''; @@ -19,7 +16,7 @@ let mkFirefoxModule = import ./firefox/mkFirefoxModule.nix; in { - meta.maintainers = [ maintainers.chayleaf maintainers.onny ]; + meta.maintainers = with lib.maintainers; [ chayleaf onny ]; imports = [ (mkFirefoxModule { @@ -39,10 +36,10 @@ in { ]; options.programs.librewolf = { - 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 = literalExpression '' + example = lib.literalExpression '' { "webgl.disabled" = false; "privacy.resistFingerprinting" = false; @@ -56,7 +53,7 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.file.".librewolf/librewolf.overrides.cfg" = lib.mkIf (cfg.settings != { }) { text = mkOverridesFile cfg.settings; }; }; diff --git a/modules/programs/lieer.nix b/modules/programs/lieer.nix index 80993f90..f67cdfc9 100644 --- a/modules/programs/lieer.nix +++ b/modules/programs/lieer.nix @@ -1,22 +1,21 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) concatStringsSep mkIf mkOption mkRenamedOptionModule types; + cfg = config.programs.lieer; - lieerAccounts = - filter (a: a.lieer.enable) (attrValues config.accounts.email.accounts); + lieerAccounts = lib.filter (a: a.lieer.enable) + (lib.attrValues config.accounts.email.accounts); nonGmailAccounts = - map (a: a.name) (filter (a: a.flavor != "gmail.com") lieerAccounts); + map (a: a.name) (lib.filter (a: a.flavor != "gmail.com") lieerAccounts); nonGmailConfigHelp = map (name: ''accounts.email.accounts.${name}.flavor = "gmail.com";'') nonGmailAccounts; missingNotmuchAccounts = map (a: a.name) - (filter (a: !a.notmuch.enable && a.lieer.notmuchSetupWarning) + (lib.filter (a: !a.notmuch.enable && a.lieer.notmuchSetupWarning) lieerAccounts); notmuchConfigHelp = @@ -121,7 +120,7 @@ let }; syncOpts = { - enable = mkEnableOption "lieer synchronization service"; + enable = lib.mkEnableOption "lieer synchronization service"; frequency = mkOption { type = types.str; @@ -138,7 +137,7 @@ let }; lieerOpts = { - enable = mkEnableOption "lieer Gmail synchronization for notmuch"; + enable = lib.mkEnableOption "lieer Gmail synchronization for notmuch"; notmuchSetupWarning = mkOption { type = types.bool; @@ -210,28 +209,12 @@ let }; }; }; - - renamedOptions = account: - let prefix = [ "accounts" "email" "accounts" account.name "lieer" ]; - in [ - (mkRenamedOptionModule (prefix ++ [ "dropNonExistingLabels" ]) - (prefix ++ [ "settings" "drop_non_existing_label" ])) - (mkRenamedOptionModule (prefix ++ [ "ignoreTagsRemote" ]) - (prefix ++ [ "settings" "ignore_remote_labels" ])) - (mkRenamedOptionModule (prefix ++ [ "ignoreTagsLocal" ]) - (prefix ++ [ "settings" "ignore_tags" ])) - (mkRenamedOptionModule (prefix ++ [ "timeout" ]) - (prefix ++ [ "settings" "timeout" ])) - (mkRenamedOptionModule (prefix ++ [ "replaceSlashWithDot" ]) - (prefix ++ [ "settings" "replace_slash_with_dot" ])) - ]; - in { - meta.maintainers = [ maintainers.tadfisher ]; + meta.maintainers = [ lib.maintainers.tadfisher ]; options = { programs.lieer = { - enable = mkEnableOption "lieer Gmail synchronization for notmuch"; + enable = lib.mkEnableOption "lieer Gmail synchronization for notmuch"; package = mkOption { type = types.package; @@ -247,7 +230,7 @@ in { mkOption { type = with types; attrsOf lieerModule; }; }; - config = mkIf cfg.enable (mkMerge [ + config = mkIf cfg.enable (lib.mkMerge [ (mkIf (missingNotmuchAccounts != [ ]) { warnings = ['' lieer is enabled for the following email accounts, but notmuch is not: @@ -280,14 +263,14 @@ in { ''; }]; - warnings = flatten (map (account: account.warnings) lieerAccounts); + warnings = lib.flatten (map (account: account.warnings) lieerAccounts); home.packages = [ cfg.package ]; # Notmuch should ignore non-mail files created by lieer. programs.notmuch.new.ignore = [ "/.*[.](json|lock|bak)$/" ]; - home.file = listToAttrs (map configFile lieerAccounts); + home.file = lib.listToAttrs (map configFile lieerAccounts); } ]); } diff --git a/modules/programs/looking-glass-client.nix b/modules/programs/looking-glass-client.nix index c1780244..0dcaaf5e 100644 --- a/modules/programs/looking-glass-client.nix +++ b/modules/programs/looking-glass-client.nix @@ -1,23 +1,21 @@ { config, lib, pkgs, ... }: - -with lib; - let cfg = config.programs.looking-glass-client; settingsFormat = pkgs.formats.ini { }; in { - meta.maintainers = with maintainers; [ j-brn ]; + meta.maintainers = with lib.maintainers; [ j-brn ]; options.programs.looking-glass-client = { - enable = mkEnableOption "looking-glass-client"; + enable = lib.mkEnableOption "looking-glass-client"; - package = mkPackageOption pkgs "looking-glass-client" { nullable = true; }; + package = + lib.mkPackageOption pkgs "looking-glass-client" { nullable = true; }; - settings = mkOption { + settings = lib.mkOption { type = settingsFormat.type; default = { }; description = "looking-glass-client settings."; - example = literalExpression '' + example = lib.literalExpression '' { app = { allowDMA = true; @@ -44,17 +42,16 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ - (hm.assertions.assertPlatform "programs.looking-glass-client" pkgs - platforms.linux) + (lib.hm.assertions.assertPlatform "programs.looking-glass-client" pkgs + lib.platforms.linux) ]; home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; - xdg.configFile."looking-glass/client.ini" = mkIf (cfg.settings != { }) { - source = - settingsFormat.generate ("looking-glass-client.ini") cfg.settings; + xdg.configFile."looking-glass/client.ini" = lib.mkIf (cfg.settings != { }) { + source = settingsFormat.generate "looking-glass-client.ini" cfg.settings; }; }; } diff --git a/modules/programs/man.nix b/modules/programs/man.nix index 2de4bcc6..edc9b56a 100644 --- a/modules/programs/man.nix +++ b/modules/programs/man.nix @@ -1,8 +1,7 @@ { config, lib, pkgs, ... }: - -with lib; - -let cfg = config.programs.man; +let + inherit (lib) mkOption types; + cfg = config.programs.man; in { options = { programs.man = { @@ -19,7 +18,7 @@ in { package = mkOption { type = types.package; default = pkgs.man; - defaultText = literalExpression "pkgs.man"; + defaultText = lib.literalExpression "pkgs.man"; description = "The man package to use."; }; @@ -40,12 +39,12 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; home.extraOutputsToInstall = [ "man" ]; # This is mostly copy/pasted/adapted from NixOS' documentation.nix. - home.file = mkIf cfg.generateCaches { + home.file = lib.mkIf cfg.generateCaches { ".manpath".text = let # Generate a directory containing installed packages' manpages. manualPages = pkgs.buildEnv { diff --git a/modules/programs/mangohud.nix b/modules/programs/mangohud.nix index 61b05666..aa564842 100644 --- a/modules/programs/mangohud.nix +++ b/modules/programs/mangohud.nix @@ -1,8 +1,7 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkIf mkOption types; + cfg = config.programs.mangohud; settingsType = with types; @@ -15,18 +14,20 @@ let path = int; bool = "0"; # "on/off" opts are disabled with `=0` string = option; - list = concatStringsSep "," (lists.forEach option (x: toString x)); + list = + lib.concatStringsSep "," (lib.lists.forEach option (x: toString x)); }.${builtins.typeOf option}; - renderLine = k: v: (if isBool v && v then k else "${k}=${renderOption v}"); + renderLine = k: v: + (if lib.isBool v && v then k else "${k}=${renderOption v}"); renderSettings = attrs: - strings.concatStringsSep "\n" (attrsets.mapAttrsToList renderLine attrs) - + "\n"; + lib.strings.concatStringsSep "\n" + (lib.attrsets.mapAttrsToList renderLine attrs) + "\n"; in { options = { programs.mangohud = { - enable = mkEnableOption "Mangohud"; + enable = lib.mkEnableOption "Mangohud"; package = lib.mkPackageOption pkgs "mangohud" { }; @@ -42,7 +43,7 @@ in { settings = mkOption { type = with types; attrsOf settingsType; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { output_folder = ~/Documents/mangohud/; full = true; @@ -59,7 +60,7 @@ in { settingsPerApplication = mkOption { type = with types; attrsOf (attrsOf settingsType); default = { }; - example = literalExpression '' + example = lib.literalExpression '' { mpv = { no_display = true; @@ -79,7 +80,8 @@ in { config = mkIf cfg.enable { assertions = [ - (hm.assertions.assertPlatform "programs.mangohud" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "programs.mangohud" pkgs + lib.platforms.linux) ]; home.packages = [ cfg.package ]; @@ -92,10 +94,10 @@ in { xdg.configFile = { "MangoHud/MangoHud.conf" = mkIf (cfg.settings != { }) { text = renderSettings cfg.settings; }; - } // mapAttrs' - (n: v: nameValuePair "MangoHud/${n}.conf" { text = renderSettings v; }) + } // lib.mapAttrs' (n: v: + lib.nameValuePair "MangoHud/${n}.conf" { text = renderSettings v; }) cfg.settingsPerApplication; }; - meta.maintainers = with maintainers; [ zeratax ]; + meta.maintainers = with lib.maintainers; [ zeratax ]; } diff --git a/modules/programs/matplotlib.nix b/modules/programs/matplotlib.nix index cde6f39f..bc240138 100644 --- a/modules/programs/matplotlib.nix +++ b/modules/programs/matplotlib.nix @@ -1,25 +1,23 @@ { config, lib, ... }: - -with lib; - let + inherit (lib) mkIf mkOption types; cfg = config.programs.matplotlib; formatLine = o: n: v: let formatValue = v: - if isBool v then (if v then "True" else "False") else toString v; - in if isAttrs v then - concatStringsSep "\n" (mapAttrsToList (formatLine "${o}${n}.") v) + if lib.isBool v then (if v then "True" else "False") else toString v; + in if lib.isAttrs v then + lib.concatStringsSep "\n" (lib.mapAttrsToList (formatLine "${o}${n}.") v) else (if v == "" then "" else "${o}${n}: ${formatValue v}"); in { - meta.maintainers = [ maintainers.rprospero ]; + meta.maintainers = [ lib.maintainers.rprospero ]; options.programs.matplotlib = { - enable = mkEnableOption "matplotlib, a plotting library for python"; + enable = lib.mkEnableOption "matplotlib, a plotting library for python"; config = mkOption { default = { }; @@ -28,7 +26,7 @@ in { Add terms to the {file}`matplotlibrc` file to control the default matplotlib behavior. ''; - example = literalExpression '' + example = lib.literalExpression '' { backend = "Qt5Agg"; axes = { @@ -52,8 +50,8 @@ in { }; config = mkIf cfg.enable { - xdg.configFile."matplotlib/matplotlibrc".text = concatStringsSep "\n" ([ ] - ++ mapAttrsToList (formatLine "") cfg.config - ++ optional (cfg.extraConfig != "") cfg.extraConfig) + "\n"; + xdg.configFile."matplotlib/matplotlibrc".text = lib.concatStringsSep "\n" + ([ ] ++ lib.mapAttrsToList (formatLine "") cfg.config + ++ lib.optional (cfg.extraConfig != "") cfg.extraConfig) + "\n"; }; } diff --git a/modules/programs/mbsync-accounts.nix b/modules/programs/mbsync-accounts.nix index 8dc03b12..36c2653d 100644 --- a/modules/programs/mbsync-accounts.nix +++ b/modules/programs/mbsync-accounts.nix @@ -1,8 +1,6 @@ -{ config, lib, ... }: - -with lib; - +{ lib, ... }: let + inherit (lib) literalExpression mkOption types; extraConfigType = with lib.types; attrsOf (oneOf [ str int bool (listOf str) ]); @@ -113,7 +111,7 @@ let in { options.mbsync = { - enable = mkEnableOption "synchronization using mbsync"; + enable = lib.mkEnableOption "synchronization using mbsync"; flatten = mkOption { type = types.nullOr types.str; diff --git a/modules/programs/mbsync.nix b/modules/programs/mbsync.nix index f9dffd2f..274f1f26 100644 --- a/modules/programs/mbsync.nix +++ b/modules/programs/mbsync.nix @@ -1,19 +1,19 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) + any concatStringsSep concatMapStringsSep literalExpression mapAttrsToList + mkIf mkOption optionalAttrs types; cfg = config.programs.mbsync; # Accounts for which mbsync is enabled. - mbsyncAccounts = - filter (a: a.mbsync.enable) (attrValues config.accounts.email.accounts); + mbsyncAccounts = lib.filter (a: a.mbsync.enable) + (lib.attrValues config.accounts.email.accounts); # Given a SINGLE group's channels attribute set, return true if ANY of the channel's # patterns use the invalidOption attribute set value name. channelInvalidOption = channels: invalidOption: - any (c: c) (mapAttrsToList (c: hasAttr invalidOption) channels); + any (c: c) (mapAttrsToList (c: lib.hasAttr invalidOption) channels); # Given a SINGLE account's groups attribute set, return true if ANY of the account's group's channel's patterns use the invalidOption attribute set value name. groupInvalidOption = groups: invalidOption: @@ -36,18 +36,10 @@ let "STARTTLS" else "IMAPS"; - } // optionalAttrs (tls.enable && tls.certificatesFile != null) { + } // lib.optionalAttrs (tls.enable && tls.certificatesFile != null) { CertificateFile = toString tls.certificatesFile; }; - imports = [ - (mkRenamedOptionModule [ "programs" "mbsync" "masterSlaveMapping" ] [ - "programs" - "mbsync" - "nearFarMapping" - ]) - ]; - nearFarMapping = { none = "None"; imap = "Far"; @@ -57,18 +49,18 @@ let genSection = header: entries: let - escapeValue = escape [ ''"'' ]; + escapeValue = lib.escape [ ''"'' ]; hasSpace = v: builtins.match ".* .*" v != null; genValue = n: v: - if isList v then + if lib.isList v then concatMapStringsSep " " (genValue n) v - else if isBool v then + else if lib.isBool v then lib.hm.booleans.yesNo v - else if isInt v then + else if lib.isInt v then toString v - else if isString v && hasSpace v then + else if lib.isString v && hasSpace v then ''"${escapeValue v}"'' - else if isString v then + else if lib.isString v then v else let prettyV = lib.generators.toPretty { } v; @@ -80,8 +72,8 @@ let ''; genAccountConfig = account: - with account; - genSection "IMAPAccount ${name}" ({ + let inherit (account) name maildir imap mbsync passwordCommand userName; + in genSection "IMAPAccount ${name}" ({ Host = imap.host; User = userName; PassCmd = toString passwordCommand; @@ -91,7 +83,7 @@ let + genSection "IMAPStore ${name}-remote" ({ Account = name; } // mbsync.extraConfig.remote) + "\n" + genSection "MaildirStore ${name}-local" ({ - Inbox = "${maildir.absPath}/${folders.inbox}"; + Inbox = "${maildir.absPath}/${account.folders.inbox}"; } // optionalAttrs (mbsync.subFolders != "Maildir++" || mbsync.flatten != null) { Path = "${maildir.absPath}/"; @@ -101,8 +93,8 @@ let // mbsync.extraConfig.local) + "\n" + genChannels account; genChannels = account: - with account; - if mbsync.groups == { } then + let inherit (account) name mbsync; + in if mbsync.groups == { } then genAccountWideChannel account else genGroupChannelConfig name mbsync.groups + "\n" @@ -112,8 +104,8 @@ let # single channel for the entire account that is then further refined within # the Group for synchronization. genAccountWideChannel = account: - with account; - genSection "Channel ${name}" ({ + let inherit (account) name mbsync; + in genSection "Channel ${name}" ({ Far = ":${name}-remote:"; Near = ":${name}-local:"; Patterns = mbsync.patterns; @@ -132,12 +124,12 @@ let # itself, generate the string for the desired configuration. genChannelString = groupName: channel: let - escapeValue = escape [ ''\"'' ]; + escapeValue = lib.escape [ ''\"'' ]; hasSpace = v: builtins.match ".* .*" v != null; # Given a list of patterns, will return the string requested. # Only prints if the pattern is NOT the empty list, the default. genChannelPatterns = patterns: - if (length patterns) != 0 then + if (lib.length patterns) != 0 then "Pattern " + concatStringsSep " " (map (pat: if hasSpace pat then escapeValue pat else pat) patterns) + "\n" @@ -150,7 +142,7 @@ let # Given the group name, and a attr set of channels within that group, # Generate a list of strings for each channels' configuration. genChannelStrings = groupName: channels: - optionals (channels != { }) + lib.optionals (channels != { }) (mapAttrsToList (channelName: info: genChannelString groupName info) channels); # Given a group, return a string that configures all the channels within @@ -158,8 +150,8 @@ let genGroupsChannels = group: concatStringsSep "\n" (genChannelStrings group.name group.channels); # Generate all channel configurations for all groups for this account. - in concatStringsSep "\n" - (remove "" (mapAttrsToList (name: group: genGroupsChannels group) groups)); + in concatStringsSep "\n" (lib.remove "" + (mapAttrsToList (name: group: genGroupsChannels group) groups)); # Given the attr set of groups, return a string which maps channels to groups genAccountGroups = groups: @@ -171,14 +163,16 @@ let # Take in 1 group, if the group has channels specified, construct the # "Group " header and each of the channels. genGroupChannelString = group: - flatten (optionals (group.channels != { }) ([ "Group ${group.name}" ] - ++ (genChannelStrings group.name group.channels))); + lib.flatten (lib.optionals (group.channels != { }) + ([ "Group ${group.name}" ] + ++ (genChannelStrings group.name group.channels))); # Given set of groups, generates list of strings, where each string is one # of the groups and its constituent channels. genGroupsStrings = mapAttrsToList (name: info: concatStringsSep "\n" (genGroupChannelString groups.${name})) groups; # Join all non-empty groups. - combined = concatStringsSep "\n\n" (remove "" genGroupsStrings) + "\n"; + combined = concatStringsSep "\n\n" (lib.remove "" genGroupsStrings) + + "\n"; in combined; genGroupConfig = name: channels: @@ -188,11 +182,12 @@ let ([ "Group ${name}" ] ++ mapAttrsToList genGroupChannel channels); in { - meta.maintainers = [ maintainers.KarlJoad ]; + meta.maintainers = [ lib.maintainers.KarlJoad ]; options = { programs.mbsync = { - enable = mkEnableOption "mbsync IMAP4 and Maildir mailbox synchronizer"; + enable = + lib.mkEnableOption "mbsync IMAP4 and Maildir mailbox synchronizer"; package = mkOption { type = types.package; @@ -232,11 +227,11 @@ in { }; }; - config = mkIf cfg.enable (mkMerge [ + config = mkIf cfg.enable (lib.mkMerge [ { assertions = let checkAccounts = pred: msg: - let badAccounts = filter pred mbsyncAccounts; + let badAccounts = lib.filter pred mbsyncAccounts; in { assertion = badAccounts == [ ]; message = "mbsync: ${msg} for accounts: " @@ -279,16 +274,16 @@ in { in '' # Generated by Home Manager. - '' - + concatStringsSep "\n" (optional (cfg.extraConfig != "") cfg.extraConfig) + '' + concatStringsSep "\n" + (lib.optional (cfg.extraConfig != "") cfg.extraConfig) + concatStringsSep "\n\n" accountsConfig + concatStringsSep "\n" groupsConfig; home.activation = mkIf (mbsyncAccounts != [ ]) { createMaildir = - hm.dag.entryBetween [ "linkGeneration" ] [ "writeBoundary" ] '' + lib.hm.dag.entryBetween [ "linkGeneration" ] [ "writeBoundary" ] '' run mkdir -m700 -p $VERBOSE_ARG ${ - concatMapStringsSep " " (a: escapeShellArg a.maildir.absPath) + concatMapStringsSep " " (a: lib.escapeShellArg a.maildir.absPath) mbsyncAccounts } ''; diff --git a/modules/programs/mcfly.nix b/modules/programs/mcfly.nix index 4ff43e5a..7f464cd9 100644 --- a/modules/programs/mcfly.nix +++ b/modules/programs/mcfly.nix @@ -1,7 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; let + inherit (lib) getExe optionalString mkIf mkOption types; cfg = config.programs.mcfly; @@ -38,23 +37,23 @@ in { meta.maintainers = [ ]; imports = [ - (mkChangedOptionModule # \ + (lib.mkChangedOptionModule # \ [ "programs" "mcfly" "enableFuzzySearch" ] # \ [ "programs" "mcfly" "fuzzySearchFactor" ] # \ (config: let - value = - getAttrFromPath [ "programs" "mcfly" "enableFuzzySearch" ] config; + value = lib.getAttrFromPath [ "programs" "mcfly" "enableFuzzySearch" ] + config; in if value then 2 else 0)) ]; options.programs.mcfly = { - enable = mkEnableOption "mcfly"; + enable = lib.mkEnableOption "mcfly"; settings = mkOption { type = tomlFormat.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { colors = { menubar = { @@ -98,7 +97,7 @@ in { ''; }; - fzf.enable = mkEnableOption "McFly fzf integration"; + fzf.enable = lib.mkEnableOption "McFly fzf integration"; enableLightTheme = mkOption { default = false; @@ -128,9 +127,10 @@ in { lib.hm.shell.mkZshIntegrationOption { inherit config; }; }; - config = mkIf cfg.enable (mkMerge [ + config = mkIf cfg.enable (lib.mkMerge [ { - home.packages = [ pkgs.mcfly ] ++ optional cfg.fzf.enable pkgs.mcfly-fzf; + home.packages = [ pkgs.mcfly ] + ++ lib.optional cfg.fzf.enable pkgs.mcfly-fzf; # Oddly enough, McFly expects this in the data path, not in config. xdg.dataFile."mcfly/config.toml" = mkIf (cfg.settings != { }) { diff --git a/modules/programs/mercurial.nix b/modules/programs/mercurial.nix index 6b6df21a..6e85f9d3 100644 --- a/modules/programs/mercurial.nix +++ b/modules/programs/mercurial.nix @@ -1,8 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkIf mkOption types; cfg = config.programs.mercurial; @@ -12,7 +10,7 @@ in { options = { programs.mercurial = { - enable = mkEnableOption "Mercurial"; + enable = lib.mkEnableOption "Mercurial"; package = lib.mkPackageOption pkgs "mercurial" { }; @@ -60,7 +58,7 @@ in { }; }; - config = mkIf cfg.enable (mkMerge [ + config = mkIf cfg.enable (lib.mkMerge [ { home.packages = [ cfg.package ]; @@ -78,9 +76,9 @@ in { xdg.configFile."hg/hgignore_global".text = '' syntax: glob - '' + concatStringsSep "\n" cfg.ignores + "\n" + '' + '' + lib.concatStringsSep "\n" cfg.ignores + "\n" + '' syntax: regexp - '' + concatStringsSep "\n" cfg.ignoresRegexp + "\n"; + '' + lib.concatStringsSep "\n" cfg.ignoresRegexp + "\n"; }) (mkIf (cfg.aliases != { }) { diff --git a/modules/programs/micro.nix b/modules/programs/micro.nix index acd76867..2d8330e2 100644 --- a/modules/programs/micro.nix +++ b/modules/programs/micro.nix @@ -1,26 +1,21 @@ { config, lib, pkgs, ... }: - -with lib; - let - cfg = config.programs.micro; jsonFormat = pkgs.formats.json { }; - in { - meta.maintainers = [ hm.maintainers.mforster ]; + meta.maintainers = [ lib.hm.maintainers.mforster ]; options = { programs.micro = { - enable = mkEnableOption "micro, a terminal-based text editor"; + enable = lib.mkEnableOption "micro, a terminal-based text editor"; - package = mkPackageOption pkgs "micro" { nullable = true; }; + package = lib.mkPackageOption pkgs "micro" { nullable = true; }; - settings = mkOption { + settings = lib.mkOption { type = jsonFormat.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { autosu = false; cursorline = false; @@ -36,7 +31,7 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; xdg.configFile."micro/settings.json".source = diff --git a/modules/programs/mise.nix b/modules/programs/mise.nix index f4bbcade..84ef1958 100644 --- a/modules/programs/mise.nix +++ b/modules/programs/mise.nix @@ -1,16 +1,14 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) getExe mkIf mkOption; cfg = config.programs.mise; tomlFormat = pkgs.formats.toml { }; in { - meta.maintainers = [ hm.maintainers.pedorich-n ]; + meta.maintainers = [ lib.hm.maintainers.pedorich-n ]; imports = let mkRemovedWarning = opt: - (mkRemovedOptionModule [ "programs" "rtx" opt ] '' + (lib.mkRemovedOptionModule [ "programs" "rtx" opt ] '' The `rtx` package has been replaced by `mise`, please switch over to using the options under `programs.mise.*` instead. ''); @@ -27,9 +25,9 @@ in { options = { programs.mise = { - enable = mkEnableOption "mise"; + enable = lib.mkEnableOption "mise"; - package = mkPackageOption pkgs "mise" { nullable = true; }; + package = lib.mkPackageOption pkgs "mise" { nullable = true; }; enableBashIntegration = lib.hm.shell.mkBashIntegrationOption { inherit config; }; @@ -46,7 +44,7 @@ in { globalConfig = mkOption { type = tomlFormat.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' tools = { node = "lts"; python = ["3.10" "3.11"]; @@ -67,7 +65,7 @@ in { settings = mkOption { type = tomlFormat.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' verbose = false; experimental = false; disable_tools = ["node"]; @@ -83,7 +81,7 @@ in { }; config = mkIf cfg.enable { - warnings = optional (cfg.package == null && (cfg.enableBashIntegration + warnings = lib.optional (cfg.package == null && (cfg.enableBashIntegration || cfg.enableZshIntegration || cfg.enableFishIntegration || cfg.enableNushellIntegration)) '' You have enabled shell integration for `mise` but have not set `package`. diff --git a/modules/programs/mods.nix b/modules/programs/mods.nix index f20f36a6..fdc2c6e8 100644 --- a/modules/programs/mods.nix +++ b/modules/programs/mods.nix @@ -1,18 +1,18 @@ { config, lib, pkgs, ... }: - -with lib; let + inherit (lib) mkIf mkOrder; + cfg = config.programs.mods; yamlFormat = pkgs.formats.yaml { }; in { - meta.maintainers = [ hm.maintainers.ipsavitsky ]; + meta.maintainers = [ lib.hm.maintainers.ipsavitsky ]; options.programs.mods = { - enable = mkEnableOption "mods"; + enable = lib.mkEnableOption "mods"; package = lib.mkPackageOption pkgs "mods" { }; - settings = mkOption { + settings = lib.mkOption { type = yamlFormat.type; default = { }; example = '' diff --git a/modules/programs/mpv.nix b/modules/programs/mpv.nix index b6220876..332a3f9d 100644 --- a/modules/programs/mpv.nix +++ b/modules/programs/mpv.nix @@ -1,8 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) generators literalExpression mkIf mkOption types; inherit (builtins) typeOf stringLength; cfg = config.programs.mpv; @@ -47,11 +45,11 @@ let }; renderBindings = bindings: - concatStringsSep "\n" - (mapAttrsToList (name: value: "${name} ${value}") bindings); + lib.concatStringsSep "\n" + (lib.mapAttrsToList (name: value: "${name} ${value}") bindings); renderDefaultProfiles = profiles: - renderOptions { profile = concatStringsSep "," profiles; }; + renderOptions { profile = lib.concatStringsSep "," profiles; }; mpvPackage = if cfg.scripts == [ ] then cfg.package @@ -61,7 +59,7 @@ let in { options = { programs.mpv = { - enable = mkEnableOption "mpv"; + enable = lib.mkEnableOption "mpv"; package = mkOption { type = types.package; @@ -206,7 +204,7 @@ in { }; }; - config = mkIf cfg.enable (mkMerge [ + config = mkIf cfg.enable (lib.mkMerge [ { assertions = [{ assertion = (cfg.scripts == [ ]) || (cfg.package == pkgs.mpv); @@ -222,31 +220,32 @@ in { (mkIf (cfg.includes != [ ]) { xdg.configFile."mpv/mpv.conf" = { text = lib.mkAfter - (concatMapStringsSep "\n" (x: "include=${x}") cfg.includes); + (lib.concatMapStringsSep "\n" (x: "include=${x}") cfg.includes); }; }) (mkIf (cfg.config != { } || cfg.profiles != { }) { xdg.configFile."mpv/mpv.conf".text = '' - ${optionalString (cfg.defaultProfiles != [ ]) + ${lib.optionalString (cfg.defaultProfiles != [ ]) (renderDefaultProfiles cfg.defaultProfiles)} - ${optionalString (cfg.config != { }) (renderOptions cfg.config)} - ${optionalString (cfg.profiles != { }) (renderProfiles cfg.profiles)} + ${lib.optionalString (cfg.config != { }) (renderOptions cfg.config)} + ${lib.optionalString (cfg.profiles != { }) + (renderProfiles cfg.profiles)} ''; }) (mkIf (cfg.bindings != { } || cfg.extraInput != "") { - xdg.configFile."mpv/input.conf".text = mkMerge [ + xdg.configFile."mpv/input.conf".text = lib.mkMerge [ (mkIf (cfg.bindings != { }) (renderBindings cfg.bindings)) (mkIf (cfg.extraInput != "") cfg.extraInput) ]; }) { - xdg.configFile = mapAttrs' (name: value: - nameValuePair "mpv/script-opts/${name}.conf" { + xdg.configFile = lib.mapAttrs' (name: value: + lib.nameValuePair "mpv/script-opts/${name}.conf" { text = renderScriptOptions value; }) cfg.scriptOpts; } ]); - meta.maintainers = with maintainers; [ thiagokokada chuangzhu ]; + meta.maintainers = with lib.maintainers; [ thiagokokada chuangzhu ]; } diff --git a/modules/programs/mr.nix b/modules/programs/mr.nix index 140aff32..78d4d361 100644 --- a/modules/programs/mr.nix +++ b/modules/programs/mr.nix @@ -1,25 +1,21 @@ { config, lib, pkgs, ... }: - -with lib; - let - cfg = config.programs.mr; - listToValue = concatMapStringsSep ", " (generators.mkValueStringDefault { }); + listToValue = + lib.concatMapStringsSep ", " (lib.generators.mkValueStringDefault { }); iniFormat = pkgs.formats.ini { inherit listToValue; }; - in { - meta.maintainers = [ hm.maintainers.nilp0inter ]; + meta.maintainers = [ lib.hm.maintainers.nilp0inter ]; options.programs.mr = { - enable = mkEnableOption + enable = lib.mkEnableOption "mr, a tool to manage all your version control repositories"; - package = mkPackageOption pkgs "mr" { nullable = true; }; + package = lib.mkPackageOption pkgs "mr" { nullable = true; }; - settings = mkOption { + settings = lib.mkOption { type = iniFormat.type; default = { }; description = '' @@ -27,7 +23,7 @@ in { See for an example configuration. ''; - example = literalExpression '' + example = lib.literalExpression '' { foo = { checkout = "git clone git@github.com:joeyh/foo.git"; @@ -41,7 +37,7 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; home.file.".mrconfig".source = iniFormat.generate ".mrconfig" cfg.settings; }; diff --git a/modules/programs/msmtp-accounts.nix b/modules/programs/msmtp-accounts.nix index 5e1158bf..734591bd 100644 --- a/modules/programs/msmtp-accounts.nix +++ b/modules/programs/msmtp-accounts.nix @@ -1,11 +1,7 @@ -{ config, lib, ... }: - -with lib; - -{ +{ lib, ... }: { options.msmtp = { - enable = mkOption { - type = types.bool; + enable = lib.mkOption { + type = lib.types.bool; default = false; description = '' Whether to enable msmtp. @@ -22,9 +18,9 @@ with lib; ''; }; - tls.fingerprint = mkOption { - type = - types.nullOr (types.strMatching "([[:alnum:]]{2}:)+[[:alnum:]]{2}"); + tls.fingerprint = lib.mkOption { + type = lib.types.nullOr + (lib.types.strMatching "([[:alnum:]]{2}:)+[[:alnum:]]{2}"); default = null; example = "my:SH:a2:56:ha:sh"; description = '' @@ -34,8 +30,8 @@ with lib; ''; }; - extraConfig = mkOption { - type = types.attrsOf types.str; + extraConfig = lib.mkOption { + type = lib.types.attrsOf lib.types.str; default = { }; example = { auth = "login"; }; description = '' diff --git a/modules/programs/msmtp.nix b/modules/programs/msmtp.nix index 33973aff..c9d195a7 100644 --- a/modules/programs/msmtp.nix +++ b/modules/programs/msmtp.nix @@ -1,13 +1,11 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; cfg = config.programs.msmtp; - msmtpAccounts = - filter (a: a.msmtp.enable) (attrValues config.accounts.email.accounts); + msmtpAccounts = lib.filter (a: a.msmtp.enable) + (lib.attrValues config.accounts.email.accounts); onOff = p: if p then "on" else "off"; @@ -40,7 +38,7 @@ let ${cfg.extraConfig} - ${concatStringsSep "\n\n" (map accountStr mailAccounts)} + ${lib.concatStringsSep "\n\n" (map accountStr mailAccounts)} ${cfg.extraAccounts} ''; @@ -49,12 +47,12 @@ in { options = { programs.msmtp = { - enable = mkEnableOption "msmtp"; + enable = lib.mkEnableOption "msmtp"; package = mkOption { type = types.package; default = pkgs.msmtp; - defaultText = literalExpression "pkgs.msmtp"; + defaultText = lib.literalExpression "pkgs.msmtp"; description = "The msmtp package to use."; }; @@ -87,7 +85,7 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; xdg.configFile."msmtp/config".text = configFile msmtpAccounts; diff --git a/modules/programs/mu.nix b/modules/programs/mu.nix index fdb85f85..04c7301f 100644 --- a/modules/programs/mu.nix +++ b/modules/programs/mu.nix @@ -1,9 +1,5 @@ { config, lib, pkgs, ... }: - -with lib; - let - cfg = config.programs.mu; # Used to generate command line arguments that mu can operate with. @@ -12,35 +8,35 @@ let # Sorted list of personal email addresses to register sortedAddresses = let # Set of email account sets where mu.enable = true. - muAccounts = - filter (a: a.mu.enable) (attrValues config.accounts.email.accounts); + muAccounts = lib.filter (a: a.mu.enable) + (lib.attrValues config.accounts.email.accounts); addrs = map (a: a.address) muAccounts; # Construct list of lists containing email aliases, and flatten aliases = map (alias: alias.address or alias) - (flatten (map (a: a.aliases) muAccounts)); + (lib.flatten (map (a: a.aliases) muAccounts)); # Sort the list - in sort lessThan (addrs ++ aliases); + in lib.sort lib.lessThan (addrs ++ aliases); # Takes the list of accounts with mu.enable = true, and generates a # command-line flag for initializing the mu database. myAddresses = let # Prefix --my-address= to each account's address and all defined aliases addMyAddress = map (addr: "--my-address=" + addr) sortedAddresses; - in concatStringsSep " " addMyAddress; + in lib.concatStringsSep " " addMyAddress; in { - meta.maintainers = [ maintainers.KarlJoad ]; + meta.maintainers = [ lib.maintainers.KarlJoad ]; options = { programs.mu = { - enable = mkEnableOption "mu, a maildir indexer and searcher"; + enable = lib.mkEnableOption "mu, a maildir indexer and searcher"; - package = mkPackageOption pkgs "mu" { }; + package = lib.mkPackageOption pkgs "mu" { }; - home = mkOption { - type = types.path; + home = lib.mkOption { + type = lib.types.path; default = config.xdg.cacheHome + "/mu"; - defaultText = literalExpression ''config.xdg.cacheHome + "/mu"''; + defaultText = lib.literalExpression ''config.xdg.cacheHome + "/mu"''; example = "\${config.home.homeDirectory}/Maildir/.mu"; description = '' Directory to store Mu's database. @@ -52,33 +48,33 @@ in { # information about this. }; - accounts.email.accounts = mkOption { - type = with types; - attrsOf - (submodule { options.mu.enable = mkEnableOption "mu indexing"; }); + accounts.email.accounts = lib.mkOption { + type = lib.types.attrsOf (lib.types.submodule { + options.mu.enable = lib.mkEnableOption "mu indexing"; + }); }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; home.sessionVariables.MUHOME = cfg.home; home.activation.runMuInit = let maildirOption = genCmdMaildir config.accounts.email.maildirBasePath; - muExe = getExe cfg.package; - gawkExe = getExe pkgs.gawk; - in hm.dag.entryAfter [ "writeBoundary" ] '' + muExe = lib.getExe cfg.package; + gawkExe = lib.getExe pkgs.gawk; + in lib.hm.dag.entryAfter [ "writeBoundary" ] '' # If the database directory exists and registered personal addresses remain the same, # then `mu init` should NOT be run. # In theory, mu is the only thing that creates that directory, and it is # only created during the initial index. MU_SORTED_ADDRS=$((${muExe} info store | ${gawkExe} '/personal-address/{print $4}' | LC_ALL=C sort | paste -sd ' ') || exit 0) if [[ ! -d "${cfg.home}" || ! "$MU_SORTED_ADDRS" = "${ - concatStringsSep " " sortedAddresses + lib.concatStringsSep " " sortedAddresses }" ]]; then run ${muExe} init ${maildirOption} --muhome "${ - escapeShellArg cfg.home + lib.escapeShellArg cfg.home }" ${myAddresses} $VERBOSE_ARG; fi ''; diff --git a/modules/programs/mujmap.nix b/modules/programs/mujmap.nix index a0e74ab0..98116ff1 100644 --- a/modules/programs/mujmap.nix +++ b/modules/programs/mujmap.nix @@ -1,15 +1,14 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; + cfg = config.programs.mujmap; - mujmapAccounts = - filter (a: a.mujmap.enable) (attrValues config.accounts.email.accounts); + mujmapAccounts = lib.filter (a: a.mujmap.enable) + (lib.attrValues config.accounts.email.accounts); missingNotmuchAccounts = map (a: a.name) - (filter (a: !a.notmuch.enable && a.mujmap.notmuchSetupWarning) + (lib.filter (a: !a.notmuch.enable && a.mujmap.notmuchSetupWarning) mujmapAccounts); notmuchConfigHelp = @@ -18,7 +17,7 @@ let settingsFormat = pkgs.formats.toml { }; - filterNull = attrs: attrsets.filterAttrs (n: v: v != null) attrs; + filterNull = attrs: lib.attrsets.filterAttrs (n: v: v != null) attrs; configFile = account: let @@ -32,10 +31,10 @@ let settings' = settings'' // { username = account.userName; - password_command = escapeShellArgs account.passwordCommand; + password_command = lib.escapeShellArgs account.passwordCommand; } // filterNull account.mujmap.settings; - settings = if (hasAttr "fqdn" settings') then + settings = if (lib.hasAttr "fqdn" settings') then (removeAttrs settings' [ "session_url" ]) else settings'; @@ -154,7 +153,7 @@ let password_command = mkOption { type = types.nullOr (types.either types.str (types.listOf types.str)); default = null; - apply = p: if isList p then escapeShellArgs p else p; + apply = p: if lib.isList p then lib.escapeShellArgs p else p; example = "pass alice@example.com"; description = '' Shell command which will print a password to stdout for basic HTTP @@ -232,7 +231,7 @@ let }; mujmapOpts = { - enable = mkEnableOption "mujmap JMAP synchronization for notmuch"; + enable = lib.mkEnableOption "mujmap JMAP synchronization for notmuch"; notmuchSetupWarning = mkOption { type = types.bool; @@ -263,11 +262,11 @@ let mujmapModule = types.submodule { options = { mujmap = mujmapOpts; }; }; in { - meta.maintainers = with maintainers; [ elizagamedev ]; + meta.maintainers = with lib.maintainers; [ elizagamedev ]; options = { programs.mujmap = { - enable = mkEnableOption "mujmap Gmail synchronization for notmuch"; + enable = lib.mkEnableOption "mujmap Gmail synchronization for notmuch"; package = mkOption { type = types.package; @@ -283,16 +282,16 @@ in { mkOption { type = with types; attrsOf mujmapModule; }; }; - config = mkIf cfg.enable (mkMerge [ - (mkIf (missingNotmuchAccounts != [ ]) { + config = lib.mkIf cfg.enable (lib.mkMerge [ + (lib.mkIf (missingNotmuchAccounts != [ ]) { warnings = ['' mujmap is enabled for the following email accounts, but notmuch is not: - ${concatStringsSep "\n " missingNotmuchAccounts} + ${lib.concatStringsSep "\n " missingNotmuchAccounts} Notmuch can be enabled with: - ${concatStringsSep "\n " notmuchConfigHelp} + ${lib.concatStringsSep "\n " notmuchConfigHelp} If you have configured notmuch outside of Home Manager, you can suppress this warning with: @@ -302,14 +301,14 @@ in { }) { - warnings = flatten (map (account: account.warnings) mujmapAccounts); + warnings = lib.flatten (map (account: account.warnings) mujmapAccounts); home.packages = [ cfg.package ]; # Notmuch should ignore non-mail files created by mujmap. programs.notmuch.new.ignore = [ "/.*[.](toml|json|lock)$/" ]; - home.file = listToAttrs (map configFile mujmapAccounts); + home.file = lib.listToAttrs (map configFile mujmapAccounts); } ]); } diff --git a/modules/programs/navi.nix b/modules/programs/navi.nix index 45c5003a..f804779d 100644 --- a/modules/programs/navi.nix +++ b/modules/programs/navi.nix @@ -1,7 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; let + inherit (lib) mkIf; cfg = config.programs.navi; @@ -16,19 +15,19 @@ in { meta.maintainers = [ ]; options.programs.navi = { - enable = mkEnableOption "Navi"; + enable = lib.mkEnableOption "Navi"; - package = mkOption { - type = types.package; + package = lib.mkOption { + type = lib.types.package; default = pkgs.navi; - defaultText = literalExpression "pkgs.navi"; + defaultText = lib.literalExpression "pkgs.navi"; description = "The package to use for the navi binary."; }; - settings = mkOption { + settings = lib.mkOption { type = yamlFormat.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { cheats = { paths = [ diff --git a/modules/programs/ncmpcpp.nix b/modules/programs/ncmpcpp.nix index d0f2c474..6d67337c 100644 --- a/modules/programs/ncmpcpp.nix +++ b/modules/programs/ncmpcpp.nix @@ -1,13 +1,11 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) concatStringsSep literalExpression mkIf mkOption types; cfg = config.programs.ncmpcpp; renderSettings = settings: - concatStringsSep "\n" (mapAttrsToList renderSetting settings); + concatStringsSep "\n" (lib.mapAttrsToList renderSetting settings); renderSetting = name: value: "${name}=${renderValue value}"; @@ -23,7 +21,7 @@ let renderBinding = { key, command }: concatStringsSep "\n " ([ ''def_key "${key}"'' ] ++ maybeWrapList command); - maybeWrapList = xs: if isList xs then xs else [ xs ]; + maybeWrapList = xs: if lib.isList xs then xs else [ xs ]; valueType = with types; oneOf [ bool int str ]; @@ -44,11 +42,11 @@ let }); in { - meta.maintainers = [ hm.maintainers.olmokramer ]; + meta.maintainers = [ lib.hm.maintainers.olmokramer ]; options.programs.ncmpcpp = { - enable = - mkEnableOption "ncmpcpp - an ncurses Music Player Daemon (MPD) client"; + enable = lib.mkEnableOption + "ncmpcpp - an ncurses Music Player Daemon (MPD) client"; package = mkOption { type = types.package; @@ -119,7 +117,7 @@ in { xdg.configFile = { "ncmpcpp/config" = let - settings = cfg.settings // optionalAttrs (cfg.mpdMusicDir != null) { + settings = cfg.settings // lib.optionalAttrs (cfg.mpdMusicDir != null) { mpd_music_dir = cfg.mpdMusicDir; }; in mkIf (settings != { }) { text = renderSettings settings + "\n"; }; diff --git a/modules/programs/ncspot.nix b/modules/programs/ncspot.nix index c3fe37a2..29eb92df 100644 --- a/modules/programs/ncspot.nix +++ b/modules/programs/ncspot.nix @@ -1,30 +1,25 @@ { config, lib, pkgs, ... }: - -with lib; - let - cfg = config.programs.ncspot; tomlFormat = pkgs.formats.toml { }; - in { meta.maintainers = [ ]; options.programs.ncspot = { - enable = mkEnableOption "ncspot"; + enable = lib.mkEnableOption "ncspot"; - package = mkOption { - type = types.package; + package = lib.mkOption { + type = lib.types.package; default = pkgs.ncspot; - defaultText = literalExpression "pkgs.ncspot"; + defaultText = lib.literalExpression "pkgs.ncspot"; description = "The package to use for ncspot."; }; - settings = mkOption { + settings = lib.mkOption { type = tomlFormat.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { shuffle = true; gapless = true; @@ -40,10 +35,10 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; - xdg.configFile."ncspot/config.toml" = mkIf (cfg.settings != { }) { + xdg.configFile."ncspot/config.toml" = lib.mkIf (cfg.settings != { }) { source = tomlFormat.generate "ncspot-config" cfg.settings; }; }; diff --git a/modules/programs/ne.nix b/modules/programs/ne.nix index 3b030312..b938dd80 100644 --- a/modules/programs/ne.nix +++ b/modules/programs/ne.nix @@ -1,28 +1,26 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkIf mkOption types; cfg = config.programs.ne; autoPrefFiles = let autoprefs = cfg.automaticPreferences - // optionalAttrs (cfg.defaultPreferences != "") { + // lib.optionalAttrs (cfg.defaultPreferences != "") { ".default" = cfg.defaultPreferences; }; gen = fileExtension: configText: - nameValuePair ".ne/${fileExtension}#ap" { + lib.nameValuePair ".ne/${fileExtension}#ap" { text = configText; }; # Generates [path].text format expected by home.file. - in mapAttrs' gen autoprefs; + in lib.mapAttrs' gen autoprefs; in { - meta.maintainers = [ hm.maintainers.cwyc ]; + meta.maintainers = [ lib.hm.maintainers.cwyc ]; options.programs.ne = { - enable = mkEnableOption "ne"; + enable = lib.mkEnableOption "ne"; keybindings = mkOption { type = types.lines; @@ -49,7 +47,7 @@ in { automaticPreferences = mkOption { type = types.attrsOf types.lines; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { nix = ''' TAB 0 diff --git a/modules/programs/neomutt-accounts.nix b/modules/programs/neomutt-accounts.nix index bdeda863..fa36ab37 100644 --- a/modules/programs/neomutt-accounts.nix +++ b/modules/programs/neomutt-accounts.nix @@ -1,8 +1,7 @@ { config, lib, ... }: - -with lib; - let + inherit (lib) mkOption types; + extraMailboxOptions = { options = { mailbox = mkOption { @@ -30,7 +29,9 @@ let in { options.notmuch.neomutt = { - enable = mkEnableOption "Notmuch support in NeoMutt" // { default = true; }; + enable = lib.mkEnableOption "Notmuch support in NeoMutt" // { + default = true; + }; virtualMailboxes = mkOption { type = types.listOf (types.submodule ./notmuch-virtual-mailbox.nix); @@ -47,7 +48,7 @@ in { }; options.neomutt = { - enable = mkEnableOption "NeoMutt"; + enable = lib.mkEnableOption "NeoMutt"; sendMailCommand = mkOption { type = types.nullOr types.str; @@ -55,7 +56,7 @@ in { "msmtpq --read-envelope-from --read-recipients" else null; - defaultText = literalExpression '' + defaultText = lib.literalExpression '' if config.msmtp.enable then "msmtpq --read-envelope-from --read-recipients" else diff --git a/modules/programs/neomutt.nix b/modules/programs/neomutt.nix index 8ef1a45c..7abbe495 100644 --- a/modules/programs/neomutt.nix +++ b/modules/programs/neomutt.nix @@ -1,17 +1,18 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) + attrValues concatStringsSep concatMapStringsSep filter isString mkIf + mkOption optionalString types; + cfg = config.programs.neomutt; neomuttAccounts = filter (a: a.neomutt.enable) (attrValues config.accounts.email.accounts); - accountCommandNeeded = any (a: + accountCommandNeeded = lib.any (a: a.neomutt.enable && (a.neomutt.mailboxType == "imap" - || (any (m: !isString m && m.type == "imap") a.neomutt.extraMailboxes))) - (attrValues config.accounts.email.accounts); + || (lib.any (m: !isString m && m.type == "imap") + a.neomutt.extraMailboxes))) (attrValues config.accounts.email.accounts); accountCommand = let imapAccounts = filter (a: @@ -63,7 +64,7 @@ let sidebarModule = types.submodule { options = { - enable = mkEnableOption "sidebar support"; + enable = lib.mkEnableOption "sidebar support"; width = mkOption { type = types.int; @@ -154,7 +155,7 @@ let virtualMailboxes)}"; setOption = n: v: if v == null then "unset ${n}" else "set ${n}=${v}"; - escape = replaceStrings [ "%" ] [ "%25" ]; + escape = lib.replaceStrings [ "%" ] [ "%25" ]; accountFilename = account: config.xdg.configHome + "/neomutt/" + account.name; @@ -201,10 +202,9 @@ let }; genAccountConfig = account: - with account; let - folderHook = mapAttrsToList setOption (genCommonFolderHooks account - // optionalAttrs cfg.changeFolderWhenSourcingAccount { + folderHook = lib.mapAttrsToList setOption (genCommonFolderHooks account + // lib.optionalAttrs cfg.changeFolderWhenSourcingAccount { folder = "'${accountRoot account}'"; }); in '' @@ -237,10 +237,9 @@ let else ''named-mailboxes "${extra.name}" "${mailboxroot}/${extra.mailbox}"'') account.neomutt.extraMailboxes; - in with account; - [ "## register account ${name}" ] - ++ optional account.neomutt.showDefaultMailbox - ''${mailboxes} "${mailroot}/${folders.inbox}"'' ++ [ + in [ "## register account ${account.name}" ] + ++ lib.optional account.neomutt.showDefaultMailbox + ''${mailboxes} "${mailroot}/${account.folders.inbox}"'' ++ [ extraMailboxes '' ${hookName} ${mailroot}/ " \ @@ -249,13 +248,13 @@ let ]; mraSection = account: - with account; if account.imap.host != null || account.maildir != null then genAccountConfig account else throw "Only maildir and IMAP is supported at the moment"; - optionsStr = attrs: concatStringsSep "\n" (mapAttrsToList setOption attrs); + optionsStr = attrs: + concatStringsSep "\n" (lib.mapAttrsToList setOption attrs); sidebarSection = '' # Sidebar @@ -269,7 +268,7 @@ let concatMapStringsSep "\n" (bind: '' ${bindType} ${ - concatStringsSep "," (toList bind.map) + concatStringsSep "," (lib.toList bind.map) } ${bind.key} "${bind.action}"''); bindSection = (genBindMapper "bind") cfg.binds; @@ -283,11 +282,11 @@ let notmuchSection = account: let virtualMailboxes = account.notmuch.neomutt.virtualMailboxes; - in with account; '' + in '' # notmuch section set nm_default_uri = "notmuch://${config.accounts.email.maildirBasePath}" ${optionalString - (notmuch.neomutt.enable && builtins.length virtualMailboxes > 0) + (account.notmuch.neomutt.enable && builtins.length virtualMailboxes > 0) (mkNotmuchVirtualboxes virtualMailboxes)} ''; @@ -341,12 +340,12 @@ let in { options = { programs.neomutt = { - enable = mkEnableOption "the NeoMutt mail client"; + enable = lib.mkEnableOption "the NeoMutt mail client"; package = mkOption { type = types.package; default = pkgs.neomutt; - defaultText = literalExpression "pkgs.neomutt"; + defaultText = lib.literalExpression "pkgs.neomutt"; description = "The neomutt package to use."; }; @@ -369,7 +368,7 @@ in { }; sort = mkOption { - # allow users to choose any option from sortOptions, or any option prefixed with "reverse-" + # Allow users to choose any option from sortOptions, or any option prefixed with "reverse-" type = types.enum (builtins.concatMap (_pre: map (_opt: _pre + _opt) sortOptions) [ "" @@ -407,12 +406,12 @@ in { }; changeFolderWhenSourcingAccount = - mkEnableOption "changing the folder when sourcing an account" // { + lib.mkEnableOption "changing the folder when sourcing an account" // { default = true; }; sourcePrimaryAccount = - mkEnableOption "source the primary account by default" // { + lib.mkEnableOption "source the primary account by default" // { default = true; }; @@ -445,14 +444,14 @@ in { rcFile = account: { "${accountFilename account}".text = accountStr account; }; - in foldl' (a: b: a // b) { } (map rcFile neomuttAccounts); + in lib.foldl' (a: b: a // b) { } (map rcFile neomuttAccounts); xdg.configFile."neomutt/neomuttrc" = mkIf (neomuttAccounts != [ ]) { text = let # Find the primary account, if it has neomutt enabled; # otherwise use the first neomutt account as primary. primary = - head (filter (a: a.primary) neomuttAccounts ++ neomuttAccounts); + lib.head (filter (a: a.primary) neomuttAccounts ++ neomuttAccounts); in concatStringsSep "\n" ([ "# Generated by Home Manager." ''set header_cache = "${config.xdg.cacheHome}/neomutt/headers/"'' @@ -475,7 +474,7 @@ in { # Macros'' macroSection "# Register accounts" - (optionalString (accountCommandNeeded) '' + (optionalString accountCommandNeeded '' set account_command = '${accountCommand}/bin/account-command.sh' '') ] ++ (lib.flatten (map registerAccount neomuttAccounts)) ++ [ @@ -490,15 +489,14 @@ in { }; assertions = [{ - assertion = - ((filter (b: (length (toList b.map)) == 0) (cfg.binds ++ cfg.macros)) - == [ ]); + assertion = ((filter (b: (lib.length (lib.toList b.map)) == 0) + (cfg.binds ++ cfg.macros)) == [ ]); message = "The 'programs.neomutt.(binds|macros).map' list must contain at least one element."; }]; warnings = - let hasOldBinds = binds: (filter (b: !(isList b.map)) binds) != [ ]; + let hasOldBinds = binds: (filter (b: !(lib.isList b.map)) binds) != [ ]; in mkIf (hasOldBinds (cfg.binds ++ cfg.macros)) [ "Specifying 'programs.neomutt.(binds|macros).map' as a string is deprecated, use a list of strings instead. See https://github.com/nix-community/home-manager/pull/1885." ]; diff --git a/modules/programs/newsboat.nix b/modules/programs/newsboat.nix index 5f30f9d4..e8505a1c 100644 --- a/modules/programs/newsboat.nix +++ b/modules/programs/newsboat.nix @@ -1,21 +1,20 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkIf mkOption types; + cfg = config.programs.newsboat; wrapQuote = x: ''"${x}"''; urlsFileContents = let mkUrlEntry = u: - concatStringsSep " " ([ u.url ] ++ map wrapQuote u.tags - ++ optional (u.title != null) (wrapQuote "~${u.title}")); + lib.concatStringsSep " " ([ u.url ] ++ map wrapQuote u.tags + ++ lib.optional (u.title != null) (wrapQuote "~${u.title}")); urls = map mkUrlEntry cfg.urls; - mkQueryEntry = n: v: ''"query:${n}:${escape [ ''"'' ] v}"''; - queries = mapAttrsToList mkQueryEntry cfg.queries; - in concatStringsSep "\n" - (if versionAtLeast config.home.stateVersion "20.03" then + mkQueryEntry = n: v: ''"query:${n}:${lib.escape [ ''"'' ] v}"''; + queries = lib.mapAttrsToList mkQueryEntry cfg.queries; + in lib.concatStringsSep "\n" + (if lib.versionAtLeast config.home.stateVersion "20.03" then queries ++ urls else urls ++ queries) + "\n"; @@ -25,7 +24,7 @@ let browser ${cfg.browser} reload-threads ${toString cfg.reloadThreads} auto-reload ${lib.hm.booleans.yesNo cfg.autoReload} - ${optionalString (cfg.reloadTime != null) + ${lib.optionalString (cfg.reloadTime != null) (toString "reload-time ${toString cfg.reloadTime}")} prepopulate-query-feeds yes @@ -33,13 +32,13 @@ let ''; in { - meta.maintainers = [ maintainers.sumnerevans ]; + meta.maintainers = [ lib.maintainers.sumnerevans ]; options = { programs.newsboat = { - enable = mkEnableOption "the Newsboat feed reader"; + enable = lib.mkEnableOption "the Newsboat feed reader"; - package = mkPackageOption pkgs "newsboat" { nullable = true; }; + package = lib.mkPackageOption pkgs "newsboat" { nullable = true; }; urls = mkOption { type = types.listOf (types.submodule { @@ -138,13 +137,14 @@ in { # Use ~/.newsboat on stateVersion < 21.05 and use ~/.config/newsboat for # stateVersion >= 21.05. - home.file = mkIf (versionOlder config.home.stateVersion "21.05") { + home.file = mkIf (lib.versionOlder config.home.stateVersion "21.05") { ".newsboat/urls" = mkIf (cfg.urls != [ ]) { text = urlsFileContents; }; ".newsboat/config".text = configFileContents; }; - xdg.configFile = mkIf (versionAtLeast config.home.stateVersion "21.05") { - "newsboat/urls" = mkIf (cfg.urls != [ ]) { text = urlsFileContents; }; - "newsboat/config".text = configFileContents; - }; + xdg.configFile = + mkIf (lib.versionAtLeast config.home.stateVersion "21.05") { + "newsboat/urls" = mkIf (cfg.urls != [ ]) { text = urlsFileContents; }; + "newsboat/config".text = configFileContents; + }; }; } diff --git a/modules/programs/nheko.nix b/modules/programs/nheko.nix index 0e858b30..6bc4d492 100644 --- a/modules/programs/nheko.nix +++ b/modules/programs/nheko.nix @@ -1,7 +1,4 @@ { config, lib, pkgs, ... }: - -with lib; - let cfg = config.programs.nheko; @@ -14,22 +11,22 @@ let config.xdg.configHome; camelCaseToSnakeCase = - replaceStrings upperChars (map (s: "_${s}") lowerChars); + lib.replaceStrings lib.upperChars (map (s: "_${s}") lib.lowerChars); - inherit (generators) mkKeyValueDefault toINI; + inherit (lib.generators) mkKeyValueDefault toINI; in { - meta.maintainers = [ maintainers.gvolpe ]; + meta.maintainers = [ lib.maintainers.gvolpe ]; options.programs.nheko = { - enable = mkEnableOption "Qt desktop client for Matrix"; + enable = lib.mkEnableOption "Qt desktop client for Matrix"; - package = mkPackageOption pkgs "nheko" { nullable = true; }; + package = lib.mkPackageOption pkgs "nheko" { nullable = true; }; - settings = mkOption { + settings = lib.mkOption { type = iniFmt.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { general.disableCertificateValidation = false; auth = { @@ -63,10 +60,10 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; - home.file."${configDir}/nheko/nheko.conf" = mkIf (cfg.settings != { }) { + home.file."${configDir}/nheko/nheko.conf" = lib.mkIf (cfg.settings != { }) { text = '' ; Generated by Home Manager. diff --git a/modules/programs/nix-index.nix b/modules/programs/nix-index.nix index 23d3c979..62474a07 100644 --- a/modules/programs/nix-index.nix +++ b/modules/programs/nix-index.nix @@ -4,13 +4,13 @@ in { meta.maintainers = [ lib.hm.maintainers.ambroisie lib.maintainers.khaneliman ]; - options.programs.nix-index = with lib; { - enable = mkEnableOption "nix-index, a file database for nixpkgs"; + options.programs.nix-index = { + enable = lib.mkEnableOption "nix-index, a file database for nixpkgs"; - package = mkOption { - type = types.package; + package = lib.mkOption { + type = lib.types.package; default = pkgs.nix-index; - defaultText = literalExpression "pkgs.nix-index"; + defaultText = lib.literalExpression "pkgs.nix-index"; description = "Package providing the {command}`nix-index` tool."; }; diff --git a/modules/programs/nix-your-shell.nix b/modules/programs/nix-your-shell.nix index c39d3a50..05a6bfcb 100644 --- a/modules/programs/nix-your-shell.nix +++ b/modules/programs/nix-your-shell.nix @@ -1,20 +1,14 @@ { config, lib, pkgs, ... }: - -with lib; - -let - - cfg = config.programs.nix-your-shell; - +let cfg = config.programs.nix-your-shell; in { - meta.maintainers = [ maintainers.terlar ]; + meta.maintainers = [ lib.maintainers.terlar ]; options.programs.nix-your-shell = { - enable = mkEnableOption '' + enable = lib.mkEnableOption '' {command}`nix-your-shell`, a wrapper for `nix develop` or `nix-shell` to retain the same shell inside the new environment''; - package = mkPackageOption pkgs "nix-your-shell" { }; + package = lib.mkPackageOption pkgs "nix-your-shell" { }; enableFishIntegration = lib.hm.shell.mkFishIntegrationOption { inherit config; }; @@ -26,15 +20,15 @@ in { lib.hm.shell.mkZshIntegrationOption { inherit config; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; programs = { - fish.interactiveShellInit = mkIf cfg.enableFishIntegration '' + fish.interactiveShellInit = lib.mkIf cfg.enableFishIntegration '' ${cfg.package}/bin/nix-your-shell fish | source ''; - nushell = mkIf cfg.enableNushellIntegration { + nushell = lib.mkIf cfg.enableNushellIntegration { extraEnv = '' mkdir ${config.xdg.cacheHome}/nix-your-shell ${cfg.package}/bin/nix-your-shell nu | save --force ${config.xdg.cacheHome}/nix-your-shell/init.nu @@ -45,7 +39,7 @@ in { ''; }; - zsh.initContent = mkIf cfg.enableZshIntegration '' + zsh.initContent = lib.mkIf cfg.enableZshIntegration '' ${cfg.package}/bin/nix-your-shell zsh | source /dev/stdin ''; }; diff --git a/modules/programs/nnn.nix b/modules/programs/nnn.nix index 4a81486f..8f7b43ba 100644 --- a/modules/programs/nnn.nix +++ b/modules/programs/nnn.nix @@ -1,14 +1,13 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) literalExpression mkOption types; + cfg = config.programs.nnn; renderSetting = key: value: "${key}:${value}"; renderSettings = settings: - concatStringsSep ";" (mapAttrsToList renderSetting settings); + lib.concatStringsSep ";" (lib.mapAttrsToList renderSetting settings); pluginModule = types.submodule ({ ... }: { options = { @@ -45,11 +44,11 @@ let }; }); in { - meta.maintainers = with maintainers; [ thiagokokada ]; + meta.maintainers = with lib.maintainers; [ thiagokokada ]; options = { programs.nnn = { - enable = mkEnableOption "nnn"; + enable = lib.mkEnableOption "nnn"; package = mkOption { type = types.package; @@ -115,15 +114,15 @@ in { ${oldAttrs.postInstall or ""} wrapProgram $out/bin/nnn \ - --prefix PATH : "${makeBinPath cfg.extraPackages}" \ + --prefix PATH : "${lib.makeBinPath cfg.extraPackages}" \ --prefix NNN_BMS : "${renderSettings cfg.bookmarks}" \ --prefix NNN_PLUG : "${renderSettings cfg.plugins.mappings}" ''; }); - in mkIf cfg.enable { + in lib.mkIf cfg.enable { programs.nnn.finalPackage = nnnPackage; home.packages = [ nnnPackage ]; xdg.configFile."nnn/plugins" = - mkIf (cfg.plugins.src != null) { source = cfg.plugins.src; }; + lib.mkIf (cfg.plugins.src != null) { source = cfg.plugins.src; }; }; } diff --git a/modules/programs/noti.nix b/modules/programs/noti.nix index 491d73b0..3ccea78e 100644 --- a/modules/programs/noti.nix +++ b/modules/programs/noti.nix @@ -1,19 +1,13 @@ { config, lib, pkgs, ... }: - -with lib; - -let - - cfg = config.programs.noti; - +let cfg = config.programs.noti; in { meta.maintainers = [ ]; options.programs.noti = { - enable = mkEnableOption "Noti"; + enable = lib.mkEnableOption "Noti"; - settings = mkOption { - type = types.attrsOf (types.attrsOf types.str); + settings = lib.mkOption { + type = with lib.types; attrsOf (attrsOf str); default = { }; description = '' Configuration written to @@ -23,7 +17,7 @@ in { {manpage}`noti.yaml(5)`. for the full list of options. ''; - example = literalExpression '' + example = lib.literalExpression '' { say = { voice = "Alex"; @@ -37,11 +31,11 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ pkgs.noti ]; - xdg.configFile."noti/noti.yaml" = - mkIf (cfg.settings != { }) { text = generators.toYAML { } cfg.settings; }; + xdg.configFile."noti/noti.yaml" = lib.mkIf (cfg.settings != { }) { + text = lib.generators.toYAML { } cfg.settings; + }; }; - } diff --git a/modules/programs/notmuch-virtual-mailbox.nix b/modules/programs/notmuch-virtual-mailbox.nix index 72a78842..fd5d8121 100644 --- a/modules/programs/notmuch-virtual-mailbox.nix +++ b/modules/programs/notmuch-virtual-mailbox.nix @@ -1,5 +1,6 @@ -{ config, lib, ... }: -with lib; { +{ lib, ... }: +let inherit (lib) mkOption types; +in { options = { name = mkOption { type = types.str; @@ -23,7 +24,7 @@ with lib; { }; type = mkOption { - type = types.nullOr (types.enum ([ "threads" "messages" ])); + type = types.nullOr (types.enum [ "threads" "messages" ]); example = "threads"; default = null; description = diff --git a/modules/programs/notmuch.nix b/modules/programs/notmuch.nix index 071f0855..655a9a3f 100644 --- a/modules/programs/notmuch.nix +++ b/modules/programs/notmuch.nix @@ -1,25 +1,23 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) catAttrs filter mkOption optionalAttrs types; cfg = config.programs.notmuch; mkIniKeyValue = key: value: let tweakVal = v: - if isString v then + if lib.isString v then v - else if isList v then - concatMapStringsSep ";" tweakVal v - else if isBool v then + else if lib.isList v then + lib.concatMapStringsSep ";" tweakVal v + else if lib.isBool v then (if v then "true" else "false") else toString v; in "${key}=${tweakVal value}"; - notmuchIni = recursiveUpdate { + notmuchIni = lib.recursiveUpdate { database = { path = config.accounts.email.maildirBasePath; }; maildir = { synchronize_flags = cfg.maildir.synchronizeFlags; }; @@ -31,13 +29,13 @@ let user = let accounts = filter (a: a.notmuch.enable) - (attrValues config.accounts.email.accounts); + (lib.attrValues config.accounts.email.accounts); primary = filter (a: a.primary) accounts; secondaries = filter (a: !a.primary) accounts; in { name = catAttrs "realName" primary; primary_email = catAttrs "address" primary; - other_email = map (email: email.address or email) (flatten + other_email = map (email: email.address or email) (lib.flatten (catAttrs "aliases" primary ++ catAttrs "address" secondaries ++ catAttrs "aliases" secondaries)); }; @@ -48,7 +46,7 @@ let in { options = { programs.notmuch = { - enable = mkEnableOption "Notmuch mail indexer"; + enable = lib.mkEnableOption "Notmuch mail indexer"; new = mkOption { type = types.submodule { @@ -148,12 +146,12 @@ in { accounts.email.accounts = mkOption { type = with types; attrsOf (submodule { - options.notmuch.enable = mkEnableOption "notmuch indexing"; + options.notmuch.enable = lib.mkEnableOption "notmuch indexing"; }); }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ { assertion = notmuchIni.user.name != [ ]; @@ -184,7 +182,7 @@ in { }; in { "notmuch/default/config".text = - let toIni = generators.toINI { mkKeyValue = mkIniKeyValue; }; + let toIni = lib.generators.toINI { mkKeyValue = mkIniKeyValue; }; in '' # Generated by Home Manager. diff --git a/modules/programs/obs-studio.nix b/modules/programs/obs-studio.nix index e6d41331..7fc7413c 100644 --- a/modules/programs/obs-studio.nix +++ b/modules/programs/obs-studio.nix @@ -1,37 +1,34 @@ { config, lib, pkgs, ... }: - -with lib; - let cfg = config.programs.obs-studio; in { - meta.maintainers = [ maintainers.adisbladis ]; + meta.maintainers = [ lib.maintainers.adisbladis ]; options = { programs.obs-studio = { - enable = mkEnableOption "obs-studio"; + enable = lib.mkEnableOption "obs-studio"; package = lib.mkPackageOption pkgs "obs-studio" { }; - finalPackage = mkOption { - type = types.package; + finalPackage = lib.mkOption { + type = lib.types.package; visible = false; readOnly = true; description = "Resulting customized OBS Studio package."; }; - plugins = mkOption { + plugins = lib.mkOption { default = [ ]; - example = literalExpression "[ pkgs.obs-studio-plugins.wlrobs ]"; + example = lib.literalExpression "[ pkgs.obs-studio-plugins.wlrobs ]"; description = "Optional OBS plugins."; - type = types.listOf types.package; + type = lib.types.listOf lib.types.package; }; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.finalPackage ]; programs.obs-studio.finalPackage = pkgs.wrapOBS.override { obs-studio = cfg.package; } { diff --git a/modules/programs/octant.nix b/modules/programs/octant.nix index f3b810c9..5ed4d10b 100644 --- a/modules/programs/octant.nix +++ b/modules/programs/octant.nix @@ -1,15 +1,13 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) literalExpression; cfg = config.programs.octant; mkPluginEnv = packages: let pluginDirs = map (pkg: "${pkg}/bin") packages; - plugins = concatMapStringsSep " " (p: "${p}/*") pluginDirs; + plugins = lib.concatMapStringsSep " " (p: "${p}/*") pluginDirs; in pkgs.runCommandLocal "octant-plugins" { } '' mkdir $out [[ '${plugins}' ]] || exit 0 @@ -19,33 +17,33 @@ let ''; in { - meta.maintainers = with maintainers; [ jk ]; + meta.maintainers = with lib.maintainers; [ jk ]; options = { programs.octant = { - enable = mkEnableOption "octant"; + enable = lib.mkEnableOption "octant"; - package = mkOption { - type = types.package; + package = lib.mkOption { + type = lib.types.package; default = pkgs.octant; defaultText = literalExpression "pkgs.octant"; example = literalExpression "pkgs.octant-other"; description = "The Octant package to use."; }; - plugins = mkOption { + plugins = lib.mkOption { default = [ ]; example = literalExpression "[ pkgs.starboard-octant-plugin ]"; description = "Optional Octant plugins."; - type = types.listOf types.package; + type = lib.types.listOf lib.types.package; }; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; xdg.configFile."octant/plugins" = - mkIf (cfg.plugins != [ ]) { source = mkPluginEnv cfg.plugins; }; + lib.mkIf (cfg.plugins != [ ]) { source = mkPluginEnv cfg.plugins; }; }; } diff --git a/modules/programs/offlineimap-accounts.nix b/modules/programs/offlineimap-accounts.nix index bbbc057a..5fb79cce 100644 --- a/modules/programs/offlineimap-accounts.nix +++ b/modules/programs/offlineimap-accounts.nix @@ -1,14 +1,11 @@ { lib, ... }: - -with lib; - let + inherit (lib) mkOption types; extraConfigType = with types; attrsOf (either (either str int) bool); - in { options.offlineimap = { - enable = mkEnableOption "OfflineIMAP"; + enable = lib.mkEnableOption "OfflineIMAP"; extraConfig.account = mkOption { type = extraConfigType; diff --git a/modules/programs/offlineimap.nix b/modules/programs/offlineimap.nix index fcafec06..e5bc91cc 100644 --- a/modules/programs/offlineimap.nix +++ b/modules/programs/offlineimap.nix @@ -1,25 +1,24 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkOption optionalAttrs; cfg = config.programs.offlineimap; - accounts = filter (a: a.offlineimap.enable) - (attrValues config.accounts.email.accounts); + accounts = lib.filter (a: a.offlineimap.enable) + (lib.attrValues config.accounts.email.accounts); - toIni = generators.toINI { + toIni = lib.generators.toINI { mkKeyValue = key: value: let value' = - (if isBool value then lib.hm.booleans.yesNo else toString) value; + (if lib.isBool value then lib.hm.booleans.yesNo else toString) value; in "${key} = ${value'}"; }; accountStr = account: - with account; let + inherit (account) imap name passwordCommand offlineimap; + postSyncHook = optionalAttrs (offlineimap.postSyncHookCommand != "") { postsynchook = pkgs.writeShellScriptBin "postsynchook" offlineimap.postSyncHookCommand + "/bin/postsynchook"; @@ -46,7 +45,7 @@ let }; remotePassEval = - let arglist = concatMapStringsSep "," (x: "'${x}'") passwordCommand; + let arglist = lib.concatMapStringsSep "," (x: "'${x}'") passwordCommand; in optionalAttrs (passwordCommand != null) { remotepasseval = ''get_pass("${name}", [${arglist}]).strip(b"\n")''; }; @@ -58,24 +57,24 @@ let "Repository ${name}-local" = { type = localType; - localfolders = maildir.absPath; + localfolders = account.maildir.absPath; } // offlineimap.extraConfig.local; "Repository ${name}-remote" = { type = remoteType; - remoteuser = userName; + remoteuser = account.userName; } // remoteHost // remotePort // remotePassEval // ssl // offlineimap.extraConfig.remote; }; - extraConfigType = with types; attrsOf (either (either str int) bool); + extraConfigType = with lib.types; attrsOf (either (either str int) bool); in { options = { programs.offlineimap = { - enable = mkEnableOption "OfflineIMAP"; + enable = lib.mkEnableOption "OfflineIMAP"; - package = mkPackageOption pkgs "offlineimap" { + package = lib.mkPackageOption pkgs "offlineimap" { example = '' pkgs.offlineimap.overridePythonAttrs ( old: { propagatedBuildInputs = old.propagatedBuildInputs @@ -86,7 +85,7 @@ in { }; pythonFile = mkOption { - type = types.lines; + type = lib.types.lines; default = '' import subprocess @@ -125,7 +124,7 @@ in { extraConfig.mbnames = mkOption { type = extraConfigType; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { filename = "~/.config/mutt/mailboxes"; header = "'mailboxes '"; @@ -142,12 +141,12 @@ in { }; accounts.email.accounts = mkOption { - type = with types; + type = with lib.types; attrsOf (submodule (import ./offlineimap-accounts.nix)); }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; xdg.configFile."offlineimap/get_settings.py".text = cfg.pythonFile; @@ -169,14 +168,14 @@ in { # for an exhaustive list of options. '' + toIni ({ general = { - accounts = concatMapStringsSep "," (a: a.name) accounts; + accounts = lib.concatMapStringsSep "," (a: a.name) accounts; pythonfile = "${config.xdg.configHome}/offlineimap/get_settings.py"; metadata = "${config.xdg.dataHome}/offlineimap"; } // cfg.extraConfig.general; - } // optionalAttrs (cfg.extraConfig.mbnames != { }) { + } // lib.optionalAttrs (cfg.extraConfig.mbnames != { }) { mbnames = { enabled = true; } // cfg.extraConfig.mbnames; - } // optionalAttrs (cfg.extraConfig.default != { }) { + } // lib.optionalAttrs (cfg.extraConfig.default != { }) { DEFAULT = cfg.extraConfig.default; - }) + "\n" + concatStringsSep "\n" (map accountStr accounts); + }) + "\n" + lib.concatStringsSep "\n" (map accountStr accounts); }; } diff --git a/modules/programs/oh-my-posh.nix b/modules/programs/oh-my-posh.nix index dc666afb..2d6b063f 100644 --- a/modules/programs/oh-my-posh.nix +++ b/modules/programs/oh-my-posh.nix @@ -1,7 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; let + inherit (lib) mkIf; cfg = config.programs.oh-my-posh; @@ -15,17 +14,18 @@ let ""; in { - meta.maintainers = [ maintainers.arjan-s ]; + meta.maintainers = [ lib.maintainers.arjan-s ]; options.programs.oh-my-posh = { - enable = mkEnableOption "oh-my-posh, a prompt theme engine for any shell"; + enable = + lib.mkEnableOption "oh-my-posh, a prompt theme engine for any shell"; - package = mkPackageOption pkgs "oh-my-posh" { }; + package = lib.mkPackageOption pkgs "oh-my-posh" { }; - settings = mkOption { + settings = lib.mkOption { type = jsonFormat.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' builtins.fromJSON (builtins.unsafeDiscardStringContext (builtins.readFile "''${pkgs.oh-my-posh}/share/oh-my-posh/themes/space.omp.json"))''; description = '' Configuration written to @@ -36,8 +36,8 @@ in { ''; }; - useTheme = mkOption { - type = types.nullOr types.str; + useTheme = lib.mkOption { + type = lib.types.nullOr lib.types.str; default = null; description = '' Use one of the official themes. This should be a name from this list: diff --git a/modules/programs/opam.nix b/modules/programs/opam.nix index d75a0215..961bc724 100644 --- a/modules/programs/opam.nix +++ b/modules/programs/opam.nix @@ -1,16 +1,10 @@ { config, lib, pkgs, ... }: - -with lib; - -let - - cfg = config.programs.opam; - +let cfg = config.programs.opam; in { meta.maintainers = [ ]; options.programs.opam = { - enable = mkEnableOption "Opam"; + enable = lib.mkEnableOption "Opam"; package = lib.mkPackageOption pkgs "opam" { }; @@ -24,18 +18,18 @@ in { lib.hm.shell.mkZshIntegrationOption { inherit config; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; - programs.bash.initExtra = mkIf cfg.enableBashIntegration '' + programs.bash.initExtra = lib.mkIf cfg.enableBashIntegration '' eval "$(${cfg.package}/bin/opam env --shell=bash)" ''; - programs.zsh.initContent = mkIf cfg.enableZshIntegration '' + programs.zsh.initContent = lib.mkIf cfg.enableZshIntegration '' eval "$(${cfg.package}/bin/opam env --shell=zsh)" ''; - programs.fish.shellInit = mkIf cfg.enableFishIntegration '' + programs.fish.shellInit = lib.mkIf cfg.enableFishIntegration '' eval (${cfg.package}/bin/opam env --shell=fish) ''; }; diff --git a/modules/programs/papis.nix b/modules/programs/papis.nix index 1b8ae137..9e98d52d 100644 --- a/modules/programs/papis.nix +++ b/modules/programs/papis.nix @@ -1,30 +1,30 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; cfg = config.programs.papis; - defaultLibraries = remove null - (mapAttrsToList (n: v: if v.isDefault then n else null) cfg.libraries); + defaultLibraries = lib.remove null + (lib.mapAttrsToList (n: v: if v.isDefault then n else null) cfg.libraries); settingsIni = (lib.mapAttrs (n: v: v.settings) cfg.libraries) // { - settings = cfg.settings // { "default-library" = head defaultLibraries; }; + settings = cfg.settings // { + "default-library" = lib.head defaultLibraries; + }; }; in { meta.maintainers = [ ]; options.programs.papis = { - enable = mkEnableOption "papis"; + enable = lib.mkEnableOption "papis"; - package = mkPackageOption pkgs "papis" { nullable = true; }; + package = lib.mkPackageOption pkgs "papis" { nullable = true; }; settings = mkOption { type = with types; attrsOf (oneOf [ bool int str ]); default = { }; - example = literalExpression '' + example = lib.literalExpression '' { editor = "nvim"; file-browser = "ranger" @@ -62,7 +62,7 @@ in { settings = mkOption { type = with types; attrsOf (oneOf [ bool int str ]); default = { }; - example = literalExpression '' + example = lib.literalExpression '' { dir = "~/papers/"; } @@ -77,18 +77,19 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [{ - assertion = cfg.libraries == { } || length defaultLibraries == 1; + assertion = cfg.libraries == { } || lib.length defaultLibraries == 1; message = "Must have exactly one default papis library, but found " - + toString (length defaultLibraries) - + optionalString (length defaultLibraries > 1) - (", namely " + concatStringsSep "," defaultLibraries); + + toString (lib.length defaultLibraries) + + lib.optionalString (lib.length defaultLibraries > 1) + (", namely " + lib.concatStringsSep "," defaultLibraries); }]; home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; - xdg.configFile."papis/config" = - mkIf (cfg.libraries != { }) { text = generators.toINI { } settingsIni; }; + xdg.configFile."papis/config" = lib.mkIf (cfg.libraries != { }) { + text = lib.generators.toINI { } settingsIni; + }; }; } diff --git a/modules/programs/password-store.nix b/modules/programs/password-store.nix index c57b7a85..e4a9342d 100644 --- a/modules/programs/password-store.nix +++ b/modules/programs/password-store.nix @@ -1,16 +1,14 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) literalExpression mkOption types; cfg = config.programs.password-store; in { - meta.maintainers = with maintainers; [ euxane ]; + meta.maintainers = with lib.maintainers; [ euxane ]; options.programs.password-store = { - enable = mkEnableOption "Password store"; + enable = lib.mkEnableOption "Password store"; package = mkOption { type = types.package; @@ -27,7 +25,7 @@ in { settings = mkOption rec { type = with types; attrsOf str; - apply = mergeAttrs default; + apply = lib.mergeAttrs default; default = { PASSWORD_STORE_DIR = "${config.xdg.dataHome}/password-store"; }; @@ -52,14 +50,14 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; home.sessionVariables = cfg.settings; services.pass-secret-service.storePath = - mkDefault cfg.settings.PASSWORD_STORE_DIR; + lib.mkDefault cfg.settings.PASSWORD_STORE_DIR; - xsession.importedVariables = mkIf config.xsession.enable - (mapAttrsToList (name: value: name) cfg.settings); + xsession.importedVariables = lib.mkIf config.xsession.enable + (lib.mapAttrsToList (name: value: name) cfg.settings); }; } diff --git a/modules/programs/pazi.nix b/modules/programs/pazi.nix index 8e9838af..05c9898b 100644 --- a/modules/programs/pazi.nix +++ b/modules/programs/pazi.nix @@ -1,8 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkIf; cfg = config.programs.pazi; @@ -10,7 +8,7 @@ in { meta.maintainers = [ ]; options.programs.pazi = { - enable = mkEnableOption "pazi"; + enable = lib.mkEnableOption "pazi"; enableBashIntegration = lib.hm.shell.mkBashIntegrationOption { inherit config; }; diff --git a/modules/programs/pet.nix b/modules/programs/pet.nix index ee7c107d..23bfe8eb 100644 --- a/modules/programs/pet.nix +++ b/modules/programs/pet.nix @@ -1,8 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; cfg = config.programs.pet; @@ -40,7 +38,7 @@ let tag = mkOption { type = types.listOf types.str; default = [ ]; - example = literalExpression ''["git" "nixpkgs"]''; + example = lib.literalExpression ''["git" "nixpkgs"]''; description = '' List of tags attached to the command. ''; @@ -50,7 +48,7 @@ let in { options.programs.pet = { - enable = mkEnableOption "pet"; + enable = lib.mkEnableOption "pet"; settings = mkOption { type = format.type; @@ -64,7 +62,7 @@ in { selectcmdPackage = mkOption { type = types.package; default = pkgs.fzf; - defaultText = literalExpression "pkgs.fzf"; + defaultText = lib.literalExpression "pkgs.fzf"; description = '' The package needed for the {var}`settings.selectcmd`. ''; @@ -79,13 +77,13 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { programs.pet.settings = let defaultGeneral = { - selectcmd = mkDefault "fzf"; + selectcmd = lib.mkDefault "fzf"; snippetfile = config.xdg.configHome + "/pet/snippet.toml"; }; - in if versionAtLeast config.home.stateVersion "21.11" then { + in if lib.versionAtLeast config.home.stateVersion "21.11" then { General = defaultGeneral; } else defaultGeneral; @@ -94,12 +92,12 @@ in { xdg.configFile = { "pet/config.toml".source = format.generate "config.toml" - (if versionAtLeast config.home.stateVersion "21.11" then + (if lib.versionAtLeast config.home.stateVersion "21.11" then cfg.settings else { General = cfg.settings; }); - "pet/snippet.toml" = mkIf (cfg.snippets != [ ]) { + "pet/snippet.toml" = lib.mkIf (cfg.snippets != [ ]) { source = format.generate "snippet.toml" { snippets = cfg.snippets; }; }; }; diff --git a/modules/programs/pidgin.nix b/modules/programs/pidgin.nix index d7536be7..4a7e9c8e 100644 --- a/modules/programs/pidgin.nix +++ b/modules/programs/pidgin.nix @@ -1,34 +1,28 @@ { config, lib, pkgs, ... }: - -with lib; - -let - - cfg = config.programs.pidgin; - +let cfg = config.programs.pidgin; in { - meta.maintainers = [ maintainers.rycee ]; + meta.maintainers = [ lib.maintainers.rycee ]; options = { programs.pidgin = { - enable = mkEnableOption "Pidgin messaging client"; + enable = lib.mkEnableOption "Pidgin messaging client"; - package = mkOption { - type = types.package; + package = lib.mkOption { + type = lib.types.package; default = pkgs.pidgin; - defaultText = literalExpression "pkgs.pidgin"; + defaultText = lib.literalExpression "pkgs.pidgin"; description = "The Pidgin package to use."; }; - plugins = mkOption { + plugins = lib.mkOption { default = [ ]; - example = literalExpression "[ pkgs.pidgin-otr pkgs.pidgin-osd ]"; + example = lib.literalExpression "[ pkgs.pidgin-otr pkgs.pidgin-osd ]"; description = "Plugins that should be available to Pidgin."; }; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ (cfg.package.override { inherit (cfg) plugins; }) ]; }; } diff --git a/modules/programs/pistol.nix b/modules/programs/pistol.nix index 28f7ea97..5dd8bc3f 100644 --- a/modules/programs/pistol.nix +++ b/modules/programs/pistol.nix @@ -1,11 +1,10 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkIf mkOption types; + cfg = config.programs.pistol; - configFile = concatStringsSep "\n" (map ({ fpath, mime, command }: + configFile = lib.concatStringsSep "\n" (map ({ fpath, mime, command }: if fpath == "" then "${mime} ${command}" else "fpath ${fpath} ${command}") cfg.associations); @@ -31,19 +30,19 @@ let }; in { imports = [ - (mkRemovedOptionModule [ "programs" "pistol" "config" ] + (lib.mkRemovedOptionModule [ "programs" "pistol" "config" ] "Pistol is now configured with programs.pistol.associations.") ]; - meta.maintainers = [ hm.maintainers.mtoohey ]; + meta.maintainers = [ lib.hm.maintainers.mtoohey ]; options.programs.pistol = { - enable = mkEnableOption "file previewer for terminal file managers"; + enable = lib.mkEnableOption "file previewer for terminal file managers"; associations = mkOption { type = types.listOf association; default = [ ]; - example = literalExpression '' + example = lib.literalExpression '' [ { mime = "application/json"; command = "bat %pistol-filename%"; } { mime = "application/*"; command = "hexyl %pistol-filename%"; } @@ -58,10 +57,10 @@ in { }; - config = mkIf cfg.enable (mkMerge [ + config = mkIf cfg.enable (lib.mkMerge [ { assertions = [{ - assertion = all ({ fpath, mime, ... }: + assertion = lib.all ({ fpath, mime, ... }: (fpath != "" && mime == "") || (fpath == "" && mime != "")) cfg.associations; message = '' diff --git a/modules/programs/piston-cli.nix b/modules/programs/piston-cli.nix index c554c596..3c07c488 100644 --- a/modules/programs/piston-cli.nix +++ b/modules/programs/piston-cli.nix @@ -1,27 +1,24 @@ { config, lib, pkgs, ... }: - -with lib; - let cfg = config.programs.piston-cli; yamlFormat = pkgs.formats.yaml { }; in { - meta.maintainers = with maintainers; [ ethancedwards8 ]; + meta.maintainers = with lib.maintainers; [ ethancedwards8 ]; options.programs.piston-cli = { - enable = mkEnableOption "piston-cli, code runner"; + enable = lib.mkEnableOption "piston-cli, code runner"; - package = mkOption { - type = types.package; + package = lib.mkOption { + type = lib.types.package; default = pkgs.piston-cli; - defaultText = literalExpression "pkgs.piston-cli"; + defaultText = lib.literalExpression "pkgs.piston-cli"; description = "The piston-cli package to use."; }; - settings = mkOption { + settings = lib.mkOption { type = yamlFormat.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { theme = "emacs"; box_style = "MINIMAL_DOUBLE_HEAD"; @@ -36,10 +33,10 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; - xdg.configFile."piston-cli/config.yml" = mkIf (cfg.settings != { }) { + xdg.configFile."piston-cli/config.yml" = lib.mkIf (cfg.settings != { }) { source = yamlFormat.generate "config.yml" cfg.settings; }; }; diff --git a/modules/programs/pls.nix b/modules/programs/pls.nix index 8abb8261..633d892b 100644 --- a/modules/programs/pls.nix +++ b/modules/programs/pls.nix @@ -1,8 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkIf; cfg = config.programs.pls; @@ -13,14 +11,14 @@ let }; in { - meta.maintainers = [ maintainers.arjan-s ]; + meta.maintainers = [ lib.maintainers.arjan-s ]; options.programs.pls = { - enable = mkEnableOption "pls, a modern replacement for {command}`ls`"; + enable = lib.mkEnableOption "pls, a modern replacement for {command}`ls`"; - package = mkPackageOption pkgs "pls" { }; + package = lib.mkPackageOption pkgs "pls" { }; - enableAliases = mkEnableOption "recommended pls aliases"; + enableAliases = lib.mkEnableOption "recommended pls aliases"; }; config = mkIf cfg.enable { @@ -28,7 +26,7 @@ in { programs.bash.shellAliases = mkIf cfg.enableAliases aliases; - programs.fish = mkMerge [ + programs.fish = lib.mkMerge [ (mkIf (!config.programs.fish.preferAbbrs) { shellAliases = mkIf cfg.enableAliases aliases; }) diff --git a/modules/programs/powerline-go.nix b/modules/programs/powerline-go.nix index 520229c1..9e63c1a5 100644 --- a/modules/programs/powerline-go.nix +++ b/modules/programs/powerline-go.nix @@ -1,20 +1,17 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkIf mkOption optionalString types; cfg = config.programs.powerline-go; # Convert an option value to a string to be passed as argument to - # powerline-go: + # `powerline-go`: valueToString = value: if builtins.isList value then builtins.concatStringsSep "," (builtins.map valueToString value) else if builtins.isAttrs value then - valueToString - (mapAttrsToList (key: val: "${valueToString key}=${valueToString val}") - value) + valueToString (lib.mapAttrsToList + (key: val: "${valueToString key}=${valueToString val}") value) else builtins.toString value; @@ -26,7 +23,7 @@ let evalMode = cfg.modulesRight != null; - evalArgument = optionalString (evalMode) " -eval"; + evalArgument = optionalString evalMode " -eval"; newlineArgument = optionalString cfg.newline " -newline"; @@ -37,19 +34,19 @@ let if value == true then " -${name}" else " -${name} ${valueToString value}"; otherSettingsArgument = optionalString (cfg.settings != { }) - (concatStringsSep "" - (mapAttrsToList otherSettingPairArgument cfg.settings)); + (lib.concatStringsSep "" + (lib.mapAttrsToList otherSettingPairArgument cfg.settings)); commandLineArguments = '' ${evalArgument}${modulesArgument}${modulesRightArgument}${newlineArgument}${pathAliasesArgument}${otherSettingsArgument} ''; in { - meta.maintainers = [ maintainers.DamienCassou ]; + meta.maintainers = [ lib.maintainers.DamienCassou ]; options = { programs.powerline-go = { - enable = mkEnableOption + enable = lib.mkEnableOption "Powerline-go, a beautiful and useful low-latency prompt for your shell"; modules = mkOption { @@ -92,7 +89,7 @@ in { may use '~' to represent your home directory but you should protect it to avoid shell substitution. ''; - example = literalExpression '' + example = lib.literalExpression '' { "\\~/projects/home-manager" = "prj:home-manager"; } ''; }; @@ -104,7 +101,7 @@ in { This can be any key/value pair as described in . ''; - example = literalExpression '' + example = lib.literalExpression '' { hostname-only-if-ssh = true; numeric-exit-codes = true; diff --git a/modules/programs/pqiv.nix b/modules/programs/pqiv.nix index 26c406dd..8065f3b8 100644 --- a/modules/programs/pqiv.nix +++ b/modules/programs/pqiv.nix @@ -1,7 +1,4 @@ { config, lib, pkgs, ... }: - -with lib; - let cfg = config.programs.pqiv; iniFormat = pkgs.formats.ini { }; @@ -9,18 +6,18 @@ in { meta.maintainers = with lib.maintainers; [ donovanglover iynaix ]; options.programs.pqiv = { - enable = mkEnableOption "pqiv image viewer"; + enable = lib.mkEnableOption "pqiv image viewer"; package = lib.mkPackageOption pkgs "pqiv" { }; - settings = mkOption { + settings = lib.mkOption { type = iniFormat.type; default = { }; description = '' Configuration written to {file}`$XDG_CONFIG_HOME/pqivrc`. See {manpage}`pqiv(1)` for a list of available options. ''; - example = literalExpression '' + example = lib.literalExpression '' { options = { lazy-load = true; @@ -33,14 +30,14 @@ in { ''; }; - extraConfig = mkOption { - type = types.lines; + extraConfig = lib.mkOption { + type = lib.types.lines; default = ""; description = '' Extra lines to be added to {file}`$XDG_CONFIG_HOME/pqivrc`. See {manpage}`pqiv(1)` for a list of available options. ''; - example = literalExpression '' + example = lib.literalExpression '' [actions] set_cursor_auto_hide(1) @@ -53,19 +50,21 @@ in { }; }; - config = mkIf cfg.enable { - assertions = - [ (hm.assertions.assertPlatform "programs.pqiv" pkgs platforms.linux) ]; + config = lib.mkIf cfg.enable { + assertions = [ + (lib.hm.assertions.assertPlatform "programs.pqiv" pkgs + lib.platforms.linux) + ]; home.packages = [ cfg.package ]; xdg.configFile."pqivrc" = - mkIf (cfg.settings != { } || cfg.extraConfig != "") { + lib.mkIf (cfg.settings != { } || cfg.extraConfig != "") { text = lib.concatLines [ - (generators.toINI { + (lib.generators.toINI { mkKeyValue = key: value: let - value' = if isBool value then + value' = if lib.isBool value then (if value then "1" else "0") else toString value; diff --git a/modules/programs/pubs.nix b/modules/programs/pubs.nix index 1d7f0c0d..12f49cc7 100644 --- a/modules/programs/pubs.nix +++ b/modules/programs/pubs.nix @@ -1,28 +1,26 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; cfg = config.programs.pubs; in { - meta.maintainers = [ hm.maintainers.loicreynier ]; + meta.maintainers = [ lib.hm.maintainers.loicreynier ]; options.programs.pubs = { - enable = mkEnableOption "pubs"; + enable = lib.mkEnableOption "pubs"; package = mkOption { type = types.package; default = pkgs.pubs; - defaultText = literalExpression "pkgs.pubs"; + defaultText = lib.literalExpression "pkgs.pubs"; description = "The package to use for the pubs script."; }; extraConfig = mkOption { type = types.lines; default = ""; - example = literalExpression '' + example = lib.literalExpression '' ''' [main] pubsdir = ''${config.home.homeDirectory}/.pubs @@ -51,10 +49,10 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; home.file.".pubsrc" = - mkIf (cfg.extraConfig != "") { text = cfg.extraConfig; }; + lib.mkIf (cfg.extraConfig != "") { text = cfg.extraConfig; }; }; } diff --git a/modules/programs/pylint.nix b/modules/programs/pylint.nix index e6679b98..f646b208 100644 --- a/modules/programs/pylint.nix +++ b/modules/programs/pylint.nix @@ -1,30 +1,27 @@ { config, lib, pkgs, ... }: - -with lib; - let - cfg = config.programs.pylint; - listToValue = concatMapStringsSep ", " (generators.mkValueStringDefault { }); + listToValue = + lib.concatMapStringsSep ", " (lib.generators.mkValueStringDefault { }); iniFormat = pkgs.formats.ini { inherit listToValue; }; in { - meta.maintainers = [ hm.maintainers.florpe ]; + meta.maintainers = [ lib.hm.maintainers.florpe ]; options.programs.pylint = { - enable = mkEnableOption "the pylint Python linter"; - package = mkOption { - type = types.package; + enable = lib.mkEnableOption "the pylint Python linter"; + package = lib.mkOption { + type = lib.types.package; default = pkgs.python3Packages.pylint; - defaultText = literalExpression "pkgs.python3Packages.pylint"; + defaultText = lib.literalExpression "pkgs.python3Packages.pylint"; description = "The pylint package to use."; }; - settings = mkOption { + settings = lib.mkOption { type = iniFormat.type; default = { }; - defaultText = literalExpression "{}"; + defaultText = lib.literalExpression "{}"; description = "The pylint configuration."; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; home.file.".pylintrc".source = iniFormat.generate "pylintrc" cfg.settings; }; diff --git a/modules/programs/pywal.nix b/modules/programs/pywal.nix index c29ece0e..5903b8c2 100644 --- a/modules/programs/pywal.nix +++ b/modules/programs/pywal.nix @@ -1,13 +1,9 @@ { config, lib, pkgs, ... }: - -with lib; - let cfg = config.programs.pywal; - in { - options = { programs.pywal = { enable = mkEnableOption "pywal"; }; }; + options = { programs.pywal = { enable = lib.mkEnableOption "pywal"; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ pkgs.pywal ]; diff --git a/modules/programs/qutebrowser.nix b/modules/programs/qutebrowser.nix index 4f17b00f..ea5720fa 100644 --- a/modules/programs/qutebrowser.nix +++ b/modules/programs/qutebrowser.nix @@ -1,8 +1,7 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) + concatStringsSep literalExpression mapAttrsToList mkIf mkOption types; cfg = config.programs.qutebrowser; @@ -32,14 +31,14 @@ let if c == null then ''config.unbind("${k}", mode="${m}")'' else - ''config.bind("${k}", "${escape [ ''"'' ] c}", mode="${m}")''; + ''config.bind("${k}", "${lib.escape [ ''"'' ] c}", mode="${m}")''; in concatStringsSep "\n" (mapAttrsToList (formatKeyBinding m) b); formatQuickmarks = n: s: "${n} ${s}"; in { options.programs.qutebrowser = { - enable = mkEnableOption "qutebrowser"; + enable = lib.mkEnableOption "qutebrowser"; package = lib.mkPackageOption pkgs "qutebrowser" { }; @@ -279,14 +278,15 @@ in { ++ mapAttrsToList (formatDictLine "c.url.searchengines") cfg.searchEngines ++ mapAttrsToList (formatDictLine "c.bindings.key_mappings") cfg.keyMappings - ++ optional (!cfg.enableDefaultBindings) "c.bindings.default = {}" + ++ lib.optional (!cfg.enableDefaultBindings) "c.bindings.default = {}" ++ mapAttrsToList formatKeyBindings cfg.keyBindings - ++ optional (cfg.extraConfig != "") cfg.extraConfig); + ++ lib.optional (cfg.extraConfig != "") cfg.extraConfig); - quickmarksFile = optionals (cfg.quickmarks != { }) concatStringsSep "\n" - ((mapAttrsToList formatQuickmarks cfg.quickmarks)); + quickmarksFile = lib.optionals (cfg.quickmarks != { }) concatStringsSep "\n" + (mapAttrsToList formatQuickmarks cfg.quickmarks); - greasemonkeyDir = optionals (cfg.greasemonkey != [ ]) pkgs.linkFarmFromDrvs + greasemonkeyDir = + lib.optionals (cfg.greasemonkey != [ ]) pkgs.linkFarmFromDrvs "greasemonkey-userscripts" cfg.greasemonkey; in mkIf cfg.enable { home.packages = [ cfg.package ]; @@ -307,7 +307,7 @@ in { socket="''${XDG_RUNTIME_DIR:-/run/user/$UID}/qutebrowser/ipc-$hash" if [[ -S $socket ]]; then command=${ - escapeShellArg (builtins.toJSON { + lib.escapeShellArg (builtins.toJSON { args = [ ":config-source" ]; target_arg = null; protocol_version = 1; diff --git a/modules/programs/ranger.nix b/modules/programs/ranger.nix index 378db5f3..e1a68b05 100644 --- a/modules/programs/ranger.nix +++ b/modules/programs/ranger.nix @@ -1,12 +1,11 @@ { config, pkgs, lib, ... }: +let + inherit (lib) literalExpression mkOption types; -with lib; - -let cfg = config.programs.ranger; - + cfg = config.programs.ranger; in { options.programs.ranger = { - enable = mkEnableOption "ranger file manager"; + enable = lib.mkEnableOption "ranger file manager"; package = mkOption { type = types.package; @@ -139,7 +138,7 @@ in { }; }; - config = mkIf cfg.enable (mkMerge [ + config = lib.mkIf cfg.enable (lib.mkMerge [ { programs.ranger.finalPackage = cfg.package.overrideAttrs (oldAttrs: { propagatedBuildInputs = (oldAttrs.propagatedBuildInputs or [ ]) @@ -149,9 +148,9 @@ in { home.packages = [ cfg.finalPackage ]; xdg.configFile."ranger/rc.conf".text = let - mkString = generators.mkValueStringDefault { }; + mkString = lib.generators.mkValueStringDefault { }; mkConfig = cmd: - generators.toKeyValue { + lib.generators.toKeyValue { mkKeyValue = k: v: "${cmd} ${k} ${mkString v}"; }; in '' @@ -162,21 +161,21 @@ in { ''; } - (mkIf (cfg.plugins != [ ]) { + (lib.mkIf (cfg.plugins != [ ]) { xdg.configFile = let toAttrs = i: { name = "ranger/plugins/${i.name}"; value.source = i.src; }; - in listToAttrs (map toAttrs cfg.plugins); + in lib.listToAttrs (map toAttrs cfg.plugins); }) - (mkIf (cfg.rifle != [ ]) { + (lib.mkIf (cfg.rifle != [ ]) { xdg.configFile."ranger/rifle.conf".text = let lines = map (i: "${i.condition} = ${i.command}") cfg.rifle; - in concatLines lines; + in lib.concatLines lines; }) ]); - meta.maintainers = [ hm.maintainers.fpob ]; + meta.maintainers = [ lib.hm.maintainers.fpob ]; } diff --git a/modules/programs/rbenv.nix b/modules/programs/rbenv.nix index 59b9bba7..6954cd6a 100644 --- a/modules/programs/rbenv.nix +++ b/modules/programs/rbenv.nix @@ -1,8 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkIf mkOption types; cfg = config.programs.rbenv; @@ -27,14 +25,14 @@ in { meta.maintainers = [ ]; options.programs.rbenv = { - enable = mkEnableOption "rbenv"; + enable = lib.mkEnableOption "rbenv"; - package = mkPackageOption pkgs "rbenv" { }; + package = lib.mkPackageOption pkgs "rbenv" { }; plugins = mkOption { type = types.listOf pluginModule; default = [ ]; - example = literalExpression '' + example = lib.literalExpression '' [ { name = "ruby-build"; diff --git a/modules/programs/rbw.nix b/modules/programs/rbw.nix index b7381c67..9fdf20c9 100644 --- a/modules/programs/rbw.nix +++ b/modules/programs/rbw.nix @@ -4,70 +4,69 @@ let jsonFormat = pkgs.formats.json { }; + inherit (lib) mkOption types; inherit (pkgs.stdenv.hostPlatform) isDarwin; - settingsModule = with lib; - types.submodule { - freeformType = jsonFormat.type; - options = { - email = mkOption { - type = types.str; - example = "name@example.com"; - description = "The email address for your bitwarden account."; - }; + settingsModule = types.submodule { + freeformType = jsonFormat.type; + options = { + email = mkOption { + type = types.str; + example = "name@example.com"; + description = "The email address for your bitwarden account."; + }; - base_url = mkOption { - type = with types; nullOr str; - default = null; - example = "https://bitwarden.example.com/"; - description = - "The base-url for a self-hosted bitwarden installation."; - }; + base_url = mkOption { + type = with types; nullOr str; + default = null; + example = "https://bitwarden.example.com/"; + description = "The base-url for a self-hosted bitwarden installation."; + }; - identity_url = mkOption { - type = with types; nullOr str; - default = null; - example = "https://identity.example.com/"; - description = "The identity url for your bitwarden installation."; - }; + identity_url = mkOption { + type = with types; nullOr str; + default = null; + example = "https://identity.example.com/"; + description = "The identity url for your bitwarden installation."; + }; - lock_timeout = mkOption { - type = types.ints.unsigned; - default = 3600; - example = 300; - description = '' - The amount of time that your login information should be cached. - ''; - }; + lock_timeout = mkOption { + type = types.ints.unsigned; + default = 3600; + example = 300; + description = '' + The amount of time that your login information should be cached. + ''; + }; - pinentry = mkOption { - type = types.nullOr types.package; - example = literalExpression "pkgs.pinentry-gnome3"; - default = null; - description = '' - Which pinentry interface to use. Beware that - `pinentry-gnome3` may not work on non-Gnome - systems. You can fix it by adding the following to your - system configuration: - ```nix - services.dbus.packages = [ pkgs.gcr ]; - ``` - ''; - # we want the program in the config - apply = val: if val == null then val else lib.getExe val; - }; + pinentry = mkOption { + type = types.nullOr types.package; + example = lib.literalExpression "pkgs.pinentry-gnome3"; + default = null; + description = '' + Which pinentry interface to use. Beware that + `pinentry-gnome3` may not work on non-Gnome + systems. You can fix it by adding the following to your + system configuration: + ```nix + services.dbus.packages = [ pkgs.gcr ]; + ``` + ''; + # we want the program in the config + apply = val: if val == null then val else lib.getExe val; }; }; + }; in { meta.maintainers = with lib.hm.maintainers; [ ambroisie ]; - options.programs.rbw = with lib; { - enable = mkEnableOption "rbw, a CLI Bitwarden client"; + options.programs.rbw = { + enable = lib.mkEnableOption "rbw, a CLI Bitwarden client"; package = mkOption { type = types.package; default = pkgs.rbw; - defaultText = literalExpression "pkgs.rbw"; + defaultText = lib.literalExpression "pkgs.rbw"; description = '' Package providing the {command}`rbw` tool and its {command}`rbw-agent` daemon. @@ -77,7 +76,7 @@ in { settings = mkOption { type = types.nullOr settingsModule; default = null; - example = literalExpression '' + example = lib.literalExpression '' { email = "name@example.com"; lock_timeout = 300; diff --git a/modules/programs/readline.nix b/modules/programs/readline.nix index 56e8ea98..24607c23 100644 --- a/modules/programs/readline.nix +++ b/modules/programs/readline.nix @@ -1,8 +1,6 @@ -{ config, lib, pkgs, ... }: - -with lib; - +{ config, lib, ... }: let + inherit (lib) mkIf mkOption types; cfg = config.programs.readline; @@ -13,18 +11,18 @@ let "on" else if v == false then "off" - else if isInt v then + else if lib.isInt v then toString v - else if isString v then + else if lib.isString v then v else - abort ("values ${toPretty v} is of unsupported type"); + abort "values ${lib.toPretty v} is of unsupported type"; in "set ${n} ${mkValueStr v}"; mkBindingStr = k: v: let isKeynameNotKeyseq = k: - builtins.elem (builtins.head (lib.splitString "-" (toLower k))) [ + builtins.elem (builtins.head (lib.splitString "-" (lib.toLower k))) [ "control" "meta" ]; @@ -32,12 +30,12 @@ let in { options.programs.readline = { - enable = mkEnableOption "readline"; + enable = lib.mkEnableOption "readline"; bindings = mkOption { default = { }; type = types.attrsOf types.str; - example = literalExpression '' + example = lib.literalExpression '' { "\\C-h" = "backward-kill-word"; } ''; description = "Readline bindings."; @@ -70,17 +68,17 @@ in { config = mkIf cfg.enable (let finalConfig = let - configStr = concatStringsSep "\n" - (optional cfg.includeSystemConfig "$include /etc/inputrc" - ++ mapAttrsToList mkSetVariableStr cfg.variables - ++ mapAttrsToList mkBindingStr cfg.bindings); + configStr = lib.concatStringsSep "\n" + (lib.optional cfg.includeSystemConfig "$include /etc/inputrc" + ++ lib.mapAttrsToList mkSetVariableStr cfg.variables + ++ lib.mapAttrsToList mkBindingStr cfg.bindings); in '' # Generated by Home Manager. ${configStr} ${cfg.extraConfig} ''; - in mkMerge [ + in lib.mkMerge [ (mkIf (!config.home.preferXdgDirectories) { home.file.".inputrc".text = finalConfig; }) diff --git a/modules/programs/ripgrep.nix b/modules/programs/ripgrep.nix index 3154a770..42eb9c4c 100644 --- a/modules/programs/ripgrep.nix +++ b/modules/programs/ripgrep.nix @@ -1,7 +1,4 @@ { config, lib, pkgs, ... }: - -with lib; - let cfg = config.programs.ripgrep; in { meta.maintainers = @@ -9,12 +6,12 @@ in { options = { programs.ripgrep = { - enable = mkEnableOption "Ripgrep"; + enable = lib.mkEnableOption "Ripgrep"; - package = mkPackageOption pkgs "ripgrep" { nullable = true; }; + package = lib.mkPackageOption pkgs "ripgrep" { nullable = true; }; - arguments = mkOption { - type = with types; listOf str; + arguments = lib.mkOption { + type = with lib.types; listOf str; default = [ ]; example = [ "--max-columns-preview" "--colors=line:style:bold" ]; description = '' @@ -28,11 +25,11 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home = let configPath = "${config.xdg.configHome}/ripgrep/ripgreprc"; - in mkMerge [ + in lib.mkMerge [ { packages = lib.mkIf (cfg.package != null) [ cfg.package ]; } - (mkIf (cfg.arguments != [ ]) { + (lib.mkIf (cfg.arguments != [ ]) { file."${configPath}".text = lib.concatLines cfg.arguments; sessionVariables."RIPGREP_CONFIG_PATH" = configPath; diff --git a/modules/programs/rofi-pass.nix b/modules/programs/rofi-pass.nix index d5208d50..8e3d13e7 100644 --- a/modules/programs/rofi-pass.nix +++ b/modules/programs/rofi-pass.nix @@ -1,23 +1,20 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) types; cfg = config.programs.rofi.pass; - in { - meta.maintainers = with maintainers; [ seylerius robwalt ]; + meta.maintainers = with lib.maintainers; [ seylerius robwalt ]; options.programs.rofi.pass = { - enable = mkEnableOption "rofi integration with password-store"; + enable = lib.mkEnableOption "rofi integration with password-store"; - package = mkPackageOption pkgs "rofi-pass" { + package = lib.mkPackageOption pkgs "rofi-pass" { nullable = true; example = "pkgs.rofi-pass-wayland"; }; - stores = mkOption { + stores = lib.mkOption { type = types.listOf types.str; default = [ ]; description = '' @@ -25,7 +22,7 @@ in { ''; }; - extraConfig = mkOption { + extraConfig = lib.mkOption { type = types.lines; default = ""; example = '' @@ -41,11 +38,12 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; - xdg.configFile."rofi-pass/config".text = optionalString (cfg.stores != [ ]) - ("root=" + (concatStringsSep ":" cfg.stores) + "\n") + cfg.extraConfig - + optionalString (cfg.extraConfig != "") "\n"; + xdg.configFile."rofi-pass/config".text = + lib.optionalString (cfg.stores != [ ]) + ("root=" + (lib.concatStringsSep ":" cfg.stores) + "\n") + cfg.extraConfig + + lib.optionalString (cfg.extraConfig != "") "\n"; }; } diff --git a/modules/programs/rofi.nix b/modules/programs/rofi.nix index bf11201b..a89e53ba 100644 --- a/modules/programs/rofi.nix +++ b/modules/programs/rofi.nix @@ -1,22 +1,20 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) filterAttrs isAttrs isString literalExpression mkOption types; cfg = config.programs.rofi; mkValueString = value: - if isBool value then + if lib.isBool value then if value then "true" else "false" - else if isInt value then + else if lib.isInt value then toString value else if (value._type or "") == "literal" then value.value else if isString value then ''"${value}"'' - else if isList value then - "[ ${strings.concatStringsSep "," (map mkValueString value)} ]" + else if lib.isList value then + "[ ${lib.strings.concatStringsSep "," (map mkValueString value)} ]" else abort "Unhandled value type ${builtins.typeOf value}"; @@ -27,7 +25,8 @@ let mkRasiSection = name: value: if isAttrs value then let - toRasiKeyValue = generators.toKeyValue { mkKeyValue = mkKeyValue { }; }; + toRasiKeyValue = + lib.generators.toKeyValue { mkKeyValue = mkKeyValue { }; }; # Remove null values so the resulting config does not have empty lines configStr = toRasiKeyValue (filterAttrs (_: v: v != null) value); in '' @@ -41,7 +40,8 @@ let } name value) + "\n"; toRasi = attrs: - concatStringsSep "\n" (concatMap (mapAttrsToList mkRasiSection) [ + lib.concatStringsSep "\n" + (lib.concatMap (lib.mapAttrsToList mkRasiSection) [ (filterAttrs (n: _: n == "@theme") attrs) (filterAttrs (n: _: n == "@import") attrs) (removeAttrs attrs [ "@theme" "@import" ]) @@ -90,7 +90,7 @@ let else if (isAttrs cfg.theme) then "custom" else - removeSuffix ".rasi" (baseNameOf cfg.theme); + lib.removeSuffix ".rasi" (baseNameOf cfg.theme); themePath = if (isString cfg.theme) then null @@ -101,7 +101,7 @@ let in { options.programs.rofi = { - enable = mkEnableOption + enable = lib.mkEnableOption "Rofi: A window switcher, application launcher and dmenu replacement"; package = mkOption { @@ -156,7 +156,7 @@ in { location = mkOption { default = "center"; - type = types.enum (attrNames locationsMap); + type = types.enum (lib.attrNames locationsMap); description = "The location rofi appears on the screen."; }; @@ -239,7 +239,7 @@ in { imports = let mkRemovedOptionRofi = option: - (mkRemovedOptionModule [ "programs" "rofi" option ] + (lib.mkRemovedOptionModule [ "programs" "rofi" option ] "Please use a Rofi theme instead."); in map mkRemovedOptionRofi [ "width" @@ -253,9 +253,11 @@ in { "colors" ]; - config = mkIf cfg.enable { - assertions = - [ (hm.assertions.assertPlatform "programs.rofi" pkgs platforms.linux) ]; + config = lib.mkIf cfg.enable { + assertions = [ + (lib.hm.assertions.assertPlatform "programs.rofi" pkgs + lib.platforms.linux) + ]; lib.formats.rasi.mkLiteral = value: { _type = "literal"; @@ -277,19 +279,20 @@ in { font = cfg.font; terminal = cfg.terminal; cycle = cfg.cycle; - location = (getAttr cfg.location locationsMap); + location = (lib.getAttr cfg.location locationsMap); xoffset = cfg.xoffset; yoffset = cfg.yoffset; } // cfg.extraConfig); # @theme must go after configuration but attrs are output in alphabetical order ('@' first) - } + (optionalString (themeName != null) (toRasi { "@theme" = themeName; })); + } + (lib.optionalString (themeName != null) + (toRasi { "@theme" = themeName; })); - xdg.dataFile = mkIf (themePath != null) (if themePath == "custom" then { + xdg.dataFile = lib.mkIf (themePath != null) (if themePath == "custom" then { "rofi/themes/${themeName}.rasi".text = toRasi cfg.theme; } else { "rofi/themes/${themeName}.rasi".source = themePath; }); }; - meta.maintainers = with maintainers; [ thiagokokada ]; + meta.maintainers = with lib.maintainers; [ thiagokokada ]; } diff --git a/modules/programs/rtorrent.nix b/modules/programs/rtorrent.nix index 35c245a2..912a8bea 100644 --- a/modules/programs/rtorrent.nix +++ b/modules/programs/rtorrent.nix @@ -1,25 +1,19 @@ { config, lib, pkgs, ... }: - -with lib; - -let - - cfg = config.programs.rtorrent; - +let cfg = config.programs.rtorrent; in { meta.maintainers = [ ]; imports = [ - (mkRenamedOptionModule # \ + (lib.mkRenamedOptionModule # \ [ "programs" "rtorrent" "settings" ] # \ [ "programs" "rtorrent" "extraConfig" ]) ]; options.programs.rtorrent = { - enable = mkEnableOption "rTorrent"; + enable = lib.mkEnableOption "rTorrent"; - extraConfig = mkOption { - type = types.lines; + extraConfig = lib.mkOption { + type = lib.types.lines; default = ""; description = '' Configuration written to @@ -31,10 +25,10 @@ in { }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ pkgs.rtorrent ]; xdg.configFile."rtorrent/rtorrent.rc" = - mkIf (cfg.extraConfig != "") { text = cfg.extraConfig; }; + lib.mkIf (cfg.extraConfig != "") { text = cfg.extraConfig; }; }; } diff --git a/modules/programs/ruff.nix b/modules/programs/ruff.nix index 4ae80ebd..71a45f51 100644 --- a/modules/programs/ruff.nix +++ b/modules/programs/ruff.nix @@ -1,7 +1,4 @@ { config, lib, pkgs, ... }: - -with lib; - let cfg = config.programs.ruff; @@ -9,15 +6,15 @@ let settingsFormat = pkgs.formats.toml { }; in { - meta.maintainers = [ hm.maintainers.GaetanLepage ]; + meta.maintainers = [ lib.hm.maintainers.GaetanLepage ]; options.programs.ruff = { - enable = mkEnableOption + enable = lib.mkEnableOption "ruff, an extremely fast Python linter and code formatter, written in Rust"; - package = mkPackageOption pkgs "ruff" { nullable = true; }; + package = lib.mkPackageOption pkgs "ruff" { nullable = true; }; - settings = mkOption { + settings = lib.mkOption { type = settingsFormat.type; example = lib.literalExpression '' { @@ -36,7 +33,7 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; xdg.configFile."ruff/ruff.toml".source = diff --git a/modules/programs/sapling.nix b/modules/programs/sapling.nix index 4e27aaa8..eea6679a 100644 --- a/modules/programs/sapling.nix +++ b/modules/programs/sapling.nix @@ -1,21 +1,19 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkIf mkOption types; cfg = config.programs.sapling; iniFormat = pkgs.formats.ini { }; in { - meta.maintainers = [ maintainers.pbar ]; + meta.maintainers = [ lib.maintainers.pbar ]; options = { programs.sapling = { - enable = mkEnableOption "Sapling"; + enable = lib.mkEnableOption "Sapling"; - package = mkPackageOption pkgs "sapling" { nullable = true; }; + package = lib.mkPackageOption pkgs "sapling" { nullable = true; }; userName = mkOption { type = types.str; @@ -46,7 +44,7 @@ in { }; }; - config = mkIf cfg.enable (mkMerge [ + config = mkIf cfg.enable (lib.mkMerge [ { home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; diff --git a/modules/programs/sbt.nix b/modules/programs/sbt.nix index 62276829..7f4bcdb9 100644 --- a/modules/programs/sbt.nix +++ b/modules/programs/sbt.nix @@ -1,8 +1,7 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) + concatStringsSep concatStrings literalExpression mkIf mkOption types; renderPlugin = plugin: '' addSbtPlugin("${plugin.org}" % "${plugin.artifact}" % "${plugin.version}") @@ -17,13 +16,14 @@ let renderCredentials = creds: '' import scala.sys.process._ - ${concatStrings (imap0 renderCredential creds)}''; + ${concatStrings (lib.imap0 renderCredential creds)}''; renderRepository = value: - if isString value then '' + if lib.isString value then '' ${value} '' else '' - ${concatStrings (mapAttrsToList (name: value: "${name}: ${value}") value)} + ${concatStrings + (lib.mapAttrsToList (name: value: "${name}: ${value}") value)} ''; renderRepositories = repos: '' @@ -83,14 +83,14 @@ let in { imports = [ - (mkRemovedOptionModule [ "programs" "sbt" "baseConfigPath" ] + (lib.mkRemovedOptionModule [ "programs" "sbt" "baseConfigPath" ] "Use programs.sbt.baseUserConfigPath instead, but note that the semantics are slightly different.") ]; - meta.maintainers = [ maintainers.kubukoz ]; + meta.maintainers = [ lib.maintainers.kubukoz ]; options.programs.sbt = { - enable = mkEnableOption "sbt"; + enable = lib.mkEnableOption "sbt"; package = mkOption { type = types.package; @@ -194,7 +194,7 @@ in { }; }; - config = mkIf cfg.enable (mkMerge [ + config = mkIf cfg.enable (lib.mkMerge [ { home.packages = [ cfg.package ]; } (mkIf (cfg.plugins != [ ] || cfg.pluginsExtra != [ ]) { diff --git a/modules/programs/scmpuff.nix b/modules/programs/scmpuff.nix index 33642a35..fc47af16 100644 --- a/modules/programs/scmpuff.nix +++ b/modules/programs/scmpuff.nix @@ -1,18 +1,20 @@ { config, lib, pkgs, ... }: -with lib; -let cfg = config.programs.scmpuff; +let + inherit (lib) mkIf; + + cfg = config.programs.scmpuff; in { - meta.maintainers = [ maintainers.cpcloud ]; + meta.maintainers = [ lib.maintainers.cpcloud ]; options.programs.scmpuff = { - enable = mkEnableOption '' + enable = lib.mkEnableOption '' scmpuff, a command line tool that allows you to work quicker with Git by substituting numeric shortcuts for files''; - package = mkOption { - type = types.package; + package = lib.mkOption { + type = lib.types.package; default = pkgs.scmpuff; - defaultText = literalExpression "pkgs.scmpuff"; + defaultText = lib.literalExpression "pkgs.scmpuff"; description = "Package providing the {command}`scmpuff` tool."; }; @@ -25,9 +27,9 @@ in { enableZshIntegration = lib.hm.shell.mkZshIntegrationOption { inherit config; }; - enableAliases = mkOption { + enableAliases = lib.mkOption { default = true; - type = types.bool; + type = lib.types.bool; description = '' Whether to enable aliases (e.g. gs, ga, gd, gco). ''; @@ -36,8 +38,8 @@ in { config = mkIf cfg.enable (let mkArgs = shell: - concatStringsSep " " ([ "--shell=${shell}" ] - ++ optional (!cfg.enableAliases) "--aliases=false"); + lib.concatStringsSep " " ([ "--shell=${shell}" ] + ++ lib.optional (!cfg.enableAliases) "--aliases=false"); in { home.packages = [ cfg.package ]; @@ -50,7 +52,7 @@ in { ''; programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration - (mkAfter '' + (lib.mkAfter '' ${cfg.package}/bin/scmpuff init ${mkArgs "fish"} | source ''); }); diff --git a/modules/programs/senpai.nix b/modules/programs/senpai.nix index 1aaac393..67d59d33 100644 --- a/modules/programs/senpai.nix +++ b/modules/programs/senpai.nix @@ -1,15 +1,15 @@ { config, lib, pkgs, ... }: +let + inherit (lib) mkOption types; -with lib; - -let cfg = config.programs.senpai; + cfg = config.programs.senpai; in { options.programs.senpai = { - enable = mkEnableOption "senpai"; + enable = lib.mkEnableOption "senpai"; package = mkOption { type = types.package; default = pkgs.senpai; - defaultText = literalExpression "pkgs.senpai"; + defaultText = lib.literalExpression "pkgs.senpai"; description = "The `senpai` package to use."; }; config = mkOption { @@ -64,7 +64,7 @@ in { }; }; }; - example = literalExpression '' + example = lib.literalExpression '' { address = "libera.chat:6697"; nickname = "nicholas"; @@ -78,7 +78,7 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = with cfg.config; [ { assertion = !isNull password-cmd -> isNull password; @@ -102,5 +102,5 @@ in { lib.hm.generators.toSCFG { } cfg.config; }; - meta.maintainers = [ hm.maintainers.malvo ]; + meta.maintainers = [ lib.hm.maintainers.malvo ]; } diff --git a/modules/programs/sftpman.nix b/modules/programs/sftpman.nix index 3a8ba5ee..5c23acda 100644 --- a/modules/programs/sftpman.nix +++ b/modules/programs/sftpman.nix @@ -1,8 +1,7 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; + cfg = config.programs.sftpman; jsonFormat = pkgs.formats.json { }; @@ -67,13 +66,13 @@ let }; }; in { - meta.maintainers = with maintainers; [ fugi ]; + meta.maintainers = with lib.maintainers; [ fugi ]; options.programs.sftpman = { - enable = mkEnableOption + enable = lib.mkEnableOption "sftpman, an application that handles sshfs/sftp file systems mounting"; - package = mkPackageOption pkgs "sftpman" { nullable = true; }; + package = lib.mkPackageOption pkgs "sftpman" { nullable = true; }; defaultSshKey = mkOption { type = types.nullOr types.str; @@ -92,13 +91,15 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (let hasMissingKey = _: mount: mount.authType == "publickey" && mount.sshKey == null; - mountsWithMissingKey = attrNames (filterAttrs hasMissingKey cfg.mounts); - mountsWithMissingKeyStr = concatStringsSep ", " mountsWithMissingKey; + mountsWithMissingKey = + lib.attrNames (lib.filterAttrs hasMissingKey cfg.mounts); + mountsWithMissingKeyStr = + lib.concatStringsSep ", " mountsWithMissingKey; in { assertion = mountsWithMissingKey == [ ]; message = '' @@ -109,8 +110,8 @@ in { home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; - xdg.configFile = mapAttrs' (name: value: - nameValuePair "sftpman/mounts/${name}.json" { + xdg.configFile = lib.mapAttrs' (name: value: + lib.nameValuePair "sftpman/mounts/${name}.json" { source = jsonFormat.generate "sftpman-${name}.json" (value // { id = name; }); }) cfg.mounts; diff --git a/modules/programs/sioyek.nix b/modules/programs/sioyek.nix index 04a30973..b99663ea 100644 --- a/modules/programs/sioyek.nix +++ b/modules/programs/sioyek.nix @@ -1,12 +1,10 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) literalExpression mkIf mkOption types; cfg = config.programs.sioyek; - renderConfig = generators.toKeyValue { + renderConfig = lib.generators.toKeyValue { mkKeyValue = key: value: "${key} ${value}"; listsAsDuplicateKeys = true; }; @@ -14,7 +12,7 @@ let in { options = { programs.sioyek = { - enable = mkEnableOption + enable = lib.mkEnableOption "Sioyek, a PDF viewer designed for reading research papers and technical books"; package = mkOption { @@ -66,7 +64,7 @@ in { }; }; - config = mkIf cfg.enable (mkMerge [ + config = mkIf cfg.enable (lib.mkMerge [ { home.packages = [ cfg.package ]; } (mkIf (cfg.config != { }) { xdg.configFile."sioyek/prefs_user.config".text = renderConfig cfg.config; @@ -76,5 +74,5 @@ in { }) ]); - meta.maintainers = [ hm.maintainers.podocarp ]; + meta.maintainers = [ lib.hm.maintainers.podocarp ]; } diff --git a/modules/programs/skim.nix b/modules/programs/skim.nix index 4c221548..8e694e06 100644 --- a/modules/programs/skim.nix +++ b/modules/programs/skim.nix @@ -1,19 +1,17 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkIf mkOption types; cfg = config.programs.skim; in { options.programs.skim = { - enable = mkEnableOption "skim - a command-line fuzzy finder"; + enable = lib.mkEnableOption "skim - a command-line fuzzy finder"; package = mkOption { type = types.package; default = pkgs.skim; - defaultText = literalExpression "pkgs.skim"; + defaultText = lib.literalExpression "pkgs.skim"; description = "Package providing the {command}`skim` tool."; }; @@ -96,8 +94,8 @@ in { config = mkIf cfg.enable { home.packages = [ cfg.package ]; - home.sessionVariables = mapAttrs (n: v: toString v) - (filterAttrs (n: v: v != [ ] && v != null) { + home.sessionVariables = lib.mapAttrs (n: v: toString v) + (lib.filterAttrs (n: v: v != [ ] && v != null) { SKIM_ALT_C_COMMAND = cfg.changeDirWidgetCommand; SKIM_ALT_C_OPTS = cfg.changeDirWidgetOptions; SKIM_CTRL_R_OPTS = cfg.historyWidgetOptions; diff --git a/modules/programs/sm64ex.nix b/modules/programs/sm64ex.nix index a005484c..c98df4f9 100644 --- a/modules/programs/sm64ex.nix +++ b/modules/programs/sm64ex.nix @@ -1,15 +1,13 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) literalExpression mkOption optionalAttrs types; + cfg = config.programs.sm64ex; # This is required for tests, we cannot overwrite the dummy package. package = if cfg.region == null && cfg.baserom == null && cfg.extraCompileFlags == null then cfg.package - else cfg.package.override (attrs: { } // optionalAttrs (cfg.region != null) { region = cfg.region; } @@ -20,10 +18,10 @@ let mkConfig = key: value: let - generatedValue = if isBool value then + generatedValue = if lib.isBool value then (if value then "true" else "false") - else if isList value then - concatStringsSep " " value + else if lib.isList value then + lib.concatStringsSep " " value else toString value; in "${key} ${generatedValue}"; @@ -32,7 +30,7 @@ in { meta.maintainers = [ ]; options.programs.sm64ex = { - enable = mkEnableOption "sm64ex"; + enable = lib.mkEnableOption "sm64ex"; package = lib.mkPackageOption pkgs "sm64ex" { nullable = true; }; @@ -113,12 +111,12 @@ in { }; config = let - configFile = optionals (cfg.settings != null) - (concatStringsSep "\n" ((mapAttrsToList mkConfig cfg.settings))); - in mkIf cfg.enable { + configFile = lib.optionals (cfg.settings != null) + (lib.concatStringsSep "\n" (lib.mapAttrsToList mkConfig cfg.settings)); + in lib.mkIf cfg.enable { home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; xdg.dataFile."sm64pc/sm64config.txt" = - mkIf (cfg.settings != null) { text = configFile; }; + lib.mkIf (cfg.settings != null) { text = configFile; }; }; } diff --git a/modules/programs/sqls.nix b/modules/programs/sqls.nix index aaa161a7..3a5af813 100644 --- a/modules/programs/sqls.nix +++ b/modules/programs/sqls.nix @@ -1,23 +1,18 @@ { config, lib, pkgs, ... }: - -with lib; - let - cfg = config.programs.sqls; yamlFormat = pkgs.formats.yaml { }; - in { meta.maintainers = [ ]; options.programs.sqls = { - enable = mkEnableOption "sqls, a SQL language server written in Go"; + enable = lib.mkEnableOption "sqls, a SQL language server written in Go"; - settings = mkOption { + settings = lib.mkOption { type = yamlFormat.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { lowercaseKeywords = true; connections = [ @@ -37,10 +32,10 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ pkgs.sqls ]; - xdg.configFile."sqls/config.yml" = mkIf (cfg.settings != { }) { + xdg.configFile."sqls/config.yml" = lib.mkIf (cfg.settings != { }) { source = yamlFormat.generate "sqls-config" cfg.settings; }; }; diff --git a/modules/programs/ssh.nix b/modules/programs/ssh.nix index e062b232..4eb009ed 100644 --- a/modules/programs/ssh.nix +++ b/modules/programs/ssh.nix @@ -1,8 +1,7 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) + concatStringsSep literalExpression mapAttrsToList mkOption optional types; cfg = config.programs.ssh; @@ -18,7 +17,7 @@ let mkSetEnvStr = envStr: unwords (mapAttrsToList - (name: value: ''${name}="${escape [ ''"'' "\\" ] (toString value)}"'') + (name: value: ''${name}="${lib.escape [ ''"'' "\\" ] (toString value)}"'') envStr); bindOptions = { @@ -142,7 +141,8 @@ let identityFile = mkOption { type = with types; either (listOf str) (nullOr str); default = [ ]; - apply = p: if p == null then [ ] else if isString p then [ p ] else p; + apply = p: + if p == null then [ ] else if lib.isString p then [ p ] else p; description = '' Specifies files from which the user identity is read. Identities will be tried in the given order. @@ -227,7 +227,8 @@ let certificateFile = mkOption { type = with types; either (listOf str) (nullOr str); default = [ ]; - apply = p: if p == null then [ ] else if isString p then [ p ] else p; + apply = p: + if p == null then [ ] else if lib.isString p then [ p ] else p; description = '' Specifies files from which the user certificate is read. ''; @@ -337,12 +338,12 @@ let ++ mapAttrsToList (n: v: " ${n} ${v}") cf.extraOptions); in { - meta.maintainers = [ maintainers.rycee ]; + meta.maintainers = [ lib.maintainers.rycee ]; options.programs.ssh = { - enable = mkEnableOption "SSH client configuration"; + enable = lib.mkEnableOption "SSH client configuration"; - package = mkPackageOption pkgs "openssh" { + package = lib.mkPackageOption pkgs "openssh" { nullable = true; default = null; extraDescription = @@ -469,7 +470,7 @@ in { }; matchBlocks = mkOption { - type = hm.types.dagOf matchBlockModule; + type = lib.hm.types.dagOf matchBlockModule; default = { }; example = literalExpression '' { @@ -495,11 +496,11 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [{ assertion = let # `builtins.any`/`lib.lists.any` does not return `true` if there are no elements. - any' = pred: items: if items == [ ] then true else any pred items; + any' = pred: items: if items == [ ] then true else lib.any pred items; # Check that if `entry.address` is defined, and is a path, that `entry.port` has not # been defined. noPathWithPort = entry: @@ -510,7 +511,7 @@ in { checkLocal = block: any' checkBindAndHost block.localForwards; checkRemote = block: any' checkBindAndHost block.remoteForwards; checkMatchBlock = block: - all (fn: fn block) [ checkLocal checkRemote checkDynamic ]; + lib.all (fn: fn block) [ checkLocal checkRemote checkDynamic ]; in any' checkMatchBlock (map (block: block.data) (builtins.attrValues cfg.matchBlocks)); message = "Forwarded paths cannot have ports."; @@ -519,7 +520,7 @@ in { home.packages = optional (cfg.package != null) cfg.package; home.file.".ssh/config".text = let - sortedMatchBlocks = hm.dag.topoSort cfg.matchBlocks; + sortedMatchBlocks = lib.hm.dag.topoSort cfg.matchBlocks; sortedMatchBlocksStr = builtins.toJSON sortedMatchBlocks; matchBlocks = if sortedMatchBlocks ? result then sortedMatchBlocks.result @@ -544,13 +545,13 @@ in { ControlPath ${cfg.controlPath} ControlPersist ${cfg.controlPersist} - ${replaceStrings [ "\n" ] [ "\n " ] cfg.extraConfig} + ${lib.replaceStrings [ "\n" ] [ "\n " ] cfg.extraConfig} ''; warnings = mapAttrsToList (n: v: '' The SSH config match block `programs.ssh.matchBlocks.${n}` sets both of the host and match options. The match option takes precedence.'') - (filterAttrs (n: v: v.data.host != null && v.data.match != null) + (lib.filterAttrs (n: v: v.data.host != null && v.data.match != null) cfg.matchBlocks); }; } diff --git a/modules/programs/starship.nix b/modules/programs/starship.nix index c3b2a61a..0b6cbbc1 100644 --- a/modules/programs/starship.nix +++ b/modules/programs/starship.nix @@ -1,8 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkIf mkOption types; cfg = config.programs.starship; @@ -16,19 +14,19 @@ in { meta.maintainers = [ ]; options.programs.starship = { - enable = mkEnableOption "starship"; + enable = lib.mkEnableOption "starship"; package = mkOption { type = types.package; default = pkgs.starship; - defaultText = literalExpression "pkgs.starship"; + defaultText = lib.literalExpression "pkgs.starship"; description = "The package to use for the starship binary."; }; settings = mkOption { type = tomlFormat.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { add_newline = false; format = lib.concatStrings [ diff --git a/modules/programs/swaylock.nix b/modules/programs/swaylock.nix index dcfd30c7..5a234098 100644 --- a/modules/programs/swaylock.nix +++ b/modules/programs/swaylock.nix @@ -1,17 +1,14 @@ { pkgs, config, lib, ... }: - -with lib; - let cfg = config.programs.swaylock; in { - meta.maintainers = [ hm.maintainers.rcerc ]; + meta.maintainers = [ lib.hm.maintainers.rcerc ]; options.programs.swaylock = { - enable = mkOption { + enable = lib.mkOption { type = lib.types.bool; - default = versionOlder config.home.stateVersion "23.05" + default = lib.versionOlder config.home.stateVersion "23.05" && (cfg.settings != { }); - defaultText = literalExpression '' + defaultText = lib.literalExpression '' true if state version < 23.05 and settings ≠ { }, false otherwise ''; @@ -33,10 +30,10 @@ in { ''; }; - package = mkPackageOption pkgs "swaylock" { nullable = true; }; + package = lib.mkPackageOption pkgs "swaylock" { nullable = true; }; - settings = mkOption { - type = with types; attrsOf (oneOf [ bool float int path str ]); + settings = lib.mkOption { + type = with lib.types; attrsOf (oneOf [ bool float int path str ]); default = { }; description = '' Default arguments to {command}`swaylock`. An empty set @@ -53,7 +50,7 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ (lib.hm.assertions.assertPlatform "programs.swaylock" pkgs lib.platforms.linux) @@ -61,8 +58,8 @@ in { home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; - xdg.configFile."swaylock/config" = mkIf (cfg.settings != { }) { - text = concatStrings (mapAttrsToList (n: v: + xdg.configFile."swaylock/config" = lib.mkIf (cfg.settings != { }) { + text = lib.concatStrings (lib.mapAttrsToList (n: v: if v == false then "" else diff --git a/modules/programs/swayr.nix b/modules/programs/swayr.nix index c45ed063..3a4aeee9 100644 --- a/modules/programs/swayr.nix +++ b/modules/programs/swayr.nix @@ -1,8 +1,7 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkIf mkOption types; + cfg = config.programs.swayr; tomlFormat = pkgs.formats.toml { }; configFile = tomlFormat.generate "config.toml" cfg.settings; @@ -14,12 +13,12 @@ in { meta.maintainers = [ lib.hm.maintainers."9p4" ]; options.programs.swayr = { - enable = mkEnableOption "the swayr service"; + enable = lib.mkEnableOption "the swayr service"; settings = mkOption { type = types.nullOr tomlFormat.type; default = { }; - example = literalExpression '' + example = lib.literalExpression '' menu = { executable = "${pkgs.wofi}/bin/wofi"; args = [ @@ -89,7 +88,7 @@ in { ''; }; - systemd.enable = mkEnableOption "swayr systemd integration"; + systemd.enable = lib.mkEnableOption "swayr systemd integration"; systemd.target = mkOption { type = types.str; default = "graphical-session.target"; @@ -101,12 +100,12 @@ in { package = mkOption { type = types.package; default = pkgs.swayr; - defaultText = literalExpression "pkgs.swayr"; + defaultText = lib.literalExpression "pkgs.swayr"; description = "swayr package to use."; }; }; - config = mkIf cfg.enable (mkMerge [ + config = mkIf cfg.enable (lib.mkMerge [ { home.packages = [ cfg.package ]; diff --git a/modules/programs/taskwarrior.nix b/modules/programs/taskwarrior.nix index 8efeb136..1b2d4eb4 100644 --- a/modules/programs/taskwarrior.nix +++ b/modules/programs/taskwarrior.nix @@ -1,37 +1,34 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; cfg = config.programs.taskwarrior; formatValue = value: - if isBool value then + if lib.isBool value then if value then "true" else "false" - else if isList value then - concatMapStringsSep "," formatValue value + else if lib.isList value then + lib.concatMapStringsSep "," formatValue value else toString value; formatLine = key: value: "${key}=${formatValue value}"; formatSet = key: values: - (concatStringsSep "\n" - (mapAttrsToList (subKey: subValue: formatPair "${key}.${subKey}" subValue) - values)); + (lib.concatStringsSep "\n" (lib.mapAttrsToList + (subKey: subValue: formatPair "${key}.${subKey}" subValue) values)); formatPair = key: value: - if isAttrs value then formatSet key value else formatLine key value; + if lib.isAttrs value then formatSet key value else formatLine key value; in { options = { programs.taskwarrior = { - enable = mkEnableOption "Task Warrior"; + enable = lib.mkEnableOption "Task Warrior"; config = mkOption { type = types.attrsOf types.anything; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { confirmation = false; report.minimal.filter = "status:pending"; @@ -82,7 +79,7 @@ in { ''; }; - package = mkPackageOption pkgs "taskwarrior" { + package = lib.mkPackageOption pkgs "taskwarrior" { nullable = true; example = "pkgs.taskwarrior3"; }; @@ -92,35 +89,39 @@ in { config = let homeConf = "${config.xdg.configHome}/task/home-manager-taskrc"; userConf = "${config.xdg.configHome}/task/taskrc"; - in mkIf cfg.enable { + in lib.mkIf cfg.enable { home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; home.file."${homeConf}".text = '' data.location=${cfg.dataLocation} - ${optionalString (cfg.colorTheme != null) (if isString cfg.colorTheme then + ${lib.optionalString (cfg.colorTheme != null) + (if lib.isString cfg.colorTheme then "include ${cfg.colorTheme}.theme" else "include ${cfg.colorTheme}")} - ${concatStringsSep "\n" (mapAttrsToList formatPair cfg.config)} + ${lib.concatStringsSep "\n" (lib.mapAttrsToList formatPair cfg.config)} ${cfg.extraConfig} ''; - home.activation.regenDotTaskRc = hm.dag.entryAfter [ "writeBoundary" ] '' - verboseEcho "Ensuring generated taskwarrior config included in taskrc" + home.activation.regenDotTaskRc = + lib.hm.dag.entryAfter [ "writeBoundary" ] '' + verboseEcho "Ensuring generated taskwarrior config included in taskrc" - if [[ ! -s "${userConf}" ]]; then - # Ensure file's existence - if [[ -v DRY_RUN ]]; then - run echo "include ${homeConf}" ">" "${userConf}" - else - echo "include ${homeConf}" > "${userConf}" + if [[ ! -s "${userConf}" ]]; then + # Ensure file's existence + if [[ -v DRY_RUN ]]; then + run echo "include ${homeConf}" ">" "${userConf}" + else + echo "include ${homeConf}" > "${userConf}" + fi + elif ! grep -qF "include ${homeConf}" ${ + lib.escapeShellArg userConf + }; then + # Add include statement for Home Manager generated config. + run sed -i '1i include ${homeConf}' ${lib.escapeShellArg userConf} fi - elif ! grep -qF "include ${homeConf}" ${escapeShellArg userConf}; then - # Add include statement for Home Manager generated config. - run sed -i '1i include ${homeConf}' ${escapeShellArg userConf} - fi - ''; + ''; }; } diff --git a/modules/programs/tealdeer.nix b/modules/programs/tealdeer.nix index 6efc5aa3..8cb9afa7 100644 --- a/modules/programs/tealdeer.nix +++ b/modules/programs/tealdeer.nix @@ -1,7 +1,7 @@ { config, lib, pkgs, ... }: - -with lib; let + inherit (lib) mkIf mkOption types; + cfg = config.programs.tealdeer; configDir = if pkgs.stdenv.isDarwin then @@ -14,12 +14,12 @@ let settingsFormat = let updatesSection = types.submodule { options = { - auto_update = mkEnableOption "auto-update"; + auto_update = lib.mkEnableOption "auto-update"; auto_update_interval_hours = mkOption { type = types.ints.positive; default = 720; - example = literalExpression "24"; + example = lib.literalExpression "24"; description = '' Duration, since the last cache update, after which the cache will be refreshed. This parameter is ignored if {var}`auto_update` is set to `false`. @@ -42,10 +42,10 @@ let }; in { - meta.maintainers = [ hm.maintainers.pedorich-n ]; + meta.maintainers = [ lib.hm.maintainers.pedorich-n ]; imports = [ - (mkRemovedOptionModule [ "programs" "tealdeer" "updateOnActivation" ] '' + (lib.mkRemovedOptionModule [ "programs" "tealdeer" "updateOnActivation" ] '' Updating tealdeer's cache requires network access. The activation script should be fast and idempotent, so the option was removed. Please use @@ -57,12 +57,12 @@ in { ]; options.programs.tealdeer = { - enable = mkEnableOption "Tealdeer"; + enable = lib.mkEnableOption "Tealdeer"; settings = mkOption { type = types.nullOr settingsFormat; default = null; - example = literalExpression '' + example = lib.literalExpression '' { display = { compact = false; @@ -81,7 +81,7 @@ in { ''; }; - enableAutoUpdates = mkEnableOption "Auto updates" // { + enableAutoUpdates = lib.mkEnableOption "Auto updates" // { default = true; example = false; }; diff --git a/modules/programs/terminator.nix b/modules/programs/terminator.nix index 7c597fbf..647812eb 100644 --- a/modules/programs/terminator.nix +++ b/modules/programs/terminator.nix @@ -1,7 +1,4 @@ { config, lib, pkgs, ... }: - -with lib; - let cfg = config.programs.terminator; @@ -20,22 +17,22 @@ let toKey = depth: key: if depth == 0 then key else toKey (depth - 1) "[${key}]"; toConfigObjectLevel = depth: obj: - flatten (mapAttrsToList (key: val: - if isAttrs val then + lib.flatten (lib.mapAttrsToList (key: val: + if lib.isAttrs val then [ (toKey depth key) ] ++ toConfigObjectLevel (depth + 1) val else [ "${key} = ${toValue val}" ]) obj); - in obj: concatStringsSep "\n" (toConfigObjectLevel 1 obj); + in obj: lib.concatStringsSep "\n" (toConfigObjectLevel 1 obj); in { - meta.maintainers = [ maintainers.chisui ]; + meta.maintainers = [ lib.maintainers.chisui ]; options.programs.terminator = { - enable = mkEnableOption "terminator, a tiling terminal emulator"; + enable = lib.mkEnableOption "terminator, a tiling terminal emulator"; package = lib.mkPackageOption pkgs "terminator" { }; - config = mkOption { + config = lib.mkOption { default = { }; description = '' configuration for terminator. @@ -44,8 +41,8 @@ in { {manpage}`terminator_config(5)` man page. ''; - type = types.attrsOf types.anything; - example = literalExpression '' + type = lib.types.attrsOf lib.types.anything; + example = lib.literalExpression '' { global_config.borderless = true; profiles.default.background_color = "#002b36"; @@ -54,14 +51,15 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ - (hm.assertions.assertPlatform "programs.terminator" pkgs platforms.linux) + (lib.hm.assertions.assertPlatform "programs.terminator" pkgs + lib.platforms.linux) ]; home.packages = [ cfg.package ]; xdg.configFile."terminator/config" = - mkIf (cfg.config != { }) { text = toConfigObject cfg.config; }; + lib.mkIf (cfg.config != { }) { text = toConfigObject cfg.config; }; }; } diff --git a/modules/programs/termite.nix b/modules/programs/termite.nix index c0015dcb..810dcc57 100644 --- a/modules/programs/termite.nix +++ b/modules/programs/termite.nix @@ -1,15 +1,13 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; cfg = config.programs.termite; in { options = { programs.termite = { - enable = mkEnableOption "Termite VTE-based terminal"; + enable = lib.mkEnableOption "Termite VTE-based terminal"; allowBold = mkOption { default = null; @@ -43,7 +41,7 @@ in { ''; }; - enableVteIntegration = mkEnableOption "Shell VTE integration" // { + enableVteIntegration = lib.mkEnableOption "Shell VTE integration" // { default = true; }; @@ -323,7 +321,7 @@ in { lib.optionalString (val != null) "${name} = ${toString val}"; optionalString = name: val: lib.optionalString (val != null) "${name} = ${val}"; - in mkIf cfg.enable { + in lib.mkIf cfg.enable { home.packages = [ pkgs.termite ]; xdg.configFile."termite/config".text = '' [options] diff --git a/modules/programs/texlive.nix b/modules/programs/texlive.nix index bd17025d..bcced7af 100644 --- a/modules/programs/texlive.nix +++ b/modules/programs/texlive.nix @@ -1,8 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; cfg = config.programs.texlive; @@ -10,22 +8,22 @@ let texlivePkgs = cfg.extraPackages texlive; in { - meta.maintainers = [ maintainers.rycee ]; + meta.maintainers = [ lib.maintainers.rycee ]; options = { programs.texlive = { - enable = mkEnableOption "TeX Live"; + enable = lib.mkEnableOption "TeX Live"; packageSet = mkOption { default = pkgs.texlive; - defaultText = literalExpression "pkgs.texlive"; + defaultText = lib.literalExpression "pkgs.texlive"; description = "TeX Live package set to use."; }; extraPackages = mkOption { default = tpkgs: { inherit (tpkgs) collection-basic; }; defaultText = "tpkgs: { inherit (tpkgs) collection-basic; }"; - example = literalExpression '' + example = lib.literalExpression '' tpkgs: { inherit (tpkgs) collection-fontsrecommended algorithms; } ''; description = "Extra packages available to TeX Live."; @@ -39,7 +37,7 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [{ assertion = texlivePkgs != { }; message = "Must provide at least one extra package in" diff --git a/modules/programs/thefuck.nix b/modules/programs/thefuck.nix index 2561bf5f..ada4c1c4 100644 --- a/modules/programs/thefuck.nix +++ b/modules/programs/thefuck.nix @@ -1,17 +1,16 @@ { config, lib, pkgs, ... }: - -with lib; - -{ - meta.maintainers = [ hm.maintainers.ilaumjd ]; +let inherit (lib) mkIf; +in { + meta.maintainers = [ lib.hm.maintainers.ilaumjd ]; options.programs.thefuck = { - enable = mkEnableOption + enable = lib.mkEnableOption "thefuck - magnificent app that corrects your previous console command"; - package = mkPackageOption pkgs "thefuck" { }; + package = lib.mkPackageOption pkgs "thefuck" { }; - enableInstantMode = mkEnableOption "thefuck's experimental instant mode"; + enableInstantMode = + lib.mkEnableOption "thefuck's experimental instant mode"; enableBashIntegration = lib.hm.shell.mkBashIntegrationOption { inherit config; }; @@ -29,7 +28,7 @@ with lib; config = let cfg = config.programs.thefuck; - cliArgs = cli.toGNUCommandLineShell { } { + cliArgs = lib.cli.toGNUCommandLineShell { } { alias = true; enable-experimental-instant-mode = cfg.enableInstantMode; }; diff --git a/modules/programs/thunderbird.nix b/modules/programs/thunderbird.nix index d567ab44..0df3c0b2 100644 --- a/modules/programs/thunderbird.nix +++ b/modules/programs/thunderbird.nix @@ -1,8 +1,8 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) + attrValues concatStringsSep filter length literalExpression mapAttrsToList + mkIf mkOption mkOptionDefault optionalAttrs optionalString types; inherit (pkgs.stdenv.hostPlatform) isDarwin; cfg = config.programs.thunderbird; @@ -17,8 +17,8 @@ let moduleName = "programs.thunderbird"; - enabledAccounts = attrValues - (filterAttrs (_: a: a.thunderbird.enable) config.accounts.email.accounts); + enabledAccounts = attrValues (lib.filterAttrs (_: a: a.thunderbird.enable) + config.accounts.email.accounts); enabledAccountsWithId = map (a: a // { id = builtins.hashString "sha256" a.name; }) enabledAccounts; @@ -32,15 +32,15 @@ let thunderbirdConfigPath; profilesWithId = - imap0 (i: v: v // { id = toString i; }) (attrValues cfg.profiles); + lib.imap0 (i: v: v // { id = toString i; }) (attrValues cfg.profiles); - profilesIni = foldl recursiveUpdate { + profilesIni = lib.foldl lib.recursiveUpdate { General = { StartWithLastProfile = 1; } // lib.optionalAttrs (cfg.profileVersion != null) { Version = cfg.profileVersion; }; - } (flip map profilesWithId (profile: { + } (lib.flip map profilesWithId (profile: { "Profile${profile.id}" = { Name = profile.name; Path = if isDarwin then "Profiles/${profile.name}" else profile.name; @@ -150,7 +150,7 @@ let mkUserJs = prefs: extraPrefs: '' // Generated by Home Manager. - ${concatStrings (mapAttrsToList (name: value: '' + ${lib.concatStrings (mapAttrsToList (name: value: '' user_pref("${name}", ${builtins.toJSON value}); '') prefs)} ${extraPrefs} @@ -175,18 +175,18 @@ let '' version="9" logging="no" - '' + concatStrings (map (f: mkFilterToIniString f) filters); + '' + lib.concatStrings (map (f: mkFilterToIniString f) filters); getEmailAccountsForProfile = profileName: accounts: (filter (a: a.thunderbird.profiles == [ ] - || any (p: p == profileName) a.thunderbird.profiles) accounts); + || lib.any (p: p == profileName) a.thunderbird.profiles) accounts); in { - meta.maintainers = with hm.maintainers; [ d-dervishi jkarlson ]; + meta.maintainers = with lib.hm.maintainers; [ d-dervishi jkarlson ]; options = { programs.thunderbird = { - enable = mkEnableOption "Thunderbird"; + enable = lib.mkEnableOption "Thunderbird"; package = mkOption { type = types.package; @@ -214,143 +214,142 @@ in { }; profiles = mkOption { - type = with types; - attrsOf (submodule ({ config, name, ... }: { - options = { - name = mkOption { - type = types.str; - default = name; - readOnly = true; - description = "This profile's name."; - }; + type = types.attrsOf (types.submodule ({ config, name, ... }: { + options = { + name = mkOption { + type = types.str; + default = name; + readOnly = true; + description = "This profile's name."; + }; - isDefault = mkOption { - type = types.bool; - default = false; - example = true; - description = '' - Whether this is a default profile. There must be exactly one - default profile. - ''; - }; + isDefault = mkOption { + type = types.bool; + default = false; + example = true; + description = '' + Whether this is a default profile. There must be exactly one + default profile. + ''; + }; - feedAccounts = mkOption { - type = types.attrsOf (submodule ({ config, name, ... }: { - options = { - name = mkOption { - type = types.str; - default = name; - readOnly = true; - description = "This feed account's name."; + feedAccounts = mkOption { + type = types.attrsOf (types.submodule ({ config, name, ... }: { + options = { + name = mkOption { + type = types.str; + default = name; + readOnly = true; + description = "This feed account's name."; + }; + }; + })); + default = { }; + description = '' + Attribute set of feed accounts. Feeds themselves have to be + managed through Thunderbird's settings. This option allows + feeds to coexist with declaratively managed email accounts. + ''; + }; + + settings = mkOption { + type = thunderbirdJson; + default = { }; + example = literalExpression '' + { + "mail.spellcheck.inline" = false; + "mailnews.database.global.views.global.columns" = { + selectCol = { + visible = false; + ordinal = 1; + }; + threadCol = { + visible = true; + ordinal = 2; }; }; - })); - default = { }; - description = '' - Attribute set of feed accounts. Feeds themselves have to be - managed through Thunderbird's settings. This option allows - feeds to coexist with declaratively managed email accounts. - ''; - }; - - settings = mkOption { - type = thunderbirdJson; - default = { }; - example = literalExpression '' - { - "mail.spellcheck.inline" = false; - "mailnews.database.global.views.global.columns" = { - selectCol = { - visible = false; - ordinal = 1; - }; - threadCol = { - visible = true; - ordinal = 2; - }; - }; - } - ''; - description = '' - Preferences to add to this profile's - {file}`user.js`. - ''; - }; - - withExternalGnupg = mkOption { - type = types.bool; - default = false; - example = true; - description = "Allow using external GPG keys with GPGME."; - }; - - userChrome = mkOption { - type = types.lines; - default = ""; - description = "Custom Thunderbird user chrome CSS."; - example = '' - /* Hide tab bar in Thunderbird */ - #tabs-toolbar { - visibility: collapse !important; - } - ''; - }; - - userContent = mkOption { - type = types.lines; - default = ""; - description = "Custom Thunderbird user content CSS."; - example = '' - /* Hide scrollbar on Thunderbird pages */ - *{scrollbar-width:none !important} - ''; - }; - - extraConfig = mkOption { - type = types.lines; - default = ""; - description = '' - Extra preferences to add to {file}`user.js`. - ''; - }; - - search = mkOption { - type = types.submodule (args: - import ./firefox/profiles/search.nix { - inherit (args) config; - inherit lib pkgs; - appName = "Thunderbird"; - package = cfg.package; - modulePath = - [ "programs" "thunderbird" "profiles" name "search" ]; - profilePath = name; - }); - default = { }; - description = "Declarative search engine configuration."; - }; - - extensions = mkOption { - type = types.listOf types.package; - default = [ ]; - example = literalExpression '' - [ - pkgs.some-thunderbird-extension - ] - ''; - description = '' - List of ${name} add-on packages to install for this profile. - - Note that it is necessary to manually enable extensions - inside ${name} after the first installation. - - To automatically enable extensions add - `"extensions.autoDisableScopes" = 0;` - to - [{option}`${moduleName}.profiles..settings`](#opt-${moduleName}.profiles._name_.settings) - ''; - }; + } + ''; + description = '' + Preferences to add to this profile's + {file}`user.js`. + ''; }; - })); + + withExternalGnupg = mkOption { + type = types.bool; + default = false; + example = true; + description = "Allow using external GPG keys with GPGME."; + }; + + userChrome = mkOption { + type = types.lines; + default = ""; + description = "Custom Thunderbird user chrome CSS."; + example = '' + /* Hide tab bar in Thunderbird */ + #tabs-toolbar { + visibility: collapse !important; + } + ''; + }; + + userContent = mkOption { + type = types.lines; + default = ""; + description = "Custom Thunderbird user content CSS."; + example = '' + /* Hide scrollbar on Thunderbird pages */ + *{scrollbar-width:none !important} + ''; + }; + + extraConfig = mkOption { + type = types.lines; + default = ""; + description = '' + Extra preferences to add to {file}`user.js`. + ''; + }; + + search = mkOption { + type = types.submodule (args: + import ./firefox/profiles/search.nix { + inherit (args) config; + inherit lib pkgs; + appName = "Thunderbird"; + package = cfg.package; + modulePath = + [ "programs" "thunderbird" "profiles" name "search" ]; + profilePath = name; + }); + default = { }; + description = "Declarative search engine configuration."; + }; + + extensions = mkOption { + type = types.listOf types.package; + default = [ ]; + example = literalExpression '' + [ + pkgs.some-thunderbird-extension + ] + ''; + description = '' + List of ${name} add-on packages to install for this profile. + + Note that it is necessary to manually enable extensions + inside ${name} after the first installation. + + To automatically enable extensions add + `"extensions.autoDisableScopes" = 0;` + to + [{option}`${moduleName}.profiles..settings`](#opt-${moduleName}.profiles._name_.settings) + ''; + }; + }; + })); description = "Attribute set of Thunderbird profiles."; }; @@ -383,142 +382,141 @@ in { }; accounts.email.accounts = mkOption { - type = with types; - attrsOf (submodule ({ config, ... }: { - config.thunderbird = { - settings = lib.mkIf (config.flavor == "gmail.com") (id: { - "mail.smtpserver.smtp_${id}.authMethod" = - mkOptionDefault 10; # 10 = OAuth2 - "mail.server.server_${id}.authMethod" = - mkOptionDefault 10; # 10 = OAuth2 - "mail.server.server_${id}.socketType" = - mkOptionDefault 3; # SSL/TLS - "mail.server.server_${id}.is_gmail" = - mkOptionDefault true; # handle labels, trash, etc - }); + type = types.attrsOf (types.submodule ({ config, ... }: { + config.thunderbird = { + settings = lib.mkIf (config.flavor == "gmail.com") (id: { + "mail.smtpserver.smtp_${id}.authMethod" = + mkOptionDefault 10; # 10 = OAuth2 + "mail.server.server_${id}.authMethod" = + mkOptionDefault 10; # 10 = OAuth2 + "mail.server.server_${id}.socketType" = mkOptionDefault 3; # SSL/TLS + "mail.server.server_${id}.is_gmail" = + mkOptionDefault true; # handle labels, trash, etc + }); + }; + options.thunderbird = { + enable = + lib.mkEnableOption "the Thunderbird mail client for this account"; + + profiles = mkOption { + type = with types; listOf str; + default = [ ]; + example = literalExpression '' + [ "profile1" "profile2" ] + ''; + description = '' + List of Thunderbird profiles for which this account should be + enabled. If this list is empty (the default), this account will + be enabled for all declared profiles. + ''; }; - options.thunderbird = { - enable = - mkEnableOption "the Thunderbird mail client for this account"; - profiles = mkOption { - type = with types; listOf str; - default = [ ]; - example = literalExpression '' - [ "profile1" "profile2" ] - ''; - description = '' - List of Thunderbird profiles for which this account should be - enabled. If this list is empty (the default), this account will - be enabled for all declared profiles. - ''; - }; + settings = mkOption { + type = with types; functionTo (attrsOf (oneOf [ bool int str ])); + default = _: { }; + defaultText = literalExpression "_: { }"; + example = literalExpression '' + id: { + "mail.server.server_''${id}.check_new_mail" = false; + }; + ''; + description = '' + Extra settings to add to this Thunderbird account configuration. + The {var}`id` given as argument is an automatically + generated account identifier. + ''; + }; - settings = mkOption { - type = with types; functionTo (attrsOf (oneOf [ bool int str ])); - default = _: { }; - defaultText = literalExpression "_: { }"; - example = literalExpression '' - id: { - "mail.server.server_''${id}.check_new_mail" = false; - }; - ''; - description = '' - Extra settings to add to this Thunderbird account configuration. - The {var}`id` given as argument is an automatically - generated account identifier. - ''; - }; + perIdentitySettings = mkOption { + type = with types; functionTo (attrsOf (oneOf [ bool int str ])); + default = _: { }; + defaultText = literalExpression "_: { }"; + example = literalExpression '' + id: { + "mail.identity.id_''${id}.protectSubject" = false; + "mail.identity.id_''${id}.autoEncryptDrafts" = false; + }; + ''; + description = '' + Extra settings to add to each identity of this Thunderbird + account configuration. The {var}`id` given as + argument is an automatically generated identifier. + ''; + }; - perIdentitySettings = mkOption { - type = with types; functionTo (attrsOf (oneOf [ bool int str ])); - default = _: { }; - defaultText = literalExpression "_: { }"; - example = literalExpression '' - id: { - "mail.identity.id_''${id}.protectSubject" = false; - "mail.identity.id_''${id}.autoEncryptDrafts" = false; - }; - ''; - description = '' - Extra settings to add to each identity of this Thunderbird - account configuration. The {var}`id` given as - argument is an automatically generated identifier. - ''; - }; - - messageFilters = mkOption { - type = with types; - listOf (submodule { - options = { - name = mkOption { - type = str; - description = "Name for the filter."; - }; - enabled = mkOption { - type = bool; - default = true; - description = "Whether this filter is currently active."; - }; - type = mkOption { - type = str; - description = "Type for this filter."; - }; - action = mkOption { - type = str; - description = "Action to perform on matched messages."; - }; - actionValue = mkOption { - type = nullOr str; - default = null; - description = - "Argument passed to the filter action, e.g. a folder path."; - }; - condition = mkOption { - type = str; - description = "Condition to match messages against."; - }; - extraConfig = mkOption { - type = nullOr str; - default = null; - description = "Extra settings to apply to the filter"; - }; - text = mkOption { - type = nullOr str; - default = null; - description = '' - The raw text of the filter. - Note that this will override all other options. - ''; - }; + messageFilters = mkOption { + type = with types; + listOf (submodule { + options = { + name = mkOption { + type = str; + description = "Name for the filter."; }; - }); - default = [ ]; - defaultText = literalExpression "[ ]"; - example = literalExpression '' - [ - { - name = "Mark as Read on Archive"; - enabled = true; - type = "128"; - action = "Mark read"; - condition = "ALL"; - } - ] - ''; - description = '' - List of message filters to add to this Thunderbird account - configuration. - ''; - }; + enabled = mkOption { + type = bool; + default = true; + description = "Whether this filter is currently active."; + }; + type = mkOption { + type = str; + description = "Type for this filter."; + }; + action = mkOption { + type = str; + description = "Action to perform on matched messages."; + }; + actionValue = mkOption { + type = nullOr str; + default = null; + description = + "Argument passed to the filter action, e.g. a folder path."; + }; + condition = mkOption { + type = str; + description = "Condition to match messages against."; + }; + extraConfig = mkOption { + type = nullOr str; + default = null; + description = "Extra settings to apply to the filter"; + }; + text = mkOption { + type = nullOr str; + default = null; + description = '' + The raw text of the filter. + Note that this will override all other options. + ''; + }; + }; + }); + default = [ ]; + defaultText = literalExpression "[ ]"; + example = literalExpression '' + [ + { + name = "Mark as Read on Archive"; + enabled = true; + type = "128"; + action = "Mark read"; + condition = "ALL"; + } + ] + ''; + description = '' + List of message filters to add to this Thunderbird account + configuration. + ''; }; - })); + }; + })); }; }; config = mkIf cfg.enable { assertions = [ - (let defaults = catAttrs "name" (filter (a: a.isDefault) profilesWithId); + (let + defaults = lib.catAttrs "name" (filter (a: a.isDefault) profilesWithId); in { assertion = cfg.profiles == { } || length defaults == 1; message = "Must have exactly one default Thunderbird profile but found " @@ -527,11 +525,11 @@ in { }) (let - profiles = catAttrs "name" profilesWithId; + profiles = lib.catAttrs "name" profilesWithId; selectedProfiles = - concatMap (a: a.thunderbird.profiles) enabledAccounts; + lib.concatMap (a: a.thunderbird.profiles) enabledAccounts; in { - assertion = (intersectLists profiles selectedProfiles) + assertion = (lib.intersectLists profiles selectedProfiles) == selectedProfiles; message = "Cannot enable an account for a non-declared profile. " + "The declared profiles are " + (concatStringsSep "," profiles) @@ -540,25 +538,25 @@ in { }) ]; - warnings = optional (isDarwin && cfg.darwinSetupWarning) '' + warnings = lib.optional (isDarwin && cfg.darwinSetupWarning) '' Thunderbird packages are not yet supported on Darwin. You can still use this module to manage your accounts and profiles by setting 'programs.thunderbird.package' to a dummy value, for example using 'pkgs.runCommand'. ''; - home.packages = [ cfg.package ] - ++ optional (any (p: p.withExternalGnupg) (attrValues cfg.profiles)) - pkgs.gpgme; + home.packages = [ cfg.package ] ++ lib.optional + (lib.any (p: p.withExternalGnupg) (attrValues cfg.profiles)) pkgs.gpgme; mozilla.thunderbirdNativeMessagingHosts = [ cfg.package # package configured native messaging hosts (entire mail app actually) ] ++ cfg.nativeMessagingHosts; # user configured native messaging hosts - home.file = mkMerge ([{ - "${thunderbirdConfigPath}/profiles.ini" = - mkIf (cfg.profiles != { }) { text = generators.toINI { } profilesIni; }; - }] ++ flip mapAttrsToList cfg.profiles (name: profile: { + home.file = lib.mkMerge ([{ + "${thunderbirdConfigPath}/profiles.ini" = mkIf (cfg.profiles != { }) { + text = lib.generators.toINI { } profilesIni; + }; + }] ++ lib.flip mapAttrsToList cfg.profiles (name: profile: { "${thunderbirdProfilesPath}/${name}/chrome/userChrome.css" = mkIf (profile.userChrome != "") { text = profile.userChrome; }; diff --git a/modules/programs/tint2.nix b/modules/programs/tint2.nix index 7a1a7329..6b7abdcc 100644 --- a/modules/programs/tint2.nix +++ b/modules/programs/tint2.nix @@ -1,22 +1,19 @@ { config, lib, pkgs, ... }: - -with lib; - let cfg = config.programs.tint2; in { - meta.maintainers = [ hm.maintainers.CarlosLoboxyz ]; + meta.maintainers = [ lib.hm.maintainers.CarlosLoboxyz ]; options.programs.tint2 = { - enable = - mkEnableOption "tint2, a simple, unobtrusive and light panel for Xorg"; + enable = lib.mkEnableOption + "tint2, a simple, unobtrusive and light panel for Xorg"; package = lib.mkPackageOption pkgs "tint2" { }; - extraConfig = mkOption { - type = types.lines; + extraConfig = lib.mkOption { + type = lib.types.lines; default = ""; description = '' Commands for tint2 that will be add to the {file}`tint2rc` @@ -25,12 +22,12 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; xdg.configFile = { "tint2/tint2rc" = - mkIf (cfg.extraConfig != "") { text = cfg.extraConfig; }; + lib.mkIf (cfg.extraConfig != "") { text = cfg.extraConfig; }; }; }; } diff --git a/modules/programs/tiny.nix b/modules/programs/tiny.nix index cbf26b7c..4ac997f3 100644 --- a/modules/programs/tiny.nix +++ b/modules/programs/tiny.nix @@ -1,6 +1,4 @@ { config, lib, pkgs, ... }: - -with lib; let cfg = config.programs.tiny; format = pkgs.formats.yaml { }; @@ -9,19 +7,19 @@ let else "${config.xdg.configHome}/tiny"; in { - meta.maintainers = [ hm.maintainers.kmaasrud ]; + meta.maintainers = [ lib.hm.maintainers.kmaasrud ]; options = { programs.tiny = { - enable = mkEnableOption "tiny, a TUI IRC client written in Rust"; + enable = lib.mkEnableOption "tiny, a TUI IRC client written in Rust"; package = lib.mkPackageOption pkgs "tiny" { }; - settings = mkOption { + settings = lib.mkOption { type = format.type; default = { }; - defaultText = literalExpression "{ }"; - example = literalExpression '' + defaultText = lib.literalExpression "{ }"; + example = lib.literalExpression '' { servers = [ { @@ -50,10 +48,10 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; - home.file."${configDir}/config.yml" = mkIf (cfg.settings != { }) { + home.file."${configDir}/config.yml" = lib.mkIf (cfg.settings != { }) { source = format.generate "tiny-config" cfg.settings; }; }; diff --git a/modules/programs/tmate.nix b/modules/programs/tmate.nix index e335ca62..1351ddcf 100644 --- a/modules/programs/tmate.nix +++ b/modules/programs/tmate.nix @@ -1,17 +1,14 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) literalExpression mkOption optional types; cfg = config.programs.tmate; - in { - meta.maintainers = [ maintainers.jlesquembre ]; + meta.maintainers = [ lib.maintainers.jlesquembre ]; options = { programs.tmate = { - enable = mkEnableOption "tmate"; + enable = lib.mkEnableOption "tmate"; package = lib.mkPackageOption pkgs "tmate" { }; @@ -56,7 +53,7 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; home.file.".tmate.conf" = let @@ -69,6 +66,6 @@ in { ++ optional (cfg.rsaFingerprint != null) ''set -g tmate-server-rsa-fingerprint "${cfg.rsaFingerprint}"'' ++ optional (cfg.extraConfig != "") cfg.extraConfig; - in mkIf (conf != [ ]) { text = concatLines conf; }; + in lib.mkIf (conf != [ ]) { text = lib.concatLines conf; }; }; } diff --git a/modules/programs/tmux.nix b/modules/programs/tmux.nix index d1a8fa68..57b04c4a 100644 --- a/modules/programs/tmux.nix +++ b/modules/programs/tmux.nix @@ -1,8 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) literalExpression mkEnableOption mkOption optionalString types; cfg = config.programs.tmux; @@ -105,12 +103,12 @@ let configPlugins = { assertions = [ (let - hasBadPluginName = p: !(hasPrefix "tmuxplugin" (pluginName p)); - badPlugins = filter hasBadPluginName cfg.plugins; + hasBadPluginName = p: !(lib.hasPrefix "tmuxplugin" (pluginName p)); + badPlugins = lib.filter hasBadPluginName cfg.plugins; in { assertion = badPlugins == [ ]; message = ''Invalid tmux plugin (not prefixed with "tmuxplugins"): '' - + concatMapStringsSep ", " pluginName badPlugins; + + lib.concatMapStringsSep ", " pluginName badPlugins; }) ]; @@ -119,7 +117,7 @@ let # Load plugins with Home Manager # # --------------------------------------------- # - ${(concatMapStringsSep "\n\n" (p: '' + ${(lib.concatMapStringsSep "\n\n" (p: '' # ${pluginName p} # --------------------- ${p.extraConfig or ""} @@ -308,7 +306,7 @@ in { run at the top of your configuration. ''; default = [ ]; - example = literalExpression '' + example = lib.literalExpression '' with pkgs; [ tmuxPlugins.cpu { @@ -328,22 +326,22 @@ in { }; }; - config = mkIf cfg.enable (mkMerge ([ + config = lib.mkIf cfg.enable (lib.mkMerge [ { home.packages = [ cfg.package ] - ++ optional cfg.tmuxinator.enable pkgs.tmuxinator - ++ optional cfg.tmuxp.enable pkgs.tmuxp; + ++ lib.optional cfg.tmuxinator.enable pkgs.tmuxinator + ++ lib.optional cfg.tmuxp.enable pkgs.tmuxp; } - { xdg.configFile."tmux/tmux.conf".text = mkBefore tmuxConf; } - { xdg.configFile."tmux/tmux.conf".text = mkAfter cfg.extraConfig; } + { xdg.configFile."tmux/tmux.conf".text = lib.mkBefore tmuxConf; } + { xdg.configFile."tmux/tmux.conf".text = lib.mkAfter cfg.extraConfig; } - (mkIf cfg.secureSocket { + (lib.mkIf cfg.secureSocket { home.sessionVariables = { TMUX_TMPDIR = ''''${XDG_RUNTIME_DIR:-"/run/user/$(id -u)"}''; }; }) - (mkIf (cfg.plugins != [ ]) configPlugins) - ])); + (lib.mkIf (cfg.plugins != [ ]) configPlugins) + ]); } diff --git a/modules/programs/todoman.nix b/modules/programs/todoman.nix index 2e7ebf6a..5cb2a742 100644 --- a/modules/programs/todoman.nix +++ b/modules/programs/todoman.nix @@ -1,22 +1,14 @@ { config, lib, pkgs, ... }: - -with lib; - -let - - cfg = config.programs.todoman; - - format = pkgs.formats.keyValue { }; - +let cfg = config.programs.todoman; in { - meta.maintainers = [ hm.maintainers.mikilio ]; + meta.maintainers = [ lib.hm.maintainers.mikilio ]; options.programs.todoman = { enable = lib.mkEnableOption "todoman"; - glob = mkOption { - type = types.str; + glob = lib.mkOption { + type = lib.types.str; default = "*"; description = '' The glob expansion which matches all directories relevant. @@ -24,8 +16,8 @@ in { example = "*/*"; }; - extraConfig = mkOption { - type = types.lines; + extraConfig = lib.mkOption { + type = lib.types.lines; default = ""; description = '' Text for configuration of todoman. @@ -43,7 +35,7 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [{ assertion = config.accounts.calendar ? basePath; message = '' diff --git a/modules/programs/tofi.nix b/modules/programs/tofi.nix index b6e46a6c..cab709e7 100644 --- a/modules/programs/tofi.nix +++ b/modules/programs/tofi.nix @@ -1,25 +1,22 @@ { config, lib, pkgs, ... }: - -with lib; - let cfg = config.programs.tofi; in { - meta.maintainers = [ hm.maintainers.henrisota ]; + meta.maintainers = [ lib.hm.maintainers.henrisota ]; options.programs.tofi = { - enable = mkEnableOption "Tofi, a tiny dynamic menu for Wayland"; + enable = lib.mkEnableOption "Tofi, a tiny dynamic menu for Wayland"; - package = mkPackageOption pkgs "tofi" { nullable = true; }; + package = lib.mkPackageOption pkgs "tofi" { nullable = true; }; - settings = mkOption { - type = with types; + settings = lib.mkOption { + type = with lib.types; let primitive = either (either str int) bool; in attrsOf primitive; default = { }; - example = literalExpression '' + example = lib.literalExpression '' { background-color = "#000000"; border-width = 0; @@ -42,18 +39,20 @@ in { }; }; - config = mkIf cfg.enable { - assertions = - [ (hm.assertions.assertPlatform "programs.tofi" pkgs platforms.linux) ]; + config = lib.mkIf cfg.enable { + assertions = [ + (lib.hm.assertions.assertPlatform "programs.tofi" pkgs + lib.platforms.linux) + ]; home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; - xdg.configFile."tofi/config" = mkIf (cfg.settings != { }) { + xdg.configFile."tofi/config" = lib.mkIf (cfg.settings != { }) { text = let - renderedSettings = generators.toINIWithGlobalSection { } { + renderedSettings = lib.generators.toINIWithGlobalSection { } { globalSection = cfg.settings; }; - in removeSuffix "\n\n" '' + in lib.removeSuffix "\n\n" '' # Generated by Home Manager. ${renderedSettings} diff --git a/modules/programs/topgrade.nix b/modules/programs/topgrade.nix index 0630ccab..7f810ff2 100644 --- a/modules/programs/topgrade.nix +++ b/modules/programs/topgrade.nix @@ -1,32 +1,27 @@ { config, lib, pkgs, ... }: - -with lib; - let - cfg = config.programs.topgrade; tomlFormat = pkgs.formats.toml { }; - in { - meta.maintainers = [ hm.maintainers.msfjarvis ]; + meta.maintainers = [ lib.hm.maintainers.msfjarvis ]; options.programs.topgrade = { - enable = mkEnableOption "topgrade"; + enable = lib.mkEnableOption "topgrade"; - package = mkOption { - type = types.package; + package = lib.mkOption { + type = lib.types.package; default = pkgs.topgrade; - defaultText = literalExpression "pkgs.topgrade"; + defaultText = lib.literalExpression "pkgs.topgrade"; description = "The package to use for the topgrade binary."; }; - settings = mkOption { + settings = lib.mkOption { type = tomlFormat.type; default = { }; - defaultText = literalExpression "{ }"; - example = literalExpression '' + defaultText = lib.literalExpression "{ }"; + example = lib.literalExpression '' { misc = { assume_yes = true; @@ -52,10 +47,10 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; - xdg.configFile."topgrade.toml" = mkIf (cfg.settings != { }) { + xdg.configFile."topgrade.toml" = lib.mkIf (cfg.settings != { }) { source = tomlFormat.generate "topgrade-config" cfg.settings; }; }; diff --git a/modules/programs/translate-shell.nix b/modules/programs/translate-shell.nix index 1eb3e125..e6dca5a5 100644 --- a/modules/programs/translate-shell.nix +++ b/modules/programs/translate-shell.nix @@ -1,34 +1,30 @@ { config, lib, pkgs, ... }: - -with lib; - let - cfg = config.programs.translate-shell; mkKeyValue = key: value: let formatValue = v: - if isBool v then + if lib.isBool v then (if v then "true" else "false") - else if isString v then + else if lib.isString v then ''"${v}"'' - else if isList v then - "[ ${concatStringsSep " " (map formatValue v)} ]" + else if lib.isList v then + "[ ${lib.concatStringsSep " " (map formatValue v)} ]" else toString v; in ":${key} ${formatValue value}"; - toKeyValue = generators.toKeyValue { inherit mkKeyValue; }; + toKeyValue = lib.generators.toKeyValue { inherit mkKeyValue; }; in { meta.maintainers = [ ]; options.programs.translate-shell = { - enable = mkEnableOption "translate-shell"; + enable = lib.mkEnableOption "translate-shell"; - settings = mkOption { - type = with types; attrsOf (oneOf [ bool str (listOf str) ]); + settings = lib.mkOption { + type = with lib.types; attrsOf (oneOf [ bool str (listOf str) ]); default = { }; example = { verbose = true; @@ -43,10 +39,10 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ pkgs.translate-shell ]; xdg.configFile."translate-shell/init.trans" = - mkIf (cfg.settings != { }) { text = "{${toKeyValue cfg.settings}}"; }; + lib.mkIf (cfg.settings != { }) { text = "{${toKeyValue cfg.settings}}"; }; }; } diff --git a/modules/programs/urxvt.nix b/modules/programs/urxvt.nix index 55560505..27f84e46 100644 --- a/modules/programs/urxvt.nix +++ b/modules/programs/urxvt.nix @@ -1,14 +1,11 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; cfg = config.programs.urxvt; - in { options.programs.urxvt = { - enable = mkEnableOption "rxvt-unicode terminal emulator"; + enable = lib.mkEnableOption "rxvt-unicode terminal emulator"; package = lib.mkPackageOption pkgs "rxvt-unicode" { }; @@ -23,7 +20,7 @@ in { type = types.attrsOf types.str; default = { }; description = "Mapping of keybindings to actions"; - example = literalExpression '' + example = lib.literalExpression '' { "Shift-Control-C" = "eval:selection_to_clipboard"; "Shift-Control-V" = "eval:paste_clipboard"; @@ -126,7 +123,7 @@ in { }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; xresources.properties = { @@ -142,10 +139,11 @@ in { "URxvt.transparent" = cfg.transparent; "URxvt.shading" = cfg.shading; "URxvt.iso14755" = cfg.iso14755; - } // flip mapAttrs' cfg.keybindings - (kb: action: nameValuePair "URxvt.keysym.${kb}" action) - // optionalAttrs (cfg.fonts != [ ]) { - "URxvt.font" = concatStringsSep "," cfg.fonts; - } // flip mapAttrs' cfg.extraConfig (k: v: nameValuePair "URxvt.${k}" v); + } // lib.flip lib.mapAttrs' cfg.keybindings + (kb: action: lib.nameValuePair "URxvt.keysym.${kb}" action) + // lib.optionalAttrs (cfg.fonts != [ ]) { + "URxvt.font" = lib.concatStringsSep "," cfg.fonts; + } // lib.flip lib.mapAttrs' cfg.extraConfig + (k: v: lib.nameValuePair "URxvt.${k}" v); }; } diff --git a/modules/programs/vdirsyncer-accounts.nix b/modules/programs/vdirsyncer-accounts.nix index 7ab9521c..8b437067 100644 --- a/modules/programs/vdirsyncer-accounts.nix +++ b/modules/programs/vdirsyncer-accounts.nix @@ -1,14 +1,11 @@ { lib, ... }: - -with lib; - let + inherit (lib) mkOption types; collection = types.either types.str (types.listOf types.str); - in { options.vdirsyncer = { - enable = mkEnableOption "synchronization using vdirsyncer"; + enable = lib.mkEnableOption "synchronization using vdirsyncer"; urlCommand = mkOption { type = types.nullOr (types.listOf types.str); diff --git a/modules/programs/vdirsyncer.nix b/modules/programs/vdirsyncer.nix index 2e013af0..2391124f 100644 --- a/modules/programs/vdirsyncer.nix +++ b/modules/programs/vdirsyncer.nix @@ -1,17 +1,16 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) + concatStringsSep filterAttrs getAttrs mapAttrs mapAttrs' mapAttrsToList; cfg = config.programs.vdirsyncer; vdirsyncerCalendarAccounts = filterAttrs (_: v: v.vdirsyncer.enable) - (mapAttrs' (n: v: nameValuePair ("calendar_" + n) v) + (mapAttrs' (n: v: lib.nameValuePair ("calendar_" + n) v) config.accounts.calendar.accounts); vdirsyncerContactAccounts = filterAttrs (_: v: v.vdirsyncer.enable) - (mapAttrs' (n: v: nameValuePair ("contacts_" + n) v) + (mapAttrs' (n: v: lib.nameValuePair ("contacts_" + n) v) config.accounts.contact.accounts); vdirsyncerAccounts = vdirsyncerCalendarAccounts // vdirsyncerContactAccounts; @@ -20,8 +19,6 @@ let listString = l: "[${concatStringsSep ", " l}]"; - boolString = b: if b then "true" else "false"; - localStorage = a: filterAttrs (_: v: v != null) ((getAttrs [ "type" "fileExt" "encoding" ] a.local) // { @@ -55,7 +52,6 @@ let ] a.vdirsyncer)); pair = a: - with a.vdirsyncer; filterAttrs (k: v: k == "collections" || (v != null && v != [ ])) (getAttrs [ "collections" "conflictResolution" "metadata" "partialSync" ] a.vdirsyncer); @@ -99,7 +95,7 @@ let ''verify_fingerprint = "${v}"'' else if (n == "auth") then ''auth = "${v}"'' - else if (n == "authCert" && isString (v)) then + else if (n == "authCert" && lib.isString v) then ''auth_cert = "${v}"'' else if (n == "authCert") then "auth_cert = ${listString (map wrap v)}" @@ -121,8 +117,8 @@ let ''partial_sync = "${v}"'' else if (n == "collections") then let - contents = - map (c: if (isString c) then ''"${c}"'' else listString (map wrap c)) + contents = map + (c: if (lib.isString c) then ''"${c}"'' else listString (map wrap c)) v; in "collections = ${ if ((isNull v) || v == [ ]) then "null" else listString contents @@ -170,10 +166,10 @@ let in { options = { programs.vdirsyncer = { - enable = mkEnableOption "vdirsyncer"; + enable = lib.mkEnableOption "vdirsyncer"; - package = mkOption { - type = types.package; + package = lib.mkOption { + type = lib.types.package; default = pkgs.vdirsyncer; defaultText = "pkgs.vdirsyncer"; description = '' @@ -181,8 +177,8 @@ in { ''; }; - statusPath = mkOption { - type = types.str; + statusPath = lib.mkOption { + type = lib.types.str; default = "${config.xdg.dataHome}/vdirsyncer/status"; defaultText = "$XDG_DATA_HOME/vdirsyncer/status"; description = '' @@ -195,7 +191,7 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = let mutuallyExclusiveOptions = @@ -256,33 +252,34 @@ in { let allowed = allowedOptions v.type ++ (requiredOptions v.type); in mapAttrsToList (a: v': [{ - assertion = (elem a allowed); + assertion = (lib.elem a allowed); message = '' Storage ${n} is of type ${v.type}. Option ${a} is not allowed for this type. ''; }] ++ (let - required = - filter (a: !hasAttr "${a}Command" v) (requiredOptions v.type); + required = lib.filter (a: !lib.hasAttr "${a}Command" v) + (requiredOptions v.type); in map (a: [{ - assertion = hasAttr a v; + assertion = lib.hasAttr a v; message = '' Storage ${n} is of type ${v.type}, but required option ${a} is not set. ''; }]) required) ++ map (attrs: let - defined = attrNames (filterAttrs (n: v: v != null) - (genAttrs attrs (a: v.${a} or null))); + defined = lib.attrNames (filterAttrs (n: v: v != null) + (lib.genAttrs attrs (a: v.${a} or null))); in { - assertion = length defined <= 1; + assertion = lib.length defined <= 1; message = "Storage ${n} has mutually exclusive options: ${ concatStringsSep ", " defined }"; }) mutuallyExclusiveOptions) (removeAttrs v [ "type" "_module" ]); - storageAssertions = flatten (mapAttrsToList assertStorage localStorages) - ++ flatten (mapAttrsToList assertStorage remoteStorages); + storageAssertions = + lib.flatten (mapAttrsToList assertStorage localStorages) + ++ lib.flatten (mapAttrsToList assertStorage remoteStorages); in storageAssertions; home.packages = [ cfg.package ]; diff --git a/modules/programs/vim-vint.nix b/modules/programs/vim-vint.nix index 655c0093..5ec8818e 100644 --- a/modules/programs/vim-vint.nix +++ b/modules/programs/vim-vint.nix @@ -1,7 +1,4 @@ { config, lib, pkgs, ... }: - -with lib; - let cfg = config.programs.vim-vint; @@ -9,14 +6,14 @@ let yamlFormat = pkgs.formats.yaml { }; in { - meta.maintainers = [ maintainers.tomodachi94 ]; + meta.maintainers = [ lib.maintainers.tomodachi94 ]; options = { programs.vim-vint = { - enable = mkEnableOption "the Vint linter for Vimscript"; - package = mkPackageOption pkgs "vim-vint" { nullable = true; }; + enable = lib.mkEnableOption "the Vint linter for Vimscript"; + package = lib.mkPackageOption pkgs "vim-vint" { nullable = true; }; - settings = mkOption { + settings = lib.mkOption { type = yamlFormat.type; default = { }; description = '' @@ -27,7 +24,7 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; xdg.configFile.".vintrc.yaml".source = diff --git a/modules/programs/vim.nix b/modules/programs/vim.nix index 2f13caee..1042bed8 100644 --- a/modules/programs/vim.nix +++ b/modules/programs/vim.nix @@ -1,8 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) concatStringsSep literalExpression mkOption types; cfg = config.programs.vim; defaultPlugins = [ pkgs.vimPlugins.vim-sensible ]; @@ -38,32 +36,35 @@ let default = null; visible = false; }; - in mapAttrs opt knownSettings; + in lib.mapAttrs opt knownSettings; }; setExpr = name: value: let - v = if isBool value then + v = if lib.isBool value then (if value then "" else "no") + name else "${name}=${ - if isList value then concatStringsSep "," value else toString value + if lib.isList value then + concatStringsSep "," value + else + toString value }"; - in optionalString (value != null) ("set " + v); + in lib.optionalString (value != null) ("set " + v); plugins = let vpkgs = pkgs.vimPlugins; getPkg = p: - if isDerivation p then + if lib.isDerivation p then [ p ] else - optional (isString p && hasAttr p vpkgs) vpkgs.${p}; - in concatMap getPkg cfg.plugins; + lib.optional (lib.isString p && lib.hasAttr p vpkgs) vpkgs.${p}; + in lib.concatMap getPkg cfg.plugins; in { options = { programs.vim = { - enable = mkEnableOption "Vim"; + enable = lib.mkEnableOption "Vim"; plugins = mkOption { type = with types; listOf (either str package); @@ -92,7 +93,7 @@ in { corresponding values must be among the following supported options. - ${concatStringsSep "\n" (mapAttrsToList (n: v: '' + ${concatStringsSep "\n" (lib.mapAttrsToList (n: v: '' {var}`${n}` : ${v.description} '') knownSettings)} @@ -140,7 +141,7 @@ in { config = (let customRC = '' - ${concatStringsSep "\n" (remove "" (mapAttrsToList setExpr + ${concatStringsSep "\n" (lib.remove "" (lib.mapAttrsToList setExpr (builtins.intersectAttrs knownSettings cfg.settings)))} ${cfg.extraConfig} @@ -154,27 +155,28 @@ in { packages.home-manager.start = plugins; }; }; - in mkIf cfg.enable { + in lib.mkIf cfg.enable { assertions = let packagesNotFound = - filter (p: isString p && (!hasAttr p pkgs.vimPlugins)) cfg.plugins; + lib.filter (p: lib.isString p && (!lib.hasAttr p pkgs.vimPlugins)) + cfg.plugins; in [{ assertion = packagesNotFound == [ ]; message = "Following VIM plugin not found in pkgs.vimPlugins: ${ - concatMapStringsSep ", " (p: ''"${p}"'') packagesNotFound + lib.concatMapStringsSep ", " (p: ''"${p}"'') packagesNotFound }"; }]; - warnings = let stringPlugins = filter isString cfg.plugins; - in optional (stringPlugins != [ ]) '' + warnings = let stringPlugins = lib.filter lib.isString cfg.plugins; + in lib.optional (stringPlugins != [ ]) '' Specifying VIM plugins using strings is deprecated, found ${ - concatMapStringsSep ", " (p: ''"${p}"'') stringPlugins + lib.concatMapStringsSep ", " (p: ''"${p}"'') stringPlugins } as strings. ''; home.packages = [ cfg.package ]; - home.sessionVariables = mkIf cfg.defaultEditor { EDITOR = "vim"; }; + home.sessionVariables = lib.mkIf cfg.defaultEditor { EDITOR = "vim"; }; programs.vim = { package = vim; diff --git a/modules/programs/vscode.nix b/modules/programs/vscode.nix index 2fee53ac..6549221a 100644 --- a/modules/programs/vscode.nix +++ b/modules/programs/vscode.nix @@ -1,8 +1,7 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) + flatten literalExpression mapAttrsToList mkOption mkIf optionalString types; cfg = config.programs.vscode; @@ -65,9 +64,9 @@ let mergedUserSettings = userSettings: enableUpdateCheck: enableExtensionUpdateCheck: - userSettings - // optionalAttrs (enableUpdateCheck == false) { "update.mode" = "none"; } - // optionalAttrs (enableExtensionUpdateCheck == false) { + userSettings // lib.optionalAttrs (enableUpdateCheck == false) { + "update.mode" = "none"; + } // lib.optionalAttrs (enableExtensionUpdateCheck == false) { "extensions.autoCheckUpdates" = false; }; @@ -218,13 +217,14 @@ let allProfilesExceptDefault = removeAttrs cfg.profiles [ "default" ]; in { imports = [ - (mkChangedOptionModule [ "programs" "vscode" "immutableExtensionsDir" ] [ + (lib.mkChangedOptionModule [ "programs" "vscode" - "mutableExtensionsDir" - ] (config: !config.programs.vscode.immutableExtensionsDir)) + "immutableExtensionsDir" + ] [ "programs" "vscode" "mutableExtensionsDir" ] + (config: !config.programs.vscode.immutableExtensionsDir)) ] ++ map (v: - mkRenamedOptionModule [ "programs" "vscode" v ] [ + lib.mkRenamedOptionModule [ "programs" "vscode" v ] [ "programs" "vscode" "profiles" @@ -242,7 +242,7 @@ in { ]; options.programs.vscode = { - enable = mkEnableOption "Visual Studio Code"; + enable = lib.mkEnableOption "Visual Studio Code"; package = mkOption { type = types.package; @@ -279,7 +279,7 @@ in { warnings = [ (mkIf (allProfilesExceptDefault != { } && cfg.mutableExtensionsDir) "programs.vscode.mutableExtensionsDir can be used only if no profiles apart from default are set.") - (mkIf ((filterAttrs (n: v: + (mkIf ((lib.filterAttrs (n: v: (v ? enableExtensionUpdateCheck || v ? enableUpdateCheck) && (v.enableExtensionUpdateCheck != null || v.enableUpdateCheck != null)) allProfilesExceptDefault) != { }) @@ -294,42 +294,43 @@ in { # A caveat of adding profiles this way is, VSCode has to be closed # when this file is being written, since the file is loaded into RAM # and overwritten on closing VSCode. - home.activation.vscodeProfiles = hm.dag.entryAfter [ "writeBoundary" ] (let - modifyGlobalStorage = - pkgs.writeShellScript "vscode-global-storage-modify" '' - PATH=${makeBinPath [ pkgs.jq ]}''${PATH:+:}$PATH - file="${userDir}/globalStorage/storage.json" - file_write="" - profiles=(${ - escapeShellArgs - (flatten (mapAttrsToList (n: v: n) allProfilesExceptDefault)) - }) + home.activation.vscodeProfiles = lib.hm.dag.entryAfter [ "writeBoundary" ] + (let + modifyGlobalStorage = + pkgs.writeShellScript "vscode-global-storage-modify" '' + PATH=${lib.makeBinPath [ pkgs.jq ]}''${PATH:+:}$PATH + file="${userDir}/globalStorage/storage.json" + file_write="" + profiles=(${ + lib.escapeShellArgs + (flatten (mapAttrsToList (n: v: n) allProfilesExceptDefault)) + }) - if [ -f "$file" ]; then - existing_profiles=$(jq '.userDataProfiles // [] | map({ (.name): .location }) | add // {}' "$file") + if [ -f "$file" ]; then + existing_profiles=$(jq '.userDataProfiles // [] | map({ (.name): .location }) | add // {}' "$file") - for profile in "''${profiles[@]}"; do - if [[ "$(echo $existing_profiles | jq --arg profile $profile 'has ($profile)')" != "true" ]] || [[ "$(echo $existing_profiles | jq --arg profile $profile 'has ($profile)')" == "true" && "$(echo $existing_profiles | jq --arg profile $profile '.[$profile]')" != "\"$profile\"" ]]; then + for profile in "''${profiles[@]}"; do + if [[ "$(echo $existing_profiles | jq --arg profile $profile 'has ($profile)')" != "true" ]] || [[ "$(echo $existing_profiles | jq --arg profile $profile 'has ($profile)')" == "true" && "$(echo $existing_profiles | jq --arg profile $profile '.[$profile]')" != "\"$profile\"" ]]; then + file_write="$file_write$([ "$file_write" != "" ] && echo "...")$profile" + fi + done + else + for profile in "''${profiles[@]}"; do file_write="$file_write$([ "$file_write" != "" ] && echo "...")$profile" - fi - done - else - for profile in "''${profiles[@]}"; do - file_write="$file_write$([ "$file_write" != "" ] && echo "...")$profile" - done + done - mkdir -p $(dirname "$file") - echo "{}" > "$file" - fi + mkdir -p $(dirname "$file") + echo "{}" > "$file" + fi - if [ "$file_write" != "" ]; then - userDataProfiles=$(jq ".userDataProfiles += $(echo $file_write | jq -R 'split("...") | map({ name: ., location: . })')" "$file") - echo $userDataProfiles > "$file" - fi - ''; - in modifyGlobalStorage.outPath); + if [ "$file_write" != "" ]; then + userDataProfiles=$(jq ".userDataProfiles += $(echo $file_write | jq -R 'split("...") | map({ name: ., location: . })')" "$file") + echo $userDataProfiles > "$file" + fi + ''; + in modifyGlobalStorage.outPath); - home.file = mkMerge (flatten [ + home.file = lib.mkMerge (flatten [ (mapAttrsToList (n: v: [ (mkIf ((mergedUserSettings v.userSettings v.enableUpdateCheck v.enableExtensionUpdateCheck) != { }) { @@ -347,11 +348,11 @@ in { (mkIf (v.keybindings != [ ]) { "${keybindingsFilePath n}".source = jsonFormat.generate "vscode-keybindings" - (map (filterAttrs (_: v: v != null)) v.keybindings); + (map (lib.filterAttrs (_: v: v != null)) v.keybindings); }) - (mkIf (v.languageSnippets != { }) (mapAttrs' (language: snippet: - nameValuePair "${snippetDir n}/${language}.json" { + (mkIf (v.languageSnippets != { }) (lib.mapAttrs' (language: snippet: + lib.nameValuePair "${snippetDir n}/${language}.json" { source = jsonFormat.generate "user-snippet-${language}.json" snippet; }) v.languageSnippets)) @@ -365,8 +366,8 @@ in { # We write extensions.json for all profiles, except the default profile, # since that is handled by code below. - (mkIf (allProfilesExceptDefault != { }) (mapAttrs' (n: v: - nameValuePair "${userDir}/profiles/${n}/extensions.json" { + (mkIf (allProfilesExceptDefault != { }) (lib.mapAttrs' (n: v: + lib.nameValuePair "${userDir}/profiles/${n}/extensions.json" { source = "${ extensionJsonFile n (extensionJson v.extensions) }/share/vscode/extensions/extensions.json"; @@ -386,11 +387,10 @@ in { # Force regenerating extensions.json using the below method, # causes VSCode to create the extensions.json with all the extensions # in the extension directory, which includes extensions from other profiles. - mkMerge (concatMap toPaths + lib.mkMerge (lib.concatMap toPaths (flatten (mapAttrsToList (n: v: v.extensions) cfg.profiles)) - ++ optional - ((versionAtLeast vscodeVersion "1.74.0" || vscodePname == "cursor") - && defaultProfile != { }) { + ++ lib.optional ((lib.versionAtLeast vscodeVersion "1.74.0" + || vscodePname == "cursor") && defaultProfile != { }) { # Whenever our immutable extensions.json changes, force VSCode to regenerate # extensions.json with both mutable and immutable extensions. "${extensionPath}/.extensions-immutable.json" = { @@ -398,7 +398,7 @@ in { onChange = '' run rm $VERBOSE_ARG -f ${extensionPath}/{extensions.json,.init-default-profile-extensions} verboseEcho "Regenerating VSCode extensions.json" - run ${getExe cfg.package} --list-extensions > /dev/null + run ${lib.getExe cfg.package} --list-extensions > /dev/null ''; }; }) @@ -407,8 +407,8 @@ in { combinedExtensionsDrv = pkgs.buildEnv { name = "vscode-extensions"; paths = (flatten (mapAttrsToList (n: v: v.extensions) cfg.profiles)) - ++ optional ((versionAtLeast vscodeVersion "1.74.0" || vscodePname - == "cursor") && defaultProfile != { }) + ++ lib.optional ((lib.versionAtLeast vscodeVersion "1.74.0" + || vscodePname == "cursor") && defaultProfile != { }) (extensionJsonFile "default" (extensionJson defaultProfile.extensions)); }; diff --git a/modules/programs/vscode/haskell.nix b/modules/programs/vscode/haskell.nix index 450c748e..fefd7ab3 100644 --- a/modules/programs/vscode/haskell.nix +++ b/modules/programs/vscode/haskell.nix @@ -1,14 +1,11 @@ { pkgs, config, lib, ... }: - -with lib; - let cfg = config.programs.vscode.haskell; defaultHieNixExe = hie-nix.hies + "/bin/hie-wrapper"; defaultHieNixExeText = - literalExpression ''"''${pkgs.hie-nix.hies}/bin/hie-wrapper"''; + lib.literalExpression ''"''${pkgs.hie-nix.hies}/bin/hie-wrapper"''; hie-nix = pkgs.hie-nix or (abort '' vscode.haskell: pkgs.hie-nix missing. Please add an overlay such as: @@ -23,16 +20,16 @@ let in { options.programs.vscode.haskell = { - enable = mkEnableOption "Haskell integration for Visual Studio Code"; + enable = lib.mkEnableOption "Haskell integration for Visual Studio Code"; - hie.enable = mkOption { - type = types.bool; + hie.enable = lib.mkOption { + type = lib.types.bool; default = true; description = "Whether to enable Haskell IDE engine integration."; }; - hie.executablePath = mkOption { - type = types.path; + hie.executablePath = lib.mkOption { + type = lib.types.path; default = defaultHieNixExe; defaultText = defaultHieNixExeText; description = '' @@ -45,14 +42,14 @@ in { ${exampleOverlay} ``` ''; - example = literalExpression '' + example = lib.literalExpression '' (import ~/src/haskell-ide-engine {}).hies + "/bin/hie-wrapper"; ''; }; }; - config = mkIf cfg.enable { - programs.vscode.profiles.default.userSettings = mkIf cfg.hie.enable { + config = lib.mkIf cfg.enable { + programs.vscode.profiles.default.userSettings = lib.mkIf cfg.hie.enable { "languageServerHaskell.enableHIE" = true; "languageServerHaskell.hieExecutablePath" = cfg.hie.executablePath; }; diff --git a/modules/programs/watson.nix b/modules/programs/watson.nix index f830d28d..6e5a2557 100644 --- a/modules/programs/watson.nix +++ b/modules/programs/watson.nix @@ -1,8 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkIf; cfg = config.programs.watson; @@ -17,12 +15,12 @@ in { meta.maintainers = [ ]; options.programs.watson = { - enable = mkEnableOption "watson, a wonderful CLI to track your time"; + enable = lib.mkEnableOption "watson, a wonderful CLI to track your time"; - package = mkOption { - type = types.package; + package = lib.mkOption { + type = lib.types.package; default = pkgs.watson; - defaultText = literalExpression "pkgs.watson"; + defaultText = lib.literalExpression "pkgs.watson"; description = "Package providing the {command}`watson`."; }; @@ -35,7 +33,7 @@ in { enableZshIntegration = lib.hm.shell.mkZshIntegrationOption { inherit config; }; - settings = mkOption { + settings = lib.mkOption { type = iniFormat.type; default = { }; description = '' @@ -46,7 +44,7 @@ in { See for an example configuration. ''; - example = literalExpression '' + example = lib.literalExpression '' { backend = { url = "https://api.crick.fr"; diff --git a/modules/programs/wofi.nix b/modules/programs/wofi.nix index 5ff7a58c..db2cb897 100644 --- a/modules/programs/wofi.nix +++ b/modules/programs/wofi.nix @@ -1,23 +1,22 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkIf mkOption types; + cfg = config.programs.wofi; toConfig = attrs: '' # Generated by Home Manager. - '' + generators.toKeyValue { } - (filterAttrs (name: value: value != null) attrs); + '' + lib.generators.toKeyValue { } + (lib.filterAttrs (name: value: value != null) attrs); in { - meta.maintainers = [ maintainers.christoph-heiss ]; + meta.maintainers = [ lib.maintainers.christoph-heiss ]; options.programs.wofi = { - enable = mkEnableOption + enable = lib.mkEnableOption "wofi: a launcher/menu program for wlroots based wayland compositors such as sway"; - package = mkPackageOption pkgs "wofi" { nullable = true; }; + package = lib.mkPackageOption pkgs "wofi" { nullable = true; }; settings = mkOption { default = { }; @@ -26,7 +25,7 @@ in { Configuration options for wofi. See {manpage}`wofi(5)`. ''; - example = literalExpression '' + example = lib.literalExpression '' { location = "bottom-right"; allow_markup = true; @@ -55,12 +54,14 @@ in { }; config = mkIf cfg.enable { - assertions = - [ (hm.assertions.assertPlatform "programs.wofi" pkgs platforms.linux) ]; + assertions = [ + (lib.hm.assertions.assertPlatform "programs.wofi" pkgs + lib.platforms.linux) + ]; home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; - xdg.configFile = mkMerge [ + xdg.configFile = lib.mkMerge [ (mkIf (cfg.settings != { }) { "wofi/config".text = toConfig cfg.settings; }) diff --git a/modules/programs/xmobar.nix b/modules/programs/xmobar.nix index 267b3080..83fbb72a 100644 --- a/modules/programs/xmobar.nix +++ b/modules/programs/xmobar.nix @@ -1,24 +1,21 @@ { config, lib, pkgs, ... }: - -with lib; - let cfg = config.programs.xmobar; in { options.programs.xmobar = { - enable = mkEnableOption "Xmobar, a minimalistic status bar"; + enable = lib.mkEnableOption "Xmobar, a minimalistic status bar"; - package = mkOption { + package = lib.mkOption { default = pkgs.haskellPackages.xmobar; - defaultText = literalExpression "pkgs.haskellPackages.xmobar"; - type = types.package; + defaultText = lib.literalExpression "pkgs.haskellPackages.xmobar"; + type = lib.types.package; description = '' Package providing the {command}`xmobar` binary. ''; }; - extraConfig = mkOption { + extraConfig = lib.mkOption { default = ""; - example = literalExpression '' + example = lib.literalExpression '' Config { font = "Fira Code" , borderColor = "#d0d0d0" @@ -39,7 +36,7 @@ in { , template = " %StdinReader% | %cpu% | %memory% | %enp3s0% }{%date% " } ''; - type = types.lines; + type = lib.types.lines; description = '' Extra configuration lines to add to {file}`$XDG_CONFIG_HOME/xmobar/.xmobarrc`. @@ -50,10 +47,10 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; xdg.configFile."xmobar/.xmobarrc".text = cfg.extraConfig; }; - meta.maintainers = [ hm.maintainers.t4ccer ]; + meta.maintainers = [ lib.hm.maintainers.t4ccer ]; } diff --git a/modules/programs/yt-dlp.nix b/modules/programs/yt-dlp.nix index 3b8e9c70..10d39d29 100644 --- a/modules/programs/yt-dlp.nix +++ b/modules/programs/yt-dlp.nix @@ -1,13 +1,11 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; cfg = config.programs.yt-dlp; - renderSettings = mapAttrsToList (name: value: - if isBool value then + renderSettings = lib.mapAttrsToList (name: value: + if lib.isBool value then if value then "--${name}" else "--no-${name}" else "--${name} ${toString value}"); @@ -16,19 +14,19 @@ in { meta.maintainers = [ ]; options.programs.yt-dlp = { - enable = mkEnableOption "yt-dlp"; + enable = lib.mkEnableOption "yt-dlp"; package = mkOption { type = types.package; default = pkgs.yt-dlp; - defaultText = literalExpression "pkgs.yt-dlp"; + defaultText = lib.literalExpression "pkgs.yt-dlp"; description = "Package providing the {command}`yt-dlp` tool."; }; settings = mkOption { type = with types; attrsOf (oneOf [ bool int str ]); default = { }; - example = literalExpression '' + example = lib.literalExpression '' { embed-thumbnail = true; embed-subs = true; @@ -63,13 +61,13 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; xdg.configFile."yt-dlp/config" = - mkIf (cfg.settings != { } || cfg.extraConfig != "") { - text = concatStringsSep "\n" - (remove "" (renderSettings cfg.settings ++ [ cfg.extraConfig ])) + lib.mkIf (cfg.settings != { } || cfg.extraConfig != "") { + text = lib.concatStringsSep "\n" + (lib.remove "" (renderSettings cfg.settings ++ [ cfg.extraConfig ])) + "\n"; }; }; diff --git a/modules/programs/z-lua.nix b/modules/programs/z-lua.nix index afbf4d28..8ea88998 100644 --- a/modules/programs/z-lua.nix +++ b/modules/programs/z-lua.nix @@ -1,8 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkIf types; cfg = config.programs.z-lua; @@ -18,9 +16,9 @@ in { meta.maintainers = [ ]; options.programs.z-lua = { - enable = mkEnableOption "z.lua"; + enable = lib.mkEnableOption "z.lua"; - options = mkOption { + options = lib.mkOption { type = types.listOf types.str; default = [ ]; example = [ "enhanced" "once" "fzf" ]; @@ -38,7 +36,7 @@ in { enableZshIntegration = lib.hm.shell.mkZshIntegrationOption { inherit config; }; - enableAliases = mkOption { + enableAliases = lib.mkOption { default = false; type = types.bool; description = '' @@ -52,13 +50,13 @@ in { programs.bash.initExtra = mkIf cfg.enableBashIntegration '' eval "$(${pkgs.z-lua}/bin/z --init bash ${ - concatStringsSep " " cfg.options + lib.concatStringsSep " " cfg.options })" ''; programs.zsh.initContent = mkIf cfg.enableZshIntegration '' eval "$(${pkgs.z-lua}/bin/z --init zsh ${ - concatStringsSep " " cfg.options + lib.concatStringsSep " " cfg.options })" ''; @@ -66,11 +64,11 @@ in { programs.zsh.shellAliases = mkIf cfg.enableAliases aliases; - programs.fish = mkMerge [ + programs.fish = lib.mkMerge [ { shellInit = mkIf cfg.enableFishIntegration '' source (${pkgs.z-lua}/bin/z --init fish ${ - concatStringsSep " " cfg.options + lib.concatStringsSep " " cfg.options } | psub) ''; } diff --git a/modules/programs/zathura.nix b/modules/programs/zathura.nix index 3e41256d..fb3210ce 100644 --- a/modules/programs/zathura.nix +++ b/modules/programs/zathura.nix @@ -1,24 +1,22 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkOption types; cfg = config.programs.zathura; formatLine = n: v: let formatValue = v: - if isBool v then (if v then "true" else "false") else toString v; + if lib.isBool v then (if v then "true" else "false") else toString v; in ''set ${n} "${formatValue v}"''; formatMapLine = n: v: "map ${n} ${toString v}"; in { - meta.maintainers = [ maintainers.rprospero ]; + meta.maintainers = [ lib.maintainers.rprospero ]; options.programs.zathura = { - enable = mkEnableOption '' + enable = lib.mkEnableOption '' Zathura, a highly customizable and functional document viewer focused on keyboard interaction''; @@ -73,12 +71,12 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; - xdg.configFile."zathura/zathurarc".text = concatStringsSep "\n" ([ ] - ++ optional (cfg.extraConfig != "") cfg.extraConfig - ++ mapAttrsToList formatLine cfg.options - ++ mapAttrsToList formatMapLine cfg.mappings) + "\n"; + xdg.configFile."zathura/zathurarc".text = lib.concatStringsSep "\n" ([ ] + ++ lib.optional (cfg.extraConfig != "") cfg.extraConfig + ++ lib.mapAttrsToList formatLine cfg.options + ++ lib.mapAttrsToList formatMapLine cfg.mappings) + "\n"; }; } diff --git a/modules/programs/zed-editor.nix b/modules/programs/zed-editor.nix index cfc55c07..ae3e4165 100644 --- a/modules/programs/zed-editor.nix +++ b/modules/programs/zed-editor.nix @@ -1,8 +1,7 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) literalExpression mkIf mkOption types; + cfg = config.programs.zed-editor; jsonFormat = pkgs.formats.json { }; @@ -12,16 +11,16 @@ let auto_install_extensions = lib.genAttrs cfg.extensions (_: true); }); in { - meta.maintainers = [ hm.maintainers.libewa ]; + meta.maintainers = [ lib.hm.maintainers.libewa ]; options = { # TODO: add vscode option parity (installing extensions, configuring # keybinds with nix etc.) programs.zed-editor = { - enable = mkEnableOption + enable = lib.mkEnableOption "Zed, the high performance, multiplayer code editor from the creators of Atom and Tree-sitter"; - package = mkPackageOption pkgs "zed-editor" { }; + package = lib.mkPackageOption pkgs "zed-editor" { }; extraPackages = mkOption { type = with types; listOf package; diff --git a/modules/programs/zplug.nix b/modules/programs/zplug.nix index 8c47915f..105bd757 100644 --- a/modules/programs/zplug.nix +++ b/modules/programs/zplug.nix @@ -1,8 +1,6 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) mkOption optionalString types; cfg = config.programs.zsh.zplug; @@ -24,7 +22,7 @@ let in { options.programs.zsh.zplug = { - enable = mkEnableOption "zplug - a zsh plugin manager"; + enable = lib.mkEnableOption "zplug - a zsh plugin manager"; plugins = mkOption { default = [ ]; @@ -41,19 +39,19 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { home.packages = [ pkgs.zplug ]; - programs.zsh.initContent = mkOrder 550 '' + programs.zsh.initContent = lib.mkOrder 550 '' export ZPLUG_HOME=${cfg.zplugHome} source ${pkgs.zplug}/share/zplug/init.zsh ${optionalString (cfg.plugins != [ ]) '' - ${concatStrings (map (plugin: '' + ${lib.concatStrings (map (plugin: '' zplug "${plugin.name}"${ optionalString (plugin.tags != [ ]) '' - ${concatStrings (map (tag: ", ${tag}") plugin.tags)} + ${lib.concatStrings (map (tag: ", ${tag}") plugin.tags)} '' } '') cfg.plugins)} diff --git a/modules/programs/zsh/prezto.nix b/modules/programs/zsh/prezto.nix index 5fdc8da2..b82ffdb8 100644 --- a/modules/programs/zsh/prezto.nix +++ b/modules/programs/zsh/prezto.nix @@ -1,8 +1,6 @@ { config, pkgs, lib, ... }: - -with lib; - let + inherit (lib) mkOption optionalString strings types; cfg = config.programs.zsh.prezto; @@ -12,9 +10,9 @@ let preztoModule = types.submodule { options = { - enable = mkEnableOption "prezto"; + enable = lib.mkEnableOption "prezto"; - package = mkPackageOption pkgs "prezto" { default = "zsh-prezto"; }; + package = lib.mkPackageOption pkgs "prezto" { default = "zsh-prezto"; }; caseSensitive = mkOption { type = types.nullOr types.bool; @@ -37,7 +35,7 @@ let pmoduleDirs = mkOption { type = types.listOf types.path; default = [ ]; - example = literalExpression + example = lib.literalExpression ''[ "''${config.home.homeDirectory}/.zprezto-contrib" ]''; description = "Add additional directories to load prezto modules from."; }; @@ -369,7 +367,7 @@ let }; in { - meta.maintainers = [ maintainers.nickhu ]; + meta.maintainers = [ lib.maintainers.nickhu ]; options = { programs.zsh = { prezto = mkOption { @@ -379,7 +377,7 @@ in { }; }; }; - config = mkIf cfg.enable (mkMerge [{ + config = lib.mkIf cfg.enable (lib.mkMerge [{ home.file."${relToDotDir ".zprofile"}".text = builtins.readFile "${cfg.package}/share/zsh-prezto/runcoms/zprofile"; home.file."${relToDotDir ".zlogin"}".text = @@ -518,7 +516,7 @@ in { ${optionalString (cfg.syntaxHighlighting.styles != { }) '' zstyle ':prezto:module:syntax-highlighting' styles \ ${ - builtins.concatStringsSep " \\\n" (attrsets.mapAttrsToList + builtins.concatStringsSep " \\\n" (lib.attrsets.mapAttrsToList (k: v: strings.escapeShellArg k + " " + strings.escapeShellArg v) cfg.syntaxHighlighting.styles) } @@ -526,7 +524,7 @@ in { ${optionalString (cfg.syntaxHighlighting.pattern != { }) '' zstyle ':prezto:module:syntax-highlighting' pattern \ ${ - builtins.concatStringsSep " \\\n" (attrsets.mapAttrsToList + builtins.concatStringsSep " \\\n" (lib.attrsets.mapAttrsToList (k: v: strings.escapeShellArg k + " " + strings.escapeShellArg v) cfg.syntaxHighlighting.pattern) } diff --git a/modules/programs/zsh/zsh-abbr.nix b/modules/programs/zsh/zsh-abbr.nix index 0cc35322..83e1a3fc 100644 --- a/modules/programs/zsh/zsh-abbr.nix +++ b/modules/programs/zsh/zsh-abbr.nix @@ -1,15 +1,15 @@ { config, lib, pkgs, ... }: - -with lib; -let cfg = config.programs.zsh.zsh-abbr; +let + inherit (lib) escapeShellArg mkOption types; + cfg = config.programs.zsh.zsh-abbr; in { - meta.maintainers = [ hm.maintainers.ilaumjd ]; + meta.maintainers = [ lib.hm.maintainers.ilaumjd ]; options.programs.zsh.zsh-abbr = { - enable = - mkEnableOption "zsh-abbr - zsh manager for auto-expanding abbreviations"; + enable = lib.mkEnableOption + "zsh-abbr - zsh manager for auto-expanding abbreviations"; - package = mkPackageOption pkgs "zsh-abbr" { }; + package = lib.mkPackageOption pkgs "zsh-abbr" { }; abbreviations = mkOption { type = types.attrsOf types.str; @@ -41,15 +41,15 @@ in { config = let abbreviations = - mapAttrsToList (k: v: "abbr ${escapeShellArg k}=${escapeShellArg v}") + lib.mapAttrsToList (k: v: "abbr ${escapeShellArg k}=${escapeShellArg v}") cfg.abbreviations; - globalAbbreviations = - mapAttrsToList (k: v: "abbr -g ${escapeShellArg k}=${escapeShellArg v}") + globalAbbreviations = lib.mapAttrsToList + (k: v: "abbr -g ${escapeShellArg k}=${escapeShellArg v}") cfg.globalAbbreviations; allAbbreviations = abbreviations ++ globalAbbreviations; - in mkIf cfg.enable { + in lib.mkIf cfg.enable { programs.zsh.plugins = [{ name = "zsh-abbr"; src = cfg.package; @@ -58,7 +58,7 @@ in { xdg.configFile = { "zsh-abbr/user-abbreviations".text = - concatStringsSep "\n" allAbbreviations + "\n"; + lib.concatStringsSep "\n" allAbbreviations + "\n"; }; }; }