Skip to content

Commit

Permalink
Merge pull request #148785 from pennae/more-option-doc-staticizing
Browse files Browse the repository at this point in the history
treewide: more defaultText for options
  • Loading branch information
grahamc authored Dec 17, 2021
2 parents 4edd5c9 + e67a646 commit 06edb74
Show file tree
Hide file tree
Showing 107 changed files with 591 additions and 161 deletions.
2 changes: 2 additions & 0 deletions lib/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,8 @@ rec {
definitions = map (def: def.value) res.defsFinal;
files = map (def: def.file) res.defsFinal;
inherit (res) isDefined;
# This allows options to be correctly displayed using `${options.path.to.it}`
__toString = _: showOption loc;
};

# Merge definitions of a value of a given type.
Expand Down
8 changes: 7 additions & 1 deletion nixos/modules/config/networking.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# /etc files related to networking, such as /etc/services.

{ config, lib, pkgs, ... }:
{ config, lib, options, pkgs, ... }:

with lib;

let

cfg = config.networking;
opt = options.networking;

localhostMultiple = any (elem "localhost") (attrValues (removeAttrs cfg.hosts [ "127.0.0.1" "::1" ]));

Expand Down Expand Up @@ -78,6 +79,7 @@ in
httpProxy = lib.mkOption {
type = types.nullOr types.str;
default = cfg.proxy.default;
defaultText = literalExpression "config.${opt.proxy.default}";
description = ''
This option specifies the http_proxy environment variable.
'';
Expand All @@ -87,6 +89,7 @@ in
httpsProxy = lib.mkOption {
type = types.nullOr types.str;
default = cfg.proxy.default;
defaultText = literalExpression "config.${opt.proxy.default}";
description = ''
This option specifies the https_proxy environment variable.
'';
Expand All @@ -96,6 +99,7 @@ in
ftpProxy = lib.mkOption {
type = types.nullOr types.str;
default = cfg.proxy.default;
defaultText = literalExpression "config.${opt.proxy.default}";
description = ''
This option specifies the ftp_proxy environment variable.
'';
Expand All @@ -105,6 +109,7 @@ in
rsyncProxy = lib.mkOption {
type = types.nullOr types.str;
default = cfg.proxy.default;
defaultText = literalExpression "config.${opt.proxy.default}";
description = ''
This option specifies the rsync_proxy environment variable.
'';
Expand All @@ -114,6 +119,7 @@ in
allProxy = lib.mkOption {
type = types.nullOr types.str;
default = cfg.proxy.default;
defaultText = literalExpression "config.${opt.proxy.default}";
description = ''
This option specifies the all_proxy environment variable.
'';
Expand Down
22 changes: 16 additions & 6 deletions nixos/modules/config/system-path.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,17 @@ let
pkgs.zstd
];

defaultPackages = map (pkg: setPrio ((pkg.meta.priority or 5) + 3) pkg)
[ pkgs.nano
pkgs.perl
pkgs.rsync
pkgs.strace
];
defaultPackageNames =
[ "nano"
"perl"
"rsync"
"strace"
];
defaultPackages =
map
(n: let pkg = pkgs.${n}; in setPrio ((pkg.meta.priority or 5) + 3) pkg)
defaultPackageNames;
defaultPackagesText = "[ ${concatMapStringsSep " " (n: "pkgs.${n}") defaultPackageNames } ]";

in

Expand All @@ -73,6 +78,11 @@ in
defaultPackages = mkOption {
type = types.listOf types.package;
default = defaultPackages;
defaultText = literalDocBook ''
these packages, with their <literal>meta.priority</literal> numerically increased
(thus lowering their installation priority):
<programlisting>${defaultPackagesText}</programlisting>
'';
example = [];
description = ''
Set of default packages that aren't strictly necessary
Expand Down
8 changes: 6 additions & 2 deletions nixos/modules/hardware/system-76.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{ config, lib, pkgs, ... }:
{ config, lib, options, pkgs, ... }:

let
inherit (lib) mkOption mkEnableOption types mkIf mkMerge optional versionOlder;
inherit (lib) literalExpression mkOption mkEnableOption types mkIf mkMerge optional versionOlder;
cfg = config.hardware.system76;
opt = options.hardware.system76;

kpkgs = config.boot.kernelPackages;
modules = [ "system76" "system76-io" ] ++ (optional (versionOlder kpkgs.kernel.version "5.5") "system76-acpi");
Expand Down Expand Up @@ -60,20 +61,23 @@ in {

firmware-daemon.enable = mkOption {
default = cfg.enableAll;
defaultText = literalExpression "config.${opt.enableAll}";
example = true;
description = "Whether to enable the system76 firmware daemon";
type = types.bool;
};

kernel-modules.enable = mkOption {
default = cfg.enableAll;
defaultText = literalExpression "config.${opt.enableAll}";
example = true;
description = "Whether to make the system76 out-of-tree kernel modules available";
type = types.bool;
};

power-daemon.enable = mkOption {
default = cfg.enableAll;
defaultText = literalExpression "config.${opt.enableAll}";
example = true;
description = "Whether to enable the system76 power daemon";
type = types.bool;
Expand Down
4 changes: 3 additions & 1 deletion nixos/modules/misc/version.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{ config, lib, pkgs, ... }:
{ config, lib, options, pkgs, ... }:

with lib;

let
cfg = config.system.nixos;
opt = options.system.nixos;
in

{
Expand Down Expand Up @@ -53,6 +54,7 @@ in
stateVersion = mkOption {
type = types.str;
default = cfg.release;
defaultText = literalExpression "config.${opt.release}";
description = ''
Every once in a while, a new NixOS release may change
configuration defaults in a way incompatible with stateful
Expand Down
26 changes: 14 additions & 12 deletions nixos/modules/programs/captive-browser.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
with lib;
let
cfg = config.programs.captive-browser;
browserDefault = chromium: concatStringsSep " " [
''env XDG_CONFIG_HOME="$PREV_CONFIG_HOME"''
''${chromium}/bin/chromium''
''--user-data-dir=''${XDG_DATA_HOME:-$HOME/.local/share}/chromium-captive''
''--proxy-server="socks5://$PROXY"''
''--host-resolver-rules="MAP * ~NOTFOUND , EXCLUDE localhost"''
''--no-first-run''
''--new-window''
''--incognito''
''-no-default-browser-check''
''http://cache.nixos.org/''
];
in
{
###### interface
Expand All @@ -26,18 +38,8 @@ in
# the options below are the same as in "captive-browser.toml"
browser = mkOption {
type = types.str;
default = concatStringsSep " " [
''env XDG_CONFIG_HOME="$PREV_CONFIG_HOME"''
''${pkgs.chromium}/bin/chromium''
''--user-data-dir=''${XDG_DATA_HOME:-$HOME/.local/share}/chromium-captive''
''--proxy-server="socks5://$PROXY"''
''--host-resolver-rules="MAP * ~NOTFOUND , EXCLUDE localhost"''
''--no-first-run''
''--new-window''
''--incognito''
''-no-default-browser-check''
''http://cache.nixos.org/''
];
default = browserDefault pkgs.chromium;
defaultText = literalExpression (browserDefault "\${pkgs.chromium}");
description = ''
The shell (/bin/sh) command executed once the proxy starts.
When browser exits, the proxy exits. An extra env var PROXY is available.
Expand Down
1 change: 1 addition & 0 deletions nixos/modules/programs/gnupg.nix
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ in
type = types.nullOr (types.enum pkgs.pinentry.flavors);
example = "gnome3";
default = defaultPinentryFlavor;
defaultText = literalDocBook ''matching the configured desktop environment'';
description = ''
Which pinentry interface to use. If not null, the path to the
pinentry binary will be passed to gpg-agent via commandline and
Expand Down
4 changes: 3 additions & 1 deletion nixos/modules/programs/zsh/zsh.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This module defines global configuration for the zshell.

{ config, lib, pkgs, ... }:
{ config, lib, options, pkgs, ... }:

with lib;

Expand All @@ -9,6 +9,7 @@ let
cfge = config.environment;

cfg = config.programs.zsh;
opt = options.programs.zsh;

zshAliases = concatStringsSep "\n" (
mapAttrsFlatten (k: v: "alias ${k}=${escapeShellArg v}")
Expand Down Expand Up @@ -147,6 +148,7 @@ in

enableGlobalCompInit = mkOption {
default = cfg.enableCompletion;
defaultText = literalExpression "config.${opt.enableCompletion}";
description = ''
Enable execution of compinit call for all interactive zsh shells.
Expand Down
2 changes: 2 additions & 0 deletions nixos/modules/security/acme.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
with lib;
let
cfg = config.security.acme;
opt = options.security.acme;

# Used to calculate timer accuracy for coalescing
numCerts = length (builtins.attrNames cfg.certs);
Expand Down Expand Up @@ -485,6 +486,7 @@ let
email = mkOption {
type = types.nullOr types.str;
default = cfg.email;
defaultText = literalExpression "config.${opt.email}";
description = "Contact email address for the CA to be able to reach you.";
};

Expand Down
6 changes: 4 additions & 2 deletions nixos/modules/security/dhparams.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{ config, lib, pkgs, ... }:
{ config, lib, options, pkgs, ... }:

let
inherit (lib) mkOption types;
inherit (lib) literalExpression mkOption types;
cfg = config.security.dhparams;
opt = options.security.dhparams;

bitType = types.addCheck types.int (b: b >= 16) // {
name = "bits";
Expand All @@ -13,6 +14,7 @@ let
options.bits = mkOption {
type = bitType;
default = cfg.defaultBitSize;
defaultText = literalExpression "config.${opt.defaultBitSize}";
description = ''
The bit size for the prime that is used during a Diffie-Hellman
key exchange.
Expand Down
13 changes: 12 additions & 1 deletion nixos/modules/services/audio/mpdscribble.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{ config, lib, pkgs, ... }:
{ config, lib, options, pkgs, ... }:

with lib;

let
cfg = config.services.mpdscribble;
mpdCfg = config.services.mpd;
mpdOpt = options.services.mpd;

endpointUrls = {
"last.fm" = "http://post.audioscrobbler.com";
Expand Down Expand Up @@ -108,6 +109,11 @@ in {
mpdCfg.network.listenAddress
else
"localhost");
defaultText = literalExpression ''
if config.${mpdOpt.network.listenAddress} != "any"
then config.${mpdOpt.network.listenAddress}
else "localhost"
'';
type = types.str;
description = ''
Host for the mpdscribble daemon to search for a mpd daemon on.
Expand All @@ -122,6 +128,10 @@ in {
mpdCfg.credentials).passwordFile
else
null;
defaultText = literalDocBook ''
The first password file with read access configured for MPD when using a local instance,
otherwise <literal>null</literal>.
'';
type = types.nullOr types.str;
description = ''
File containing the password for the mpd daemon.
Expand All @@ -132,6 +142,7 @@ in {

port = mkOption {
default = mpdCfg.network.port;
defaultText = literalExpression "config.${mpdOpt.network.port}";
type = types.port;
description = ''
Port for the mpdscribble daemon to search for a mpd daemon on.
Expand Down
9 changes: 7 additions & 2 deletions nixos/modules/services/backup/tarsnap.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{ config, lib, pkgs, utils, ... }:
{ config, lib, options, pkgs, utils, ... }:

with lib;

let
gcfg = config.services.tarsnap;
opt = options.services.tarsnap;

configFile = name: cfg: ''
keyfile ${cfg.keyfile}
Expand Down Expand Up @@ -59,12 +60,13 @@ in
};

archives = mkOption {
type = types.attrsOf (types.submodule ({ config, ... }:
type = types.attrsOf (types.submodule ({ config, options, ... }:
{
options = {
keyfile = mkOption {
type = types.str;
default = gcfg.keyfile;
defaultText = literalExpression "config.${opt.keyfile}";
description = ''
Set a specific keyfile for this archive. This defaults to
<literal>"/root/tarsnap.key"</literal> if left unspecified.
Expand All @@ -87,6 +89,9 @@ in
cachedir = mkOption {
type = types.nullOr types.path;
default = "/var/cache/tarsnap/${utils.escapeSystemdPath config.keyfile}";
defaultText = literalExpression ''
"/var/cache/tarsnap/''${utils.escapeSystemdPath config.${options.keyfile}}"
'';
description = ''
The cache allows tarsnap to identify previously stored data
blocks, reducing archival time and bandwidth usage.
Expand Down
14 changes: 13 additions & 1 deletion nixos/modules/services/cluster/hadoop/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{ config, lib, pkgs, ...}:
{ config, lib, options, pkgs, ...}:
let
cfg = config.services.hadoop;
opt = options.services.hadoop;
in
with lib;
{
Expand Down Expand Up @@ -44,6 +45,14 @@ with lib;
"mapreduce.map.env" = "HADOOP_MAPRED_HOME=${cfg.package}/lib/${cfg.package.untarDir}";
"mapreduce.reduce.env" = "HADOOP_MAPRED_HOME=${cfg.package}/lib/${cfg.package.untarDir}";
};
defaultText = literalExpression ''
{
"mapreduce.framework.name" = "yarn";
"yarn.app.mapreduce.am.env" = "HADOOP_MAPRED_HOME=''${config.${opt.package}}/lib/''${config.${opt.package}.untarDir}";
"mapreduce.map.env" = "HADOOP_MAPRED_HOME=''${config.${opt.package}}/lib/''${config.${opt.package}.untarDir}";
"mapreduce.reduce.env" = "HADOOP_MAPRED_HOME=''${config.${opt.package}}/lib/''${config.${opt.package}.untarDir}";
}
'';
type = types.attrsOf types.anything;
example = literalExpression ''
options.services.hadoop.mapredSite.default // {
Expand Down Expand Up @@ -98,6 +107,9 @@ with lib;

log4jProperties = mkOption {
default = "${cfg.package}/lib/${cfg.package.untarDir}/etc/hadoop/log4j.properties";
defaultText = literalExpression ''
"''${config.${opt.package}}/lib/''${config.${opt.package}.untarDir}/etc/hadoop/log4j.properties"
'';
type = types.path;
example = literalExpression ''
"''${pkgs.hadoop}/lib/''${pkgs.hadoop.untarDir}/etc/hadoop/log4j.properties";
Expand Down
Loading

0 comments on commit 06edb74

Please sign in to comment.