Merge remote-tracking branch 'origin/master' into staging.
Conflicts: pkgs/desktops/e18/enlightenment.nix
This commit is contained in:
@@ -172,7 +172,7 @@ in
|
||||
boot.initrd.extraUtilsCommands =
|
||||
''
|
||||
# We need swapon in the initrd.
|
||||
cp ${pkgs.utillinux}/sbin/swapon $out/bin
|
||||
cp --remove-destination ${pkgs.utillinux}/sbin/swapon $out/bin
|
||||
'';
|
||||
|
||||
# Don't put old configurations in the GRUB menu. The user has no
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
# Systemd services for docker.
|
||||
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
|
||||
cfg = config.virtualisation.docker;
|
||||
|
||||
in
|
||||
|
||||
{
|
||||
###### interface
|
||||
|
||||
options.virtualisation.docker = {
|
||||
enable =
|
||||
mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description =
|
||||
''
|
||||
This option enables docker, a daemon that manages
|
||||
linux containers. Users in the "docker" group can interact with
|
||||
the daemon (e.g. to start or stop containers) using the
|
||||
<command>docker</command> command line tool.
|
||||
'';
|
||||
};
|
||||
socketActivation =
|
||||
mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description =
|
||||
''
|
||||
This option enables docker with socket activation. I.e. docker will
|
||||
start when first called by client.
|
||||
|
||||
Note: This is false by default because systemd lower than 214 that
|
||||
nixos uses so far, doesn't support SocketGroup option, so socket
|
||||
created by docker has root group now. This will likely be changed
|
||||
in future. So set this option explicitly to false if you wish.
|
||||
'';
|
||||
};
|
||||
extraOptions =
|
||||
mkOption {
|
||||
type = types.str;
|
||||
default = "";
|
||||
description =
|
||||
''
|
||||
The extra command-line options to pass to
|
||||
<command>docker</command> daemon.
|
||||
'';
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
|
||||
###### implementation
|
||||
|
||||
config = mkIf cfg.enable (mkMerge [
|
||||
{ environment.systemPackages = [ pkgs.docker ];
|
||||
}
|
||||
(mkIf cfg.socketActivation {
|
||||
|
||||
systemd.services.docker = {
|
||||
description = "Docker Application Container Engine";
|
||||
after = [ "network.target" "docker.socket" ];
|
||||
requires = [ "docker.socket" ];
|
||||
serviceConfig = {
|
||||
ExecStart = "${pkgs.docker}/bin/docker --daemon=true --host=fd:// --group=docker ${cfg.extraOptions}";
|
||||
# I'm not sure if that limits aren't too high, but it's what
|
||||
# goes in config bundled with docker itself
|
||||
LimitNOFILE = 1048576;
|
||||
LimitNPROC = 1048576;
|
||||
};
|
||||
};
|
||||
|
||||
systemd.sockets.docker = {
|
||||
description = "Docker Socket for the API";
|
||||
wantedBy = [ "sockets.target" ];
|
||||
socketConfig = {
|
||||
ListenStream = "/var/run/docker.sock";
|
||||
SocketMode = "0660";
|
||||
SocketUser = "root";
|
||||
SocketGroup = "docker";
|
||||
};
|
||||
};
|
||||
})
|
||||
(mkIf (!cfg.socketActivation) {
|
||||
|
||||
systemd.services.docker = {
|
||||
description = "Docker Application Container Engine";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "network.target" ];
|
||||
serviceConfig = {
|
||||
ExecStart = "${pkgs.docker}/bin/docker --daemon=true --group=docker ${cfg.extraOptions}";
|
||||
# I'm not sure if that limits aren't too high, but it's what
|
||||
# goes in config bundled with docker itself
|
||||
LimitNOFILE = 1048576;
|
||||
LimitNPROC = 1048576;
|
||||
};
|
||||
|
||||
# Presumably some containers are running we don't want to interrupt
|
||||
restartIfChanged = false;
|
||||
};
|
||||
})
|
||||
]);
|
||||
|
||||
}
|
||||
@@ -121,19 +121,6 @@ in
|
||||
|
||||
networking.usePredictableInterfaceNames = false;
|
||||
|
||||
systemd.services.wait-metadata-online = {
|
||||
description = "Wait for GCE metadata server to become reachable";
|
||||
wantedBy = [ "network-online.target" ];
|
||||
before = [ "network-online.target" ];
|
||||
path = [ pkgs.netcat ];
|
||||
script = ''
|
||||
# wait for the metadata server to become available for up to 60 seconds
|
||||
for counter in {1..30}; do sleep 2 && nc -vzw 2 metadata 80 && break; done
|
||||
'';
|
||||
serviceConfig.Type = "oneshot";
|
||||
serviceConfig.RemainAfterExit = true;
|
||||
};
|
||||
|
||||
systemd.services.fetch-ssh-keys =
|
||||
{ description = "Fetch host keys and authorized_keys for root user";
|
||||
|
||||
@@ -142,14 +129,15 @@ in
|
||||
after = [ "network-online.target" ];
|
||||
wants = [ "network-online.target" ];
|
||||
|
||||
path = [ pkgs.curl ];
|
||||
path = [ pkgs.wget ];
|
||||
script =
|
||||
''
|
||||
wget="wget --retry-connrefused -t 6 --waitretry=10"
|
||||
# Don't download the SSH key if it has already been downloaded
|
||||
if ! [ -e /root/.ssh/authorized_keys ]; then
|
||||
echo "obtaining SSH key..."
|
||||
mkdir -p /root/.ssh
|
||||
curl -o /root/authorized-keys-metadata http://metadata/0.1/meta-data/authorized-keys
|
||||
$wget -O /root/authorized-keys-metadata http://metadata/0.1/meta-data/authorized-keys
|
||||
if [ $? -eq 0 -a -e /root/authorized-keys-metadata ]; then
|
||||
cat /root/authorized-keys-metadata | cut -d: -f2- > /root/key.pub
|
||||
if ! grep -q -f /root/key.pub /root/.ssh/authorized_keys; then
|
||||
@@ -162,7 +150,7 @@ in
|
||||
fi
|
||||
|
||||
echo "obtaining SSH private host key..."
|
||||
curl -o /root/ssh_host_ecdsa_key --retry-max-time 60 http://metadata/0.1/meta-data/attributes/ssh_host_ecdsa_key
|
||||
$wget -O /root/ssh_host_ecdsa_key http://metadata/0.1/meta-data/attributes/ssh_host_ecdsa_key
|
||||
if [ $? -eq 0 -a -e /root/ssh_host_ecdsa_key ]; then
|
||||
mv -f /root/ssh_host_ecdsa_key /etc/ssh/ssh_host_ecdsa_key
|
||||
echo "downloaded ssh_host_ecdsa_key"
|
||||
@@ -170,7 +158,7 @@ in
|
||||
fi
|
||||
|
||||
echo "obtaining SSH public host key..."
|
||||
curl -o /root/ssh_host_ecdsa_key.pub --retry-max-time 60 http://metadata/0.1/meta-data/attributes/ssh_host_ecdsa_key_pub
|
||||
$wget -O /root/ssh_host_ecdsa_key.pub http://metadata/0.1/meta-data/attributes/ssh_host_ecdsa_key_pub
|
||||
if [ $? -eq 0 -a -e /root/ssh_host_ecdsa_key.pub ]; then
|
||||
mv -f /root/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub
|
||||
echo "downloaded ssh_host_ecdsa_key.pub"
|
||||
@@ -179,7 +167,7 @@ in
|
||||
'';
|
||||
serviceConfig.Type = "oneshot";
|
||||
serviceConfig.RemainAfterExit = true;
|
||||
serviceConfig.StandardError = "journal+console";
|
||||
serviceConfig.StandardOutput = "journal+console";
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -275,12 +275,10 @@ in
|
||||
|
||||
boot.loader.grub.device = mkVMOverride "/dev/vda";
|
||||
|
||||
boot.initrd.supportedFilesystems = optional cfg.writableStore "unionfs-fuse";
|
||||
|
||||
boot.initrd.extraUtilsCommands =
|
||||
''
|
||||
# We need mke2fs in the initrd.
|
||||
cp ${pkgs.e2fsprogs}/sbin/mke2fs $out/bin
|
||||
cp -f ${pkgs.e2fsprogs}/sbin/mke2fs $out/bin
|
||||
'';
|
||||
|
||||
boot.initrd.postDeviceCommands =
|
||||
@@ -303,20 +301,6 @@ in
|
||||
chmod 1777 $targetRoot/tmp
|
||||
|
||||
mkdir -p $targetRoot/boot
|
||||
${optionalString cfg.writableStore ''
|
||||
mkdir -p /unionfs-chroot/ro-store
|
||||
mount --rbind $targetRoot/nix/store /unionfs-chroot/ro-store
|
||||
|
||||
mkdir /unionfs-chroot/rw-store
|
||||
${if cfg.writableStoreUseTmpfs then ''
|
||||
mount -t tmpfs -o "mode=755" none /unionfs-chroot/rw-store
|
||||
'' else ''
|
||||
mkdir $targetRoot/.nix-rw-store
|
||||
mount --bind $targetRoot/.nix-rw-store /unionfs-chroot/rw-store
|
||||
''}
|
||||
|
||||
unionfs -o allow_other,cow,nonempty,chroot=/unionfs-chroot,max_files=32768,hide_meta_files /rw-store=RW:/ro-store=RO $targetRoot/nix/store
|
||||
''}
|
||||
'';
|
||||
|
||||
# After booting, register the closure of the paths in
|
||||
@@ -343,12 +327,13 @@ in
|
||||
# configuration, where the regular value for the `fileSystems'
|
||||
# attribute should be disregarded for the purpose of building a VM
|
||||
# test image (since those filesystems don't exist in the VM).
|
||||
fileSystems = mkVMOverride
|
||||
fileSystems = mkVMOverride (
|
||||
{ "/".device = "/dev/vda";
|
||||
"/nix/store" =
|
||||
${if cfg.writableStore then "/nix/.ro-store" else "/nix/store"} =
|
||||
{ device = "store";
|
||||
fsType = "9p";
|
||||
options = "trans=virtio,version=9p2000.L,msize=1048576,cache=loose";
|
||||
neededForBoot = true;
|
||||
};
|
||||
"/tmp/xchg" =
|
||||
{ device = "xchg";
|
||||
@@ -362,6 +347,18 @@ in
|
||||
options = "trans=virtio,version=9p2000.L,msize=1048576";
|
||||
neededForBoot = true;
|
||||
};
|
||||
} // optionalAttrs cfg.writableStore
|
||||
{ "/nix/store" =
|
||||
{ fsType = "unionfs-fuse";
|
||||
device = "unionfs";
|
||||
options = "allow_other,cow,nonempty,chroot=/mnt-root,max_files=32768,hide_meta_files,dirs=/nix/.rw-store=rw:/nix/.ro-store=ro";
|
||||
};
|
||||
} // optionalAttrs (cfg.writableStore && cfg.writableStoreUseTmpfs)
|
||||
{ "/nix/.rw-store" =
|
||||
{ fsType = "tmpfs";
|
||||
options = "mode=0755";
|
||||
neededForBoot = true;
|
||||
};
|
||||
} // optionalAttrs cfg.useBootLoader
|
||||
{ "/boot" =
|
||||
{ device = "/dev/disk/by-label/boot";
|
||||
@@ -369,7 +366,7 @@ in
|
||||
options = "ro";
|
||||
noCheck = true; # fsck fails on a r/o filesystem
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
swapDevices = mkVMOverride [ ];
|
||||
boot.initrd.luks.devices = mkVMOverride [];
|
||||
|
||||
Reference in New Issue
Block a user