forked from mirrors/nixpkgs
2e751c0772
the conversion procedure is simple: - find all things that look like options, ie calls to either `mkOption` or `lib.mkOption` that take an attrset. remember the attrset as the option - for all options, find a `description` attribute who's value is not a call to `mdDoc` or `lib.mdDoc` - textually convert the entire value of the attribute to MD with a few simple regexes (the set from mdize-module.sh) - if the change produced a change in the manual output, discard - if the change kept the manual unchanged, add some text to the description to make sure we've actually found an option. if the manual changes this time, keep the converted description this procedure converts 80% of nixos options to markdown. around 2000 options remain to be inspected, but most of those fail the "does not change the manual output check": currently the MD conversion process does not faithfully convert docbook tags like <code> and <package>, so any option using such tags will not be converted at all.
112 lines
3 KiB
Nix
112 lines
3 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
cfg = config.services.restic.server;
|
|
in
|
|
{
|
|
meta.maintainers = [ maintainers.bachp ];
|
|
|
|
options.services.restic.server = {
|
|
enable = mkEnableOption "Restic REST Server";
|
|
|
|
listenAddress = mkOption {
|
|
default = ":8000";
|
|
example = "127.0.0.1:8080";
|
|
type = types.str;
|
|
description = lib.mdDoc "Listen on a specific IP address and port.";
|
|
};
|
|
|
|
dataDir = mkOption {
|
|
default = "/var/lib/restic";
|
|
type = types.path;
|
|
description = lib.mdDoc "The directory for storing the restic repository.";
|
|
};
|
|
|
|
appendOnly = mkOption {
|
|
default = false;
|
|
type = types.bool;
|
|
description = lib.mdDoc ''
|
|
Enable append only mode.
|
|
This mode allows creation of new backups but prevents deletion and modification of existing backups.
|
|
This can be useful when backing up systems that have a potential of being hacked.
|
|
'';
|
|
};
|
|
|
|
privateRepos = mkOption {
|
|
default = false;
|
|
type = types.bool;
|
|
description = lib.mdDoc ''
|
|
Enable private repos.
|
|
Grants access only when a subdirectory with the same name as the user is specified in the repository URL.
|
|
'';
|
|
};
|
|
|
|
prometheus = mkOption {
|
|
default = false;
|
|
type = types.bool;
|
|
description = lib.mdDoc "Enable Prometheus metrics at /metrics.";
|
|
};
|
|
|
|
extraFlags = mkOption {
|
|
type = types.listOf types.str;
|
|
default = [];
|
|
description = lib.mdDoc ''
|
|
Extra commandline options to pass to Restic REST server.
|
|
'';
|
|
};
|
|
|
|
package = mkOption {
|
|
default = pkgs.restic-rest-server;
|
|
defaultText = literalExpression "pkgs.restic-rest-server";
|
|
type = types.package;
|
|
description = lib.mdDoc "Restic REST server package to use.";
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
systemd.services.restic-rest-server = {
|
|
description = "Restic REST Server";
|
|
after = [ "network.target" ];
|
|
wantedBy = [ "multi-user.target" ];
|
|
serviceConfig = {
|
|
ExecStart = ''
|
|
${cfg.package}/bin/rest-server \
|
|
--listen ${cfg.listenAddress} \
|
|
--path ${cfg.dataDir} \
|
|
${optionalString cfg.appendOnly "--append-only"} \
|
|
${optionalString cfg.privateRepos "--private-repos"} \
|
|
${optionalString cfg.prometheus "--prometheus"} \
|
|
${escapeShellArgs cfg.extraFlags} \
|
|
'';
|
|
Type = "simple";
|
|
User = "restic";
|
|
Group = "restic";
|
|
|
|
# Security hardening
|
|
ReadWritePaths = [ cfg.dataDir ];
|
|
PrivateTmp = true;
|
|
ProtectSystem = "strict";
|
|
ProtectKernelTunables = true;
|
|
ProtectKernelModules = true;
|
|
ProtectControlGroups = true;
|
|
PrivateDevices = true;
|
|
};
|
|
};
|
|
|
|
systemd.tmpfiles.rules = mkIf cfg.privateRepos [
|
|
"f ${cfg.dataDir}/.htpasswd 0700 restic restic -"
|
|
];
|
|
|
|
users.users.restic = {
|
|
group = "restic";
|
|
home = cfg.dataDir;
|
|
createHome = true;
|
|
uid = config.ids.uids.restic;
|
|
};
|
|
|
|
users.groups.restic.gid = config.ids.uids.restic;
|
|
};
|
|
}
|