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