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

treewide: format all inactive Nix files

After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build https://github.com/infinisil/treewide-nixpkgs-reformat-script/archive/a08b3a4d199c6124ac5b36a889d9099b4383463f.tar.gz \
      --argstr baseRev 0128fbb0a5
    result/bin/apply-formatting $NIXPKGS_PATH
This commit is contained in:
Silvan Mosberger 2024-12-10 20:29:24 +01:00
parent 0128fbb0a5
commit d9d87c5196
21586 changed files with 712147 additions and 434007 deletions

View file

@ -1,26 +1,65 @@
{ config, lib, pkgs, ... }:
{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.pgadmin;
_base = with lib.types; [ int bool str ];
base = with lib.types; oneOf ([ (listOf (oneOf _base)) (attrsOf (oneOf _base)) ] ++ _base);
_base = with lib.types; [
int
bool
str
];
base =
with lib.types;
oneOf (
[
(listOf (oneOf _base))
(attrsOf (oneOf _base))
]
++ _base
);
formatAttrset = attr:
"{${lib.concatStringsSep "\n" (lib.mapAttrsToList (key: value: "${builtins.toJSON key}: ${formatPyValue value},") attr)}}";
formatAttrset =
attr:
"{${
lib.concatStringsSep "\n" (
lib.mapAttrsToList (key: value: "${builtins.toJSON key}: ${formatPyValue value},") attr
)
}}";
formatPyValue = value:
if builtins.isString value then builtins.toJSON value
else if value ? _expr then value._expr
else if builtins.isInt value then toString value
else if builtins.isBool value then (if value then "True" else "False")
else if builtins.isAttrs value then (formatAttrset value)
else if builtins.isList value then "[${lib.concatStringsSep "\n" (map (v: "${formatPyValue v},") value)}]"
else throw "Unrecognized type";
formatPyValue =
value:
if builtins.isString value then
builtins.toJSON value
else if value ? _expr then
value._expr
else if builtins.isInt value then
toString value
else if builtins.isBool value then
(if value then "True" else "False")
else if builtins.isAttrs value then
(formatAttrset value)
else if builtins.isList value then
"[${lib.concatStringsSep "\n" (map (v: "${formatPyValue v},") value)}]"
else
throw "Unrecognized type";
formatPy = attrs:
lib.concatStringsSep "\n" (lib.mapAttrsToList (key: value: "${key} = ${formatPyValue value}") attrs);
formatPy =
attrs:
lib.concatStringsSep "\n" (
lib.mapAttrsToList (key: value: "${key} = ${formatPyValue value}") attrs
);
pyType = with lib.types; attrsOf (oneOf [ (attrsOf base) (listOf base) base ]);
pyType =
with lib.types;
attrsOf (oneOf [
(attrsOf base)
(listOf base)
base
]);
in
{
options.services.pgadmin = {
@ -118,21 +157,24 @@ in
config = lib.mkIf (cfg.enable) {
networking.firewall.allowedTCPPorts = lib.mkIf (cfg.openFirewall) [ cfg.port ];
services.pgadmin.settings = {
DEFAULT_SERVER_PORT = cfg.port;
PASSWORD_LENGTH_MIN = cfg.minimumPasswordLength;
SERVER_MODE = true;
UPGRADE_CHECK_ENABLED = false;
} // (lib.optionalAttrs cfg.openFirewall {
DEFAULT_SERVER = lib.mkDefault "::";
}) // (lib.optionalAttrs cfg.emailServer.enable {
MAIL_SERVER = cfg.emailServer.address;
MAIL_PORT = cfg.emailServer.port;
MAIL_USE_SSL = cfg.emailServer.useSSL;
MAIL_USE_TLS = cfg.emailServer.useTLS;
MAIL_USERNAME = cfg.emailServer.username;
SECURITY_EMAIL_SENDER = cfg.emailServer.sender;
});
services.pgadmin.settings =
{
DEFAULT_SERVER_PORT = cfg.port;
PASSWORD_LENGTH_MIN = cfg.minimumPasswordLength;
SERVER_MODE = true;
UPGRADE_CHECK_ENABLED = false;
}
// (lib.optionalAttrs cfg.openFirewall {
DEFAULT_SERVER = lib.mkDefault "::";
})
// (lib.optionalAttrs cfg.emailServer.enable {
MAIL_SERVER = cfg.emailServer.address;
MAIL_PORT = cfg.emailServer.port;
MAIL_USE_SSL = cfg.emailServer.useSSL;
MAIL_USE_TLS = cfg.emailServer.useTLS;
MAIL_USERNAME = cfg.emailServer.username;
SECURITY_EMAIL_SENDER = cfg.emailServer.sender;
});
systemd.services.pgadmin = {
wantedBy = [ "multi-user.target" ];
@ -142,7 +184,11 @@ in
# in case postgres doesn't start, pgadmin will just start normally
wants = [ "postgresql.service" ];
path = [ config.services.postgresql.package pkgs.coreutils pkgs.bash ];
path = [
config.services.postgresql.package
pkgs.coreutils
pkgs.bash
];
preStart = ''
# NOTE: this is idempotent (aka running it twice has no effect)
@ -179,8 +225,9 @@ in
LogsDirectory = "pgadmin";
StateDirectory = "pgadmin";
ExecStart = "${cfg.package}/bin/pgadmin4";
LoadCredential = [ "initial_password:${cfg.initialPasswordFile}" ]
++ lib.optional cfg.emailServer.enable "email_password:${cfg.emailServer.passwordFile}";
LoadCredential = [
"initial_password:${cfg.initialPasswordFile}"
] ++ lib.optional cfg.emailServer.enable "email_password:${cfg.emailServer.passwordFile}";
};
};
@ -192,12 +239,14 @@ in
users.groups.pgadmin = { };
environment.etc."pgadmin/config_system.py" = {
text = lib.optionalString cfg.emailServer.enable ''
import os
with open(os.path.join(os.environ['CREDENTIALS_DIRECTORY'], 'email_password')) as f:
pw = f.read()
MAIL_PASSWORD = pw
'' + formatPy cfg.settings;
text =
lib.optionalString cfg.emailServer.enable ''
import os
with open(os.path.join(os.environ['CREDENTIALS_DIRECTORY'], 'email_password')) as f:
pw = f.read()
MAIL_PASSWORD = pw
''
+ formatPy cfg.settings;
mode = "0600";
user = "pgadmin";
group = "pgadmin";