mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-10 03:23:29 +03:00

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-builda08b3a4d19
.tar.gz \ --argstr baseRevb32a094368
result/bin/apply-formatting $NIXPKGS_PATH
113 lines
3.5 KiB
Nix
113 lines
3.5 KiB
Nix
{
|
|
lib,
|
|
pkgs,
|
|
config,
|
|
...
|
|
}:
|
|
let
|
|
settingsFormat = pkgs.formats.yaml { };
|
|
|
|
# gemstash uses a yaml config where the keys are ruby symbols,
|
|
# which means they start with ':'. This would be annoying to use
|
|
# on the nix side, so we rewrite plain names instead.
|
|
prefixColon =
|
|
s:
|
|
lib.listToAttrs (
|
|
map (attrName: {
|
|
name = ":${attrName}";
|
|
value = if lib.isAttrs s.${attrName} then prefixColon s."${attrName}" else s."${attrName}";
|
|
}) (lib.attrNames s)
|
|
);
|
|
|
|
# parse the port number out of the tcp://ip:port bind setting string
|
|
parseBindPort = bind: lib.strings.toInt (lib.last (lib.strings.splitString ":" bind));
|
|
|
|
cfg = config.services.gemstash;
|
|
in
|
|
{
|
|
options.services.gemstash = {
|
|
enable = lib.mkEnableOption "gemstash, a cache for rubygems.org and a private gem server";
|
|
|
|
openFirewall = lib.mkOption {
|
|
type = lib.types.bool;
|
|
default = false;
|
|
description = ''
|
|
Whether to open the firewall for the port in {option}`services.gemstash.bind`.
|
|
'';
|
|
};
|
|
|
|
settings = lib.mkOption {
|
|
default = { };
|
|
description = ''
|
|
Configuration for Gemstash. The details can be found at in
|
|
[gemstash documentation](https://github.com/rubygems/gemstash/blob/master/man/gemstash-configuration.5.md).
|
|
Each key set here is automatically prefixed with ":" to match the gemstash expectations.
|
|
'';
|
|
type = lib.types.submodule {
|
|
freeformType = settingsFormat.type;
|
|
options = {
|
|
base_path = lib.mkOption {
|
|
type = lib.types.path;
|
|
default = "/var/lib/gemstash";
|
|
description = "Path to store the gem files and the sqlite database. If left unchanged, the directory will be created.";
|
|
};
|
|
bind = lib.mkOption {
|
|
type = lib.types.str;
|
|
default = "tcp://0.0.0.0:9292";
|
|
description = "Host and port combination for the server to listen on.";
|
|
};
|
|
db_adapter = lib.mkOption {
|
|
type = lib.types.nullOr (
|
|
lib.types.enum [
|
|
"sqlite3"
|
|
"postgres"
|
|
"mysql"
|
|
"mysql2"
|
|
]
|
|
);
|
|
default = null;
|
|
description = "Which database type to use. For choices other than sqlite3, the dbUrl has to be specified as well.";
|
|
};
|
|
db_url = lib.mkOption {
|
|
type = lib.types.nullOr lib.types.str;
|
|
default = null;
|
|
description = "The database to connect to when using postgres, mysql, or mysql2.";
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
users = {
|
|
users.gemstash = {
|
|
group = "gemstash";
|
|
isSystemUser = true;
|
|
};
|
|
groups.gemstash = { };
|
|
};
|
|
|
|
networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [
|
|
(parseBindPort cfg.settings.bind)
|
|
];
|
|
|
|
systemd.services.gemstash = {
|
|
wantedBy = [ "multi-user.target" ];
|
|
after = [ "network.target" ];
|
|
serviceConfig = lib.mkMerge [
|
|
{
|
|
ExecStart = "${pkgs.gemstash}/bin/gemstash start --no-daemonize --config-file ${settingsFormat.generate "gemstash.yaml" (prefixColon cfg.settings)}";
|
|
NoNewPrivileges = true;
|
|
User = "gemstash";
|
|
Group = "gemstash";
|
|
PrivateTmp = true;
|
|
RestrictSUIDSGID = true;
|
|
LockPersonality = true;
|
|
}
|
|
(lib.mkIf (cfg.settings.base_path == "/var/lib/gemstash") {
|
|
StateDirectory = "gemstash";
|
|
})
|
|
];
|
|
};
|
|
};
|
|
}
|