2014-04-01 15:42:18 +02:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
2014-03-17 14:04:39 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
|
2014-04-01 15:42:18 +02:00
|
|
|
config = mkIf config.boot.isContainer {
|
2014-03-17 14:04:39 +01:00
|
|
|
|
2014-04-19 14:41:21 +02:00
|
|
|
# Disable some features that are not useful in a container.
|
2014-04-16 01:44:43 +02:00
|
|
|
sound.enable = mkDefault false;
|
2014-04-19 14:41:21 +02:00
|
|
|
services.udisks2.enable = mkDefault false;
|
2014-04-16 01:44:43 +02:00
|
|
|
|
2014-04-18 16:40:27 +02:00
|
|
|
networking.useHostResolvConf = true;
|
|
|
|
|
2014-04-22 16:07:53 +02:00
|
|
|
# Containers should be light-weight, so start sshd on demand.
|
|
|
|
services.openssh.startWhenNeeded = mkDefault true;
|
|
|
|
|
2014-04-18 17:00:11 +02:00
|
|
|
# Shut up warnings about not having a boot loader.
|
|
|
|
system.build.installBootLoader = "${pkgs.coreutils}/bin/true";
|
|
|
|
|
2014-04-18 20:47:31 +02:00
|
|
|
# Provide a root login prompt on /var/lib/root-login.socket that
|
|
|
|
# doesn't ask for a password. This socket can only be used by root
|
|
|
|
# on the host.
|
2014-04-10 13:12:34 +02:00
|
|
|
systemd.sockets.root-login =
|
|
|
|
{ description = "Root Login Socket";
|
2014-03-17 14:04:39 +01:00
|
|
|
wantedBy = [ "sockets.target" ];
|
|
|
|
socketConfig =
|
2014-04-10 13:12:34 +02:00
|
|
|
{ ListenStream = "/var/lib/root-login.socket";
|
|
|
|
SocketMode = "0600";
|
2014-03-17 14:04:39 +01:00
|
|
|
Accept = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2014-04-10 13:12:34 +02:00
|
|
|
systemd.services."root-login@" =
|
|
|
|
{ description = "Root Login %i";
|
|
|
|
environment.TERM = "linux";
|
|
|
|
serviceConfig =
|
|
|
|
{ Type = "simple";
|
|
|
|
StandardInput = "socket";
|
|
|
|
ExecStart = "${pkgs.socat}/bin/socat -t0 - \"exec:${pkgs.shadow}/bin/login -f root,pty,setsid,setpgid,stderr,ctty\"";
|
|
|
|
TimeoutStopSec = 1; # FIXME
|
|
|
|
};
|
2014-04-15 11:22:31 +02:00
|
|
|
restartIfChanged = false;
|
2014-04-10 13:12:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
# Provide a daemon on /var/lib/run-command.socket that reads a
|
|
|
|
# command from stdin and executes it.
|
|
|
|
systemd.sockets.run-command =
|
|
|
|
{ description = "Run Command Socket";
|
|
|
|
wantedBy = [ "sockets.target" ];
|
|
|
|
socketConfig =
|
|
|
|
{ ListenStream = "/var/lib/run-command.socket";
|
|
|
|
SocketMode = "0600"; # only root can connect
|
|
|
|
Accept = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services."run-command@" =
|
|
|
|
{ description = "Run Command %i";
|
|
|
|
environment.TERM = "linux";
|
2014-03-17 14:04:39 +01:00
|
|
|
serviceConfig =
|
|
|
|
{ Type = "simple";
|
|
|
|
StandardInput = "socket";
|
|
|
|
TimeoutStopSec = 1; # FIXME
|
|
|
|
};
|
2014-04-10 13:12:34 +02:00
|
|
|
script =
|
|
|
|
''
|
|
|
|
#! ${pkgs.stdenv.shell} -e
|
|
|
|
source /etc/bashrc
|
|
|
|
read c
|
|
|
|
eval "command=($c)"
|
|
|
|
exec "''${command[@]}"
|
|
|
|
'';
|
2014-04-15 11:22:31 +02:00
|
|
|
restartIfChanged = false;
|
2014-03-17 14:04:39 +01:00
|
|
|
};
|
|
|
|
|
2014-04-01 16:02:53 +02:00
|
|
|
systemd.services.container-startup-done =
|
|
|
|
{ description = "Container Startup Notification";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "multi-user.target" ];
|
|
|
|
script =
|
|
|
|
''
|
|
|
|
if [ -p /var/lib/startup-done ]; then
|
|
|
|
echo done > /var/lib/startup-done
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
serviceConfig.RemainAfterExit = true;
|
2014-04-15 11:26:16 +02:00
|
|
|
restartIfChanged = false;
|
2014-04-01 16:02:53 +02:00
|
|
|
};
|
|
|
|
|
2014-03-17 14:04:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|