{nixos,nixosTests}/redlib: format with nixfmt
This commit is contained in:
parent
d78d09350a
commit
e286b91ebc
@ -1,8 +1,21 @@
|
|||||||
{ config, lib, pkgs, ... }:
|
{
|
||||||
|
config,
|
||||||
with lib;
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
|
inherit (lib)
|
||||||
|
concatStringsSep
|
||||||
|
mkEnableOption
|
||||||
|
mkIf
|
||||||
|
mkOption
|
||||||
|
mkPackageOption
|
||||||
|
mkRenamedOptionModule
|
||||||
|
types
|
||||||
|
;
|
||||||
|
|
||||||
cfg = config.services.redlib;
|
cfg = config.services.redlib;
|
||||||
|
|
||||||
args = concatStringsSep " " ([
|
args = concatStringsSep " " ([
|
||||||
@ -12,7 +25,16 @@ let
|
|||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
(mkRenamedOptionModule [ "services" "libreddit" ] [ "services" "redlib" ])
|
(mkRenamedOptionModule
|
||||||
|
[
|
||||||
|
"services"
|
||||||
|
"libreddit"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"services"
|
||||||
|
"redlib"
|
||||||
|
]
|
||||||
|
)
|
||||||
];
|
];
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
@ -24,7 +46,7 @@ in
|
|||||||
address = mkOption {
|
address = mkOption {
|
||||||
default = "0.0.0.0";
|
default = "0.0.0.0";
|
||||||
example = "127.0.0.1";
|
example = "127.0.0.1";
|
||||||
type = types.str;
|
type = types.str;
|
||||||
description = "The address to listen on";
|
description = "The address to listen on";
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -46,41 +68,49 @@ in
|
|||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
systemd.services.redlib = {
|
systemd.services.redlib = {
|
||||||
description = "Private front-end for Reddit";
|
description = "Private front-end for Reddit";
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = [ "network.target" ];
|
after = [ "network.target" ];
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
DynamicUser = true;
|
DynamicUser = true;
|
||||||
ExecStart = "${lib.getExe cfg.package} ${args}";
|
ExecStart = "${lib.getExe cfg.package} ${args}";
|
||||||
AmbientCapabilities = lib.mkIf (cfg.port < 1024) [ "CAP_NET_BIND_SERVICE" ];
|
AmbientCapabilities = lib.mkIf (cfg.port < 1024) [ "CAP_NET_BIND_SERVICE" ];
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
RestartSec = "2s";
|
RestartSec = "2s";
|
||||||
# Hardening
|
|
||||||
CapabilityBoundingSet = if (cfg.port < 1024) then [ "CAP_NET_BIND_SERVICE" ] else [ "" ];
|
# Hardening
|
||||||
DeviceAllow = [ "" ];
|
CapabilityBoundingSet = if (cfg.port < 1024) then [ "CAP_NET_BIND_SERVICE" ] else [ "" ];
|
||||||
LockPersonality = true;
|
DeviceAllow = [ "" ];
|
||||||
MemoryDenyWriteExecute = true;
|
LockPersonality = true;
|
||||||
PrivateDevices = true;
|
MemoryDenyWriteExecute = true;
|
||||||
# A private user cannot have process capabilities on the host's user
|
PrivateDevices = true;
|
||||||
# namespace and thus CAP_NET_BIND_SERVICE has no effect.
|
# A private user cannot have process capabilities on the host's user
|
||||||
PrivateUsers = (cfg.port >= 1024);
|
# namespace and thus CAP_NET_BIND_SERVICE has no effect.
|
||||||
ProcSubset = "pid";
|
PrivateUsers = (cfg.port >= 1024);
|
||||||
ProtectClock = true;
|
ProcSubset = "pid";
|
||||||
ProtectControlGroups = true;
|
ProtectClock = true;
|
||||||
ProtectHome = true;
|
ProtectControlGroups = true;
|
||||||
ProtectHostname = true;
|
ProtectHome = true;
|
||||||
ProtectKernelLogs = true;
|
ProtectHostname = true;
|
||||||
ProtectKernelModules = true;
|
ProtectKernelLogs = true;
|
||||||
ProtectKernelTunables = true;
|
ProtectKernelModules = true;
|
||||||
ProtectProc = "invisible";
|
ProtectKernelTunables = true;
|
||||||
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
|
ProtectProc = "invisible";
|
||||||
RestrictNamespaces = true;
|
RestrictAddressFamilies = [
|
||||||
RestrictRealtime = true;
|
"AF_INET"
|
||||||
RestrictSUIDSGID = true;
|
"AF_INET6"
|
||||||
SystemCallArchitectures = "native";
|
];
|
||||||
SystemCallFilter = [ "@system-service" "~@privileged" "~@resources" ];
|
RestrictNamespaces = true;
|
||||||
UMask = "0077";
|
RestrictRealtime = true;
|
||||||
};
|
RestrictSUIDSGID = true;
|
||||||
|
SystemCallArchitectures = "native";
|
||||||
|
SystemCallFilter = [
|
||||||
|
"@system-service"
|
||||||
|
"~@privileged"
|
||||||
|
"~@resources"
|
||||||
|
];
|
||||||
|
UMask = "0077";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
networking.firewall = mkIf cfg.openFirewall {
|
networking.firewall = mkIf cfg.openFirewall {
|
||||||
|
@ -1,20 +1,23 @@
|
|||||||
import ./make-test-python.nix ({ lib, pkgs, ... }: {
|
import ./make-test-python.nix (
|
||||||
name = "redlib";
|
{ lib, pkgs, ... }:
|
||||||
meta.maintainers = with lib.maintainers; [ soispha ];
|
{
|
||||||
|
name = "redlib";
|
||||||
|
meta.maintainers = with lib.maintainers; [ soispha ];
|
||||||
|
|
||||||
nodes.machine = {
|
nodes.machine = {
|
||||||
services.redlib = {
|
services.redlib = {
|
||||||
package = pkgs.redlib;
|
package = pkgs.redlib;
|
||||||
enable = true;
|
enable = true;
|
||||||
# Test CAP_NET_BIND_SERVICE
|
# Test CAP_NET_BIND_SERVICE
|
||||||
port = 80;
|
port = 80;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
testScript = ''
|
testScript = ''
|
||||||
machine.wait_for_unit("redlib.service")
|
machine.wait_for_unit("redlib.service")
|
||||||
machine.wait_for_open_port(80)
|
machine.wait_for_open_port(80)
|
||||||
# Query a page that does not require Internet access
|
# Query a page that does not require Internet access
|
||||||
machine.succeed("curl --fail http://localhost:80/settings")
|
machine.succeed("curl --fail http://localhost:80/settings")
|
||||||
'';
|
'';
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user