0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-13 21:50:33 +03:00

treewide: set defaultText for options using simple path defaults

adds defaultText for all options that set their default to a path expression
using the ubiquitous `cfg` shortcut bindings.
This commit is contained in:
pennae 2021-12-05 20:40:24 +01:00
parent 70b105d1d0
commit e24a8775a8
21 changed files with 79 additions and 23 deletions

View file

@ -1,12 +1,13 @@
# /etc files related to networking, such as /etc/services. # /etc files related to networking, such as /etc/services.
{ config, lib, pkgs, ... }: { config, lib, options, pkgs, ... }:
with lib; with lib;
let let
cfg = config.networking; cfg = config.networking;
opt = options.networking;
localhostMultiple = any (elem "localhost") (attrValues (removeAttrs cfg.hosts [ "127.0.0.1" "::1" ])); localhostMultiple = any (elem "localhost") (attrValues (removeAttrs cfg.hosts [ "127.0.0.1" "::1" ]));
@ -78,6 +79,7 @@ in
httpProxy = lib.mkOption { httpProxy = lib.mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;
default = cfg.proxy.default; default = cfg.proxy.default;
defaultText = literalExpression "config.${opt.proxy.default}";
description = '' description = ''
This option specifies the http_proxy environment variable. This option specifies the http_proxy environment variable.
''; '';
@ -87,6 +89,7 @@ in
httpsProxy = lib.mkOption { httpsProxy = lib.mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;
default = cfg.proxy.default; default = cfg.proxy.default;
defaultText = literalExpression "config.${opt.proxy.default}";
description = '' description = ''
This option specifies the https_proxy environment variable. This option specifies the https_proxy environment variable.
''; '';
@ -96,6 +99,7 @@ in
ftpProxy = lib.mkOption { ftpProxy = lib.mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;
default = cfg.proxy.default; default = cfg.proxy.default;
defaultText = literalExpression "config.${opt.proxy.default}";
description = '' description = ''
This option specifies the ftp_proxy environment variable. This option specifies the ftp_proxy environment variable.
''; '';
@ -105,6 +109,7 @@ in
rsyncProxy = lib.mkOption { rsyncProxy = lib.mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;
default = cfg.proxy.default; default = cfg.proxy.default;
defaultText = literalExpression "config.${opt.proxy.default}";
description = '' description = ''
This option specifies the rsync_proxy environment variable. This option specifies the rsync_proxy environment variable.
''; '';
@ -114,6 +119,7 @@ in
allProxy = lib.mkOption { allProxy = lib.mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;
default = cfg.proxy.default; default = cfg.proxy.default;
defaultText = literalExpression "config.${opt.proxy.default}";
description = '' description = ''
This option specifies the all_proxy environment variable. This option specifies the all_proxy environment variable.
''; '';

View file

@ -1,8 +1,9 @@
{ config, lib, pkgs, ... }: { config, lib, options, pkgs, ... }:
let let
inherit (lib) mkOption mkEnableOption types mkIf mkMerge optional versionOlder; inherit (lib) literalExpression mkOption mkEnableOption types mkIf mkMerge optional versionOlder;
cfg = config.hardware.system76; cfg = config.hardware.system76;
opt = options.hardware.system76;
kpkgs = config.boot.kernelPackages; kpkgs = config.boot.kernelPackages;
modules = [ "system76" "system76-io" ] ++ (optional (versionOlder kpkgs.kernel.version "5.5") "system76-acpi"); modules = [ "system76" "system76-io" ] ++ (optional (versionOlder kpkgs.kernel.version "5.5") "system76-acpi");
@ -60,6 +61,7 @@ in {
firmware-daemon.enable = mkOption { firmware-daemon.enable = mkOption {
default = cfg.enableAll; default = cfg.enableAll;
defaultText = literalExpression "config.${opt.enableAll}";
example = true; example = true;
description = "Whether to enable the system76 firmware daemon"; description = "Whether to enable the system76 firmware daemon";
type = types.bool; type = types.bool;
@ -67,6 +69,7 @@ in {
kernel-modules.enable = mkOption { kernel-modules.enable = mkOption {
default = cfg.enableAll; default = cfg.enableAll;
defaultText = literalExpression "config.${opt.enableAll}";
example = true; example = true;
description = "Whether to make the system76 out-of-tree kernel modules available"; description = "Whether to make the system76 out-of-tree kernel modules available";
type = types.bool; type = types.bool;
@ -74,6 +77,7 @@ in {
power-daemon.enable = mkOption { power-daemon.enable = mkOption {
default = cfg.enableAll; default = cfg.enableAll;
defaultText = literalExpression "config.${opt.enableAll}";
example = true; example = true;
description = "Whether to enable the system76 power daemon"; description = "Whether to enable the system76 power daemon";
type = types.bool; type = types.bool;

View file

@ -1,9 +1,10 @@
{ config, lib, pkgs, ... }: { config, lib, options, pkgs, ... }:
with lib; with lib;
let let
cfg = config.system.nixos; cfg = config.system.nixos;
opt = options.system.nixos;
in in
{ {
@ -53,6 +54,7 @@ in
stateVersion = mkOption { stateVersion = mkOption {
type = types.str; type = types.str;
default = cfg.release; default = cfg.release;
defaultText = literalExpression "config.${opt.release}";
description = '' description = ''
Every once in a while, a new NixOS release may change Every once in a while, a new NixOS release may change
configuration defaults in a way incompatible with stateful configuration defaults in a way incompatible with stateful

View file

@ -1,6 +1,6 @@
# This module defines global configuration for the zshell. # This module defines global configuration for the zshell.
{ config, lib, pkgs, ... }: { config, lib, options, pkgs, ... }:
with lib; with lib;
@ -9,6 +9,7 @@ let
cfge = config.environment; cfge = config.environment;
cfg = config.programs.zsh; cfg = config.programs.zsh;
opt = options.programs.zsh;
zshAliases = concatStringsSep "\n" ( zshAliases = concatStringsSep "\n" (
mapAttrsFlatten (k: v: "alias ${k}=${escapeShellArg v}") mapAttrsFlatten (k: v: "alias ${k}=${escapeShellArg v}")
@ -147,6 +148,7 @@ in
enableGlobalCompInit = mkOption { enableGlobalCompInit = mkOption {
default = cfg.enableCompletion; default = cfg.enableCompletion;
defaultText = literalExpression "config.${opt.enableCompletion}";
description = '' description = ''
Enable execution of compinit call for all interactive zsh shells. Enable execution of compinit call for all interactive zsh shells.

View file

@ -2,6 +2,7 @@
with lib; with lib;
let let
cfg = config.security.acme; cfg = config.security.acme;
opt = options.security.acme;
# Used to calculate timer accuracy for coalescing # Used to calculate timer accuracy for coalescing
numCerts = length (builtins.attrNames cfg.certs); numCerts = length (builtins.attrNames cfg.certs);
@ -470,6 +471,7 @@ let
email = mkOption { email = mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;
default = cfg.email; default = cfg.email;
defaultText = literalExpression "config.${opt.email}";
description = "Contact email address for the CA to be able to reach you."; description = "Contact email address for the CA to be able to reach you.";
}; };

View file

@ -1,8 +1,9 @@
{ config, lib, pkgs, ... }: { config, lib, options, pkgs, ... }:
let let
inherit (lib) mkOption types; inherit (lib) literalExpression mkOption types;
cfg = config.security.dhparams; cfg = config.security.dhparams;
opt = options.security.dhparams;
bitType = types.addCheck types.int (b: b >= 16) // { bitType = types.addCheck types.int (b: b >= 16) // {
name = "bits"; name = "bits";
@ -13,6 +14,7 @@ let
options.bits = mkOption { options.bits = mkOption {
type = bitType; type = bitType;
default = cfg.defaultBitSize; default = cfg.defaultBitSize;
defaultText = literalExpression "config.${opt.defaultBitSize}";
description = '' description = ''
The bit size for the prime that is used during a Diffie-Hellman The bit size for the prime that is used during a Diffie-Hellman
key exchange. key exchange.

View file

@ -1,9 +1,10 @@
{ config, lib, pkgs, ... }: { config, lib, options, pkgs, ... }:
with lib; with lib;
let let
cfg = config.services.kubernetes; cfg = config.services.kubernetes;
opt = options.services.kubernetes;
defaultContainerdSettings = { defaultContainerdSettings = {
version = 2; version = 2;
@ -87,6 +88,7 @@ let
description = "${prefix} certificate authority file used to connect to kube-apiserver."; description = "${prefix} certificate authority file used to connect to kube-apiserver.";
type = types.nullOr types.path; type = types.nullOr types.path;
default = cfg.caFile; default = cfg.caFile;
defaultText = literalExpression "config.${opt.caFile}";
}; };
certFile = mkOption { certFile = mkOption {

View file

@ -1,4 +1,4 @@
{ config, lib, pkgs, ... }: { config, lib, options, pkgs, ... }:
with lib; with lib;
@ -76,6 +76,7 @@ in
clusterDomain = mkOption { clusterDomain = mkOption {
description = "Use alternative domain."; description = "Use alternative domain.";
default = config.services.kubernetes.addons.dns.clusterDomain; default = config.services.kubernetes.addons.dns.clusterDomain;
defaultText = literalExpression "config.${options.services.kubernetes.addons.dns.clusterDomain}";
type = str; type = str;
}; };

View file

@ -1,10 +1,11 @@
{ config, lib, pkgs, ... }: { config, lib, options, pkgs, ... }:
with lib; with lib;
let let
cfg = config.services.slurm; cfg = config.services.slurm;
opt = options.services.slurm;
# configuration file can be generated by http://slurm.schedmd.com/configurator.html # configuration file can be generated by http://slurm.schedmd.com/configurator.html
defaultUser = "slurm"; defaultUser = "slurm";
@ -89,6 +90,7 @@ in
storageUser = mkOption { storageUser = mkOption {
type = types.str; type = types.str;
default = cfg.user; default = cfg.user;
defaultText = literalExpression "config.${opt.user}";
description = '' description = ''
Database user name. Database user name.
''; '';
@ -153,6 +155,7 @@ in
controlAddr = mkOption { controlAddr = mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;
default = cfg.controlMachine; default = cfg.controlMachine;
defaultText = literalExpression "config.${opt.controlMachine}";
example = null; example = null;
description = '' description = ''
Name that ControlMachine should be referred to in establishing a Name that ControlMachine should be referred to in establishing a

View file

@ -1,9 +1,10 @@
{ config, lib, pkgs, ... }: { config, lib, options, pkgs, ... }:
with lib; with lib;
let let
cfg = config.services.etcd; cfg = config.services.etcd;
opt = options.services.etcd;
in { in {
@ -23,6 +24,7 @@ in {
advertiseClientUrls = mkOption { advertiseClientUrls = mkOption {
description = "Etcd list of this member's client URLs to advertise to the rest of the cluster."; description = "Etcd list of this member's client URLs to advertise to the rest of the cluster.";
default = cfg.listenClientUrls; default = cfg.listenClientUrls;
defaultText = literalExpression "config.${opt.listenClientUrls}";
type = types.listOf types.str; type = types.listOf types.str;
}; };
@ -41,6 +43,7 @@ in {
initialAdvertisePeerUrls = mkOption { initialAdvertisePeerUrls = mkOption {
description = "Etcd list of this member's peer URLs to advertise to rest of the cluster."; description = "Etcd list of this member's peer URLs to advertise to rest of the cluster.";
default = cfg.listenPeerUrls; default = cfg.listenPeerUrls;
defaultText = literalExpression "config.${opt.listenPeerUrls}";
type = types.listOf types.str; type = types.listOf types.str;
}; };
@ -95,18 +98,21 @@ in {
peerCertFile = mkOption { peerCertFile = mkOption {
description = "Cert file to use for peer to peer communication"; description = "Cert file to use for peer to peer communication";
default = cfg.certFile; default = cfg.certFile;
defaultText = literalExpression "config.${opt.certFile}";
type = types.nullOr types.path; type = types.nullOr types.path;
}; };
peerKeyFile = mkOption { peerKeyFile = mkOption {
description = "Key file to use for peer to peer communication"; description = "Key file to use for peer to peer communication";
default = cfg.keyFile; default = cfg.keyFile;
defaultText = literalExpression "config.${opt.keyFile}";
type = types.nullOr types.path; type = types.nullOr types.path;
}; };
peerTrustedCaFile = mkOption { peerTrustedCaFile = mkOption {
description = "Certificate authority file to use for peer to peer communication"; description = "Certificate authority file to use for peer to peer communication";
default = cfg.trustedCaFile; default = cfg.trustedCaFile;
defaultText = literalExpression "config.${opt.trustedCaFile}";
type = types.nullOr types.path; type = types.nullOr types.path;
}; };

View file

@ -1,9 +1,10 @@
{ config, lib, pkgs, utils, ... }: { config, lib, options, pkgs, utils, ... }:
with lib; with lib;
let let
cfg = config.services.gitlab; cfg = config.services.gitlab;
opt = options.services.gitlab;
ruby = cfg.packages.gitlab.ruby; ruby = cfg.packages.gitlab.ruby;
@ -552,6 +553,7 @@ in {
defaultForProjects = mkOption { defaultForProjects = mkOption {
type = types.bool; type = types.bool;
default = cfg.registry.enable; default = cfg.registry.enable;
defaultText = literalExpression "config.${opt.registry.enable}";
description = "If GitLab container registry should be enabled by default for projects."; description = "If GitLab container registry should be enabled by default for projects.";
}; };
issuer = mkOption { issuer = mkOption {

View file

@ -1,9 +1,10 @@
{ config, lib, pkgs, ... }: { config, lib, options, pkgs, ... }:
with lib; with lib;
let let
cfg = config.services.mwlib; cfg = config.services.mwlib;
opt = options.services.mwlib;
pypkgs = pkgs.python27Packages; pypkgs = pkgs.python27Packages;
inherit (pypkgs) python mwlib; inherit (pypkgs) python mwlib;
@ -96,6 +97,7 @@ in
nslave = { nslave = {
enable = mkOption { enable = mkOption {
default = cfg.qserve.enable; default = cfg.qserve.enable;
defaultText = literalExpression "config.${opt.qserve.enable}";
type = types.bool; type = types.bool;
description = '' description = ''
Pulls new jobs from exactly one qserve instance Pulls new jobs from exactly one qserve instance

View file

@ -1,9 +1,10 @@
{ config, lib, pkgs, ... }: { config, lib, options, pkgs, ... }:
with lib; with lib;
let let
cfg = config.services.rippled; cfg = config.services.rippled;
opt = options.services.rippled;
b2i = val: if val then "1" else "0"; b2i = val: if val then "1" else "0";
@ -165,6 +166,7 @@ let
description = "Location to store the database."; description = "Location to store the database.";
type = types.path; type = types.path;
default = cfg.databasePath; default = cfg.databasePath;
defaultText = literalExpression "config.${opt.databasePath}";
}; };
compression = mkOption { compression = mkOption {
@ -177,6 +179,7 @@ let
description = "Enable automatic purging of older ledger information."; description = "Enable automatic purging of older ledger information.";
type = types.nullOr (types.addCheck types.int (v: v > 256)); type = types.nullOr (types.addCheck types.int (v: v > 256));
default = cfg.ledgerHistory; default = cfg.ledgerHistory;
defaultText = literalExpression "config.${opt.ledgerHistory}";
}; };
advisoryDelete = mkOption { advisoryDelete = mkOption {

View file

@ -1,4 +1,4 @@
{ config, lib, pkgs, ... }: { config, lib, options, pkgs, ... }:
with lib; with lib;
@ -8,6 +8,7 @@ let
+ optionalString (config.networking.domain != null) ".${config.networking.domain}"; + optionalString (config.networking.domain != null) ".${config.networking.domain}";
cfg = config.services.smartd; cfg = config.services.smartd;
opt = options.services.smartd;
nm = cfg.notifications.mail; nm = cfg.notifications.mail;
nw = cfg.notifications.wall; nw = cfg.notifications.wall;
@ -208,6 +209,7 @@ in
autodetected = mkOption { autodetected = mkOption {
default = cfg.defaults.monitored; default = cfg.defaults.monitored;
defaultText = literalExpression "config.${opt.defaults.monitored}";
type = types.separatedString " "; type = types.separatedString " ";
description = '' description = ''
Like <option>services.smartd.defaults.monitored</option>, but for the Like <option>services.smartd.defaults.monitored</option>, but for the

View file

@ -1,9 +1,10 @@
{ config, lib, pkgs, ... }: { config, lib, options, pkgs, ... }:
let let
cfg = config.services.ergo; cfg = config.services.ergo;
opt = options.services.ergo;
inherit (lib) mkEnableOption mkIf mkOption optionalString types; inherit (lib) literalExpression mkEnableOption mkIf mkOption optionalString types;
configFile = pkgs.writeText "ergo.conf" ('' configFile = pkgs.writeText "ergo.conf" (''
ergo { ergo {
@ -92,6 +93,7 @@ in {
group = mkOption { group = mkOption {
type = types.str; type = types.str;
default = cfg.user; default = cfg.user;
defaultText = literalExpression "config.${opt.user}";
description = "The group as which to run the Ergo node."; description = "The group as which to run the Ergo node.";
}; };

View file

@ -1,9 +1,10 @@
{ config, pkgs, lib, ... }: { config, options, pkgs, lib, ... }:
let let
inherit (lib) mkEnableOption mkIf mkOption literalExpression types optionalString; inherit (lib) mkEnableOption mkIf mkOption literalExpression types optionalString;
cfg = config.services.quorum; cfg = config.services.quorum;
opt = options.services.quorum;
dataDir = "/var/lib/quorum"; dataDir = "/var/lib/quorum";
genesisFile = pkgs.writeText "genesis.json" (builtins.toJSON cfg.genesis); genesisFile = pkgs.writeText "genesis.json" (builtins.toJSON cfg.genesis);
staticNodesFile = pkgs.writeText "static-nodes.json" (builtins.toJSON cfg.staticNodes); staticNodesFile = pkgs.writeText "static-nodes.json" (builtins.toJSON cfg.staticNodes);
@ -23,6 +24,7 @@ in {
group = mkOption { group = mkOption {
type = types.str; type = types.str;
default = cfg.user; default = cfg.user;
defaultText = literalExpression "config.${opt.user}";
description = "The group as which to run quorum."; description = "The group as which to run quorum.";
}; };

View file

@ -1,9 +1,10 @@
{ config, lib, pkgs, ... }: { config, lib, options, pkgs, ... }:
let let
cfg = config.services.wasabibackend; cfg = config.services.wasabibackend;
opt = options.services.wasabibackend;
inherit (lib) mkEnableOption mkIf mkOption optionalAttrs optionalString types; inherit (lib) literalExpression mkEnableOption mkIf mkOption optionalAttrs optionalString types;
confOptions = { confOptions = {
BitcoinRpcConnectionString = "${cfg.rpc.user}:${cfg.rpc.password}"; BitcoinRpcConnectionString = "${cfg.rpc.user}:${cfg.rpc.password}";
@ -103,6 +104,7 @@ in {
group = mkOption { group = mkOption {
type = types.str; type = types.str;
default = cfg.user; default = cfg.user;
defaultText = literalExpression "config.${opt.user}";
description = "The group as which to run the wasabibackend node."; description = "The group as which to run the wasabibackend node.";
}; };
}; };

View file

@ -1,9 +1,10 @@
{ config, lib, pkgs, ... }: { config, lib, options, pkgs, ... }:
with lib; with lib;
let let
cfg = config.services.epgstation; cfg = config.services.epgstation;
opt = options.services.epgstation;
username = config.users.users.epgstation.name; username = config.users.users.epgstation.name;
groupname = config.users.users.epgstation.group; groupname = config.users.users.epgstation.group;
@ -80,6 +81,7 @@ in
clientSocketioPort = mkOption { clientSocketioPort = mkOption {
type = types.port; type = types.port;
default = cfg.socketioPort; default = cfg.socketioPort;
defaultText = literalExpression "config.${opt.socketioPort}";
description = '' description = ''
Socket.io port that the web client is going to connect to. This may be Socket.io port that the web client is going to connect to. This may be
different from <option>socketioPort</option> if EPGStation is hidden different from <option>socketioPort</option> if EPGStation is hidden

View file

@ -4,6 +4,7 @@ let
json = pkgs.formats.json {}; json = pkgs.formats.json {};
cfg = config.services.discourse; cfg = config.services.discourse;
opt = options.services.discourse;
# Keep in sync with https://github.com/discourse/discourse_docker/blob/master/image/base/Dockerfile#L5 # Keep in sync with https://github.com/discourse/discourse_docker/blob/master/image/base/Dockerfile#L5
upstreamPostgresqlVersion = lib.getVersion pkgs.postgresql_13; upstreamPostgresqlVersion = lib.getVersion pkgs.postgresql_13;
@ -399,6 +400,7 @@ in
domain = lib.mkOption { domain = lib.mkOption {
type = lib.types.str; type = lib.types.str;
default = cfg.hostname; default = cfg.hostname;
defaultText = lib.literalExpression "config.${opt.hostname}";
description = '' description = ''
HELO domain to use for outgoing mail. HELO domain to use for outgoing mail.
''; '';

View file

@ -1,7 +1,8 @@
{ lib, pkgs, config, ... }: { lib, pkgs, config, options, ... }:
let let
cfg = config.services.peertube; cfg = config.services.peertube;
opt = options.services.peertube;
settingsFormat = pkgs.formats.json {}; settingsFormat = pkgs.formats.json {};
configFile = settingsFormat.generate "production.json" cfg.settings; configFile = settingsFormat.generate "production.json" cfg.settings;
@ -212,6 +213,7 @@ in {
enableUnixSocket = lib.mkOption { enableUnixSocket = lib.mkOption {
type = lib.types.bool; type = lib.types.bool;
default = cfg.redis.createLocally; default = cfg.redis.createLocally;
defaultText = lib.literalExpression "config.${opt.redis.createLocally}";
description = "Use Unix socket."; description = "Use Unix socket.";
}; };
}; };

View file

@ -1,8 +1,9 @@
{ config, lib, pkgs, ... }: { config, lib, options, pkgs, ... }:
with lib; with lib;
let cfg = config.services.xserver.synaptics; let cfg = config.services.xserver.synaptics;
opt = options.services.xserver.synaptics;
tapConfig = if cfg.tapButtons then enabledTapConfig else disabledTapConfig; tapConfig = if cfg.tapButtons then enabledTapConfig else disabledTapConfig;
enabledTapConfig = '' enabledTapConfig = ''
Option "MaxTapTime" "180" Option "MaxTapTime" "180"
@ -77,24 +78,28 @@ in {
horizTwoFingerScroll = mkOption { horizTwoFingerScroll = mkOption {
type = types.bool; type = types.bool;
default = cfg.twoFingerScroll; default = cfg.twoFingerScroll;
defaultText = literalExpression "config.${opt.twoFingerScroll}";
description = "Whether to enable horizontal two-finger drag-scrolling."; description = "Whether to enable horizontal two-finger drag-scrolling.";
}; };
vertTwoFingerScroll = mkOption { vertTwoFingerScroll = mkOption {
type = types.bool; type = types.bool;
default = cfg.twoFingerScroll; default = cfg.twoFingerScroll;
defaultText = literalExpression "config.${opt.twoFingerScroll}";
description = "Whether to enable vertical two-finger drag-scrolling."; description = "Whether to enable vertical two-finger drag-scrolling.";
}; };
horizEdgeScroll = mkOption { horizEdgeScroll = mkOption {
type = types.bool; type = types.bool;
default = ! cfg.horizTwoFingerScroll; default = ! cfg.horizTwoFingerScroll;
defaultText = literalExpression "! config.${opt.horizTwoFingerScroll}";
description = "Whether to enable horizontal edge drag-scrolling."; description = "Whether to enable horizontal edge drag-scrolling.";
}; };
vertEdgeScroll = mkOption { vertEdgeScroll = mkOption {
type = types.bool; type = types.bool;
default = ! cfg.vertTwoFingerScroll; default = ! cfg.vertTwoFingerScroll;
defaultText = literalExpression "! config.${opt.vertTwoFingerScroll}";
description = "Whether to enable vertical edge drag-scrolling."; description = "Whether to enable vertical edge drag-scrolling.";
}; };