mirror of
https://git.pvv.ntnu.no/Drift/pvv-nixos-config.git
synced 2026-02-04 09:10:01 +01:00
modules/rsync-pull-targets: init, migrate bekkalokk/website/fetch-gallery
This commit is contained in:
@@ -129,6 +129,7 @@
|
|||||||
] ++ (lib.optionals enableDefaults [
|
] ++ (lib.optionals enableDefaults [
|
||||||
sops-nix.nixosModules.sops
|
sops-nix.nixosModules.sops
|
||||||
inputs.roowho2.nixosModules.default
|
inputs.roowho2.nixosModules.default
|
||||||
|
self.nixosModules.rsync-pull-targets
|
||||||
]) ++ modules;
|
]) ++ modules;
|
||||||
}
|
}
|
||||||
(builtins.removeAttrs extraArgs [
|
(builtins.removeAttrs extraArgs [
|
||||||
@@ -270,11 +271,12 @@
|
|||||||
|
|
||||||
nixosModules = {
|
nixosModules = {
|
||||||
bluemap = ./modules/bluemap.nix;
|
bluemap = ./modules/bluemap.nix;
|
||||||
snakeoil-certs = ./modules/snakeoil-certs.nix;
|
|
||||||
snappymail = ./modules/snappymail.nix;
|
|
||||||
robots-txt = ./modules/robots-txt.nix;
|
|
||||||
gickup = ./modules/gickup;
|
gickup = ./modules/gickup;
|
||||||
matrix-ooye = ./modules/matrix-ooye.nix;
|
matrix-ooye = ./modules/matrix-ooye.nix;
|
||||||
|
robots-txt = ./modules/robots-txt.nix;
|
||||||
|
rsync-pull-targets = ./modules/rsync-pull-targets.nix;
|
||||||
|
snakeoil-certs = ./modules/snakeoil-certs.nix;
|
||||||
|
snappymail = ./modules/snappymail.nix;
|
||||||
};
|
};
|
||||||
|
|
||||||
devShells = forAllSystems (system: {
|
devShells = forAllSystems (system: {
|
||||||
|
|||||||
@@ -3,13 +3,21 @@ let
|
|||||||
galleryDir = config.services.pvv-nettsiden.settings.GALLERY.DIR;
|
galleryDir = config.services.pvv-nettsiden.settings.GALLERY.DIR;
|
||||||
transferDir = "${config.services.pvv-nettsiden.settings.GALLERY.DIR}-transfer";
|
transferDir = "${config.services.pvv-nettsiden.settings.GALLERY.DIR}-transfer";
|
||||||
in {
|
in {
|
||||||
users.users.${config.services.pvv-nettsiden.user} = {
|
|
||||||
useDefaultShell = true;
|
|
||||||
|
|
||||||
# This is pushed from microbel:/var/www/www-gallery/build-gallery.sh
|
# This is pushed from microbel:/var/www/www-gallery/build-gallery.sh
|
||||||
openssh.authorizedKeys.keys = [
|
services.rsync-pull-targets = {
|
||||||
''command="${pkgs.rrsync}/bin/rrsync -wo ${transferDir}",restrict,no-agent-forwarding,no-port-forwarding,no-pty,no-X11-forwarding ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIjHhC2dikhWs/gG+m7qP1eSohWzTehn4ToNzDSOImyR gallery-publish''
|
enable = true;
|
||||||
|
locations.${transferDir} = {
|
||||||
|
user = config.services.pvv-nettsiden.user;
|
||||||
|
rrsyncArgs.wo = true;
|
||||||
|
authorizedKeysAttrs = [
|
||||||
|
"restrict"
|
||||||
|
"no-agent-forwarding"
|
||||||
|
"no-port-forwarding"
|
||||||
|
"no-pty"
|
||||||
|
"no-X11-forwarding"
|
||||||
];
|
];
|
||||||
|
publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIjHhC2dikhWs/gG+m7qP1eSohWzTehn4ToNzDSOImyR gallery-publish";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.paths.pvv-nettsiden-gallery-update = {
|
systemd.paths.pvv-nettsiden-gallery-update = {
|
||||||
|
|||||||
130
modules/rsync-pull-targets.nix
Normal file
130
modules/rsync-pull-targets.nix
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
let
|
||||||
|
cfg = config.services.rsync-pull-targets;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.services.rsync-pull-targets = {
|
||||||
|
enable = lib.mkEnableOption "";
|
||||||
|
|
||||||
|
rrsyncPackage = lib.mkPackageOption pkgs "rrsync" { };
|
||||||
|
|
||||||
|
locations = lib.mkOption {
|
||||||
|
type = lib.types.attrsOf (lib.types.submodule ({ name, ... }@submoduleArgs: {
|
||||||
|
options = {
|
||||||
|
enable = lib.mkEnableOption "" // {
|
||||||
|
default = true;
|
||||||
|
example = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
user = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
description = "Which user to use as SSH login";
|
||||||
|
example = "root";
|
||||||
|
};
|
||||||
|
|
||||||
|
location = lib.mkOption {
|
||||||
|
type = lib.types.path;
|
||||||
|
default = name;
|
||||||
|
defaultText = lib.literalExpression "<name>";
|
||||||
|
example = "/path/to/rsyncable/item";
|
||||||
|
};
|
||||||
|
|
||||||
|
# TODO: handle autogeneration of keys
|
||||||
|
# autoGenerateSSHKeypair = lib.mkOption {
|
||||||
|
# type = lib.types.bool;
|
||||||
|
# default = config.publicKey == null;
|
||||||
|
# defaultText = lib.literalExpression "config.services.rsync-pull-targets.<name>.publicKey != null";
|
||||||
|
# example = true;
|
||||||
|
# };
|
||||||
|
|
||||||
|
publicKey = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
# type = lib.types.nullOr lib.types.str;
|
||||||
|
# default = null;
|
||||||
|
example = "ssh-ed25519 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA comment";
|
||||||
|
};
|
||||||
|
|
||||||
|
rrsyncPackage = lib.mkPackageOption pkgs "rrsync" { } // {
|
||||||
|
default = cfg.rrsyncPackage;
|
||||||
|
defaultText = lib.literalExpression "config.services.rsync-pull-targets.rrsyncPackage";
|
||||||
|
};
|
||||||
|
|
||||||
|
enableRecommendedHardening = lib.mkEnableOption "a commonly used security profile for authorizedKeys attributes and rrsync args";
|
||||||
|
|
||||||
|
rrsyncArgs = {
|
||||||
|
ro = lib.mkEnableOption "" // {
|
||||||
|
description = "Allow only reading from the DIR. Implies -no-del and -no-lock.";
|
||||||
|
};
|
||||||
|
wo = lib.mkEnableOption "" // {
|
||||||
|
description = "Allow only writing to the DIR.";
|
||||||
|
};
|
||||||
|
munge = lib.mkEnableOption "" // {
|
||||||
|
description = "Enable rsync's --munge-links on the server side.";
|
||||||
|
# TODO: set a default?
|
||||||
|
};
|
||||||
|
no-del = lib.mkEnableOption "" // {
|
||||||
|
description = "Disable rsync's --delete* and --remove* options.";
|
||||||
|
default = submoduleArgs.config.enableRecommendedHardening;
|
||||||
|
defaultText = lib.literalExpression "config.services.rsync-pull-targets.<name>.enableRecommendedHardening";
|
||||||
|
};
|
||||||
|
no-lock = lib.mkEnableOption "" // {
|
||||||
|
description = "Avoid the single-run (per-user) lock check.";
|
||||||
|
default = submoduleArgs.config.enableRecommendedHardening;
|
||||||
|
defaultText = lib.literalExpression "config.services.rsync-pull-targets.<name>.enableRecommendedHardening";
|
||||||
|
};
|
||||||
|
no-overwrite = lib.mkEnableOption "" // {
|
||||||
|
description = "Prevent overwriting existing files by enforcing --ignore-existing";
|
||||||
|
default = submoduleArgs.config.enableRecommendedHardening;
|
||||||
|
defaultText = lib.literalExpression "config.services.rsync-pull-targets.<name>.enableRecommendedHardening";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
authorizedKeysAttrs = lib.mkOption {
|
||||||
|
type = lib.types.listOf lib.types.str;
|
||||||
|
default = lib.optionals submoduleArgs.config.enableRecommendedHardening [
|
||||||
|
"restrict"
|
||||||
|
"no-agent-forwarding"
|
||||||
|
"no-port-forwarding"
|
||||||
|
"no-pty"
|
||||||
|
"no-X11-forwarding"
|
||||||
|
];
|
||||||
|
defaultText = lib.literalExpression ''
|
||||||
|
lib.optionals config.services.rsync-pull-targets.<name>.enableRecommendedHardening [
|
||||||
|
"restrict"
|
||||||
|
"no-agent-forwarding"
|
||||||
|
"no-port-forwarding"
|
||||||
|
"no-pty"
|
||||||
|
"no-X11-forwarding"
|
||||||
|
]
|
||||||
|
'';
|
||||||
|
example = [
|
||||||
|
"restrict"
|
||||||
|
"no-agent-forwarding"
|
||||||
|
"no-port-forwarding"
|
||||||
|
"no-pty"
|
||||||
|
"no-X11-forwarding"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
services.openssh.enable = true;
|
||||||
|
users.users = lib.pipe cfg.locations [
|
||||||
|
(lib.filterAttrs (_: value: value.enable))
|
||||||
|
(lib.mapAttrs' (_: { user, location, rrsyncPackage, rrsyncArgs, authorizedKeysAttrs, publicKey, ... }: let
|
||||||
|
rrsyncArgString = lib.cli.toCommandLineShellGNU {
|
||||||
|
isLong = _: false;
|
||||||
|
} rrsyncArgs;
|
||||||
|
# TODO: handle " in location
|
||||||
|
in {
|
||||||
|
name = user;
|
||||||
|
value.openssh.authorizedKeys.keys = [
|
||||||
|
"command=\"${lib.getExe rrsyncPackage} ${rrsyncArgString} ${location}\",${lib.concatStringsSep "," authorizedKeysAttrs} ${publicKey}"
|
||||||
|
];
|
||||||
|
}))
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user