Disable various services when running inside a container
This commit is contained in:
parent
da093461a2
commit
2b1f212494
@ -46,7 +46,10 @@ in
|
|||||||
before = [ "sysinit.target" "shutdown.target" ];
|
before = [ "sysinit.target" "shutdown.target" ];
|
||||||
wantedBy = [ "sysinit.target" "multi-user.target" ];
|
wantedBy = [ "sysinit.target" "multi-user.target" ];
|
||||||
restartTriggers = [ config.environment.etc."sysctl.d/nixos.conf".source ];
|
restartTriggers = [ config.environment.etc."sysctl.d/nixos.conf".source ];
|
||||||
unitConfig.DefaultDependencies = false; # needed to prevent a cycle
|
unitConfig = {
|
||||||
|
DefaultDependencies = false; # needed to prevent a cycle
|
||||||
|
ConditionPathIsReadWrite = "/proc/sys/"; # prevent systemd-sysctl in containers
|
||||||
|
};
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
RemainAfterExit = true;
|
RemainAfterExit = true;
|
||||||
|
@ -55,6 +55,7 @@ in
|
|||||||
{ description = "Store Sound Card State";
|
{ description = "Store Sound Card State";
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
unitConfig.RequiresMountsFor = "/var/lib/alsa";
|
unitConfig.RequiresMountsFor = "/var/lib/alsa";
|
||||||
|
unitConfig.ConditionVirtualization = "!systemd-nspawn";
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
RemainAfterExit = true;
|
RemainAfterExit = true;
|
||||||
|
@ -110,6 +110,7 @@ in
|
|||||||
|
|
||||||
exec = "acpid --confdir ${acpiConfDir}";
|
exec = "acpid --confdir ${acpiConfDir}";
|
||||||
|
|
||||||
|
unitConfig.ConditionVirtualization = "!systemd-nspawn";
|
||||||
unitConfig.ConditionPathExists = [ "/proc/acpi" ];
|
unitConfig.ConditionPathExists = [ "/proc/acpi" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -32,6 +32,8 @@ with pkgs.lib;
|
|||||||
|
|
||||||
path = [ pkgs.sysklogd ];
|
path = [ pkgs.sysklogd ];
|
||||||
|
|
||||||
|
unitConfig.ConditionVirtualization = "!systemd-nspawn";
|
||||||
|
|
||||||
exec =
|
exec =
|
||||||
"klogd -c 1 -2 -n " +
|
"klogd -c 1 -2 -n " +
|
||||||
"-k $(dirname $(readlink -f /run/booted-system/kernel))/System.map";
|
"-k $(dirname $(readlink -f /run/booted-system/kernel))/System.map";
|
||||||
|
@ -279,6 +279,7 @@ in
|
|||||||
{ description = "Nix Daemon Socket";
|
{ description = "Nix Daemon Socket";
|
||||||
wantedBy = [ "sockets.target" ];
|
wantedBy = [ "sockets.target" ];
|
||||||
before = [ "multi-user.target" ];
|
before = [ "multi-user.target" ];
|
||||||
|
unitConfig.ConditionPathIsReadWrite = "/nix/var/nix/daemon-socket/";
|
||||||
socketConfig.ListenStream = "/nix/var/nix/daemon-socket/socket";
|
socketConfig.ListenStream = "/nix/var/nix/daemon-socket/socket";
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -290,6 +291,8 @@ in
|
|||||||
|
|
||||||
environment = cfg.envVars // { CURL_CA_BUNDLE = "/etc/ssl/certs/ca-bundle.crt"; };
|
environment = cfg.envVars // { CURL_CA_BUNDLE = "/etc/ssl/certs/ca-bundle.crt"; };
|
||||||
|
|
||||||
|
unitConfig.ConditionPathIsReadWrite = "/nix/var/nix/daemon-socket/";
|
||||||
|
|
||||||
serviceConfig =
|
serviceConfig =
|
||||||
{ ExecStart = "@${nix}/bin/nix-daemon nix-daemon --daemon";
|
{ ExecStart = "@${nix}/bin/nix-daemon nix-daemon --daemon";
|
||||||
KillMode = "process";
|
KillMode = "process";
|
||||||
|
@ -114,6 +114,8 @@ in
|
|||||||
|
|
||||||
path = [ dhcpcd pkgs.nettools pkgs.openresolv ];
|
path = [ dhcpcd pkgs.nettools pkgs.openresolv ];
|
||||||
|
|
||||||
|
unitConfig.ConditionCapability = "CAP_NET_ADMIN";
|
||||||
|
|
||||||
serviceConfig =
|
serviceConfig =
|
||||||
{ Type = "forking";
|
{ Type = "forking";
|
||||||
PIDFile = "/run/dhcpcd.pid";
|
PIDFile = "/run/dhcpcd.pid";
|
||||||
|
@ -231,7 +231,10 @@ in
|
|||||||
wantedBy = [ "sysinit.target" "multi-user.target" ];
|
wantedBy = [ "sysinit.target" "multi-user.target" ];
|
||||||
before = [ "sysinit.target" "shutdown.target" ];
|
before = [ "sysinit.target" "shutdown.target" ];
|
||||||
conflicts = [ "shutdown.target" ];
|
conflicts = [ "shutdown.target" ];
|
||||||
unitConfig.DefaultDependencies = "no";
|
unitConfig =
|
||||||
|
{ DefaultDependencies = false;
|
||||||
|
ConditionCapability = "CAP_SYS_MODULE";
|
||||||
|
};
|
||||||
serviceConfig =
|
serviceConfig =
|
||||||
{ Type = "oneshot";
|
{ Type = "oneshot";
|
||||||
RemainAfterExit = true;
|
RemainAfterExit = true;
|
||||||
|
@ -6,20 +6,20 @@ with pkgs.lib;
|
|||||||
|
|
||||||
# This unit saves the value of the system clock to the hardware
|
# This unit saves the value of the system clock to the hardware
|
||||||
# clock on shutdown.
|
# clock on shutdown.
|
||||||
systemd.units."save-hwclock.service" =
|
systemd.services.save-hwclock =
|
||||||
{ wantedBy = [ "shutdown.target" ];
|
{ description = "Save Hardware Clock";
|
||||||
|
|
||||||
text =
|
wantedBy = [ "shutdown.target" ];
|
||||||
''
|
|
||||||
[Unit]
|
|
||||||
Description=Save Hardware Clock
|
|
||||||
DefaultDependencies=no
|
|
||||||
Before=shutdown.target
|
|
||||||
|
|
||||||
[Service]
|
unitConfig = {
|
||||||
Type=oneshot
|
DefaultDependencies = false;
|
||||||
ExecStart=${pkgs.utillinux}/sbin/hwclock --systohc ${if config.time.hardwareClockInLocalTime then "--localtime" else "--utc"}
|
ConditionVirtualization = "!systemd-nspawn";
|
||||||
'';
|
};
|
||||||
|
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
ExecStart = "${pkgs.utillinux}/sbin/hwclock --systohc ${if config.time.hardwareClockInLocalTime then "--localtime" else "--utc"}";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
boot.kernel.sysctl."kernel.poweroff_cmd" = "${config.systemd.package}/sbin/poweroff";
|
boot.kernel.sysctl."kernel.poweroff_cmd" = "${config.systemd.package}/sbin/poweroff";
|
||||||
|
@ -33,6 +33,8 @@ with pkgs.lib;
|
|||||||
after = [ "systemd-modules-load.service" ];
|
after = [ "systemd-modules-load.service" ];
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
|
||||||
|
unitConfig.ConditionPathIsReadWrite = "/sys/devices/";
|
||||||
|
|
||||||
path = [ pkgs.cpufrequtils ];
|
path = [ pkgs.cpufrequtils ];
|
||||||
|
|
||||||
preStart = ''
|
preStart = ''
|
||||||
|
@ -270,6 +270,8 @@ in
|
|||||||
before = [ "network.target" ];
|
before = [ "network.target" ];
|
||||||
wantedBy = [ "network.target" ];
|
wantedBy = [ "network.target" ];
|
||||||
|
|
||||||
|
unitConfig.ConditionCapability = "CAP_NET_ADMIN";
|
||||||
|
|
||||||
path = [ pkgs.iproute ];
|
path = [ pkgs.iproute ];
|
||||||
|
|
||||||
serviceConfig.Type = "oneshot";
|
serviceConfig.Type = "oneshot";
|
||||||
|
@ -31,6 +31,8 @@ with pkgs.lib;
|
|||||||
|
|
||||||
task = true;
|
task = true;
|
||||||
|
|
||||||
|
unitConfig.ConditionPathIsReadWrite = "/sys/class/scsi_host";
|
||||||
|
|
||||||
script = ''
|
script = ''
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
for x in /sys/class/scsi_host/host*/link_power_management_policy; do
|
for x in /sys/class/scsi_host/host*/link_power_management_policy; do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user