First attempt at using systemd
Basic booting works. Systemd starts agetty instances on tty1 and tty2. Shutdown and journald also work.
This commit is contained in:
parent
f2a33809c1
commit
f21aa7d22c
|
@ -17,7 +17,6 @@ let
|
||||||
|
|
||||||
requiredPackages =
|
requiredPackages =
|
||||||
[ config.system.sbin.modprobe # must take precedence over module_init_tools
|
[ config.system.sbin.modprobe # must take precedence over module_init_tools
|
||||||
config.system.build.upstart
|
|
||||||
config.environment.nix
|
config.environment.nix
|
||||||
pkgs.acl
|
pkgs.acl
|
||||||
pkgs.attr
|
pkgs.attr
|
||||||
|
|
|
@ -198,6 +198,7 @@
|
||||||
./system/boot/stage-1.nix
|
./system/boot/stage-1.nix
|
||||||
./system/boot/stage-1-extratools.nix
|
./system/boot/stage-1-extratools.nix
|
||||||
./system/boot/stage-2.nix
|
./system/boot/stage-2.nix
|
||||||
|
./system/boot/systemd.nix
|
||||||
./system/etc/etc.nix
|
./system/etc/etc.nix
|
||||||
./system/upstart-events/control-alt-delete.nix
|
./system/upstart-events/control-alt-delete.nix
|
||||||
./system/upstart-events/runlevel.nix
|
./system/upstart-events/runlevel.nix
|
||||||
|
|
|
@ -117,12 +117,12 @@ let
|
||||||
|
|
||||||
ln -s ${config.system.build.etc}/etc $out/etc
|
ln -s ${config.system.build.etc}/etc $out/etc
|
||||||
ln -s ${config.system.path} $out/sw
|
ln -s ${config.system.path} $out/sw
|
||||||
ln -s ${config.system.build.upstart} $out/upstart
|
ln -s ${pkgs.systemd} $out/systemd
|
||||||
ln -s ${config.hardware.firmware} $out/firmware
|
ln -s ${config.hardware.firmware} $out/firmware
|
||||||
|
|
||||||
echo -n "$kernelParams" > $out/kernel-params
|
echo -n "$kernelParams" > $out/kernel-params
|
||||||
echo -n "$configurationName" > $out/configuration-name
|
echo -n "$configurationName" > $out/configuration-name
|
||||||
echo -n "${toString config.system.build.upstart.interfaceVersion}" > $out/upstart-interface-version
|
#echo -n "${toString config.system.build.upstart.interfaceVersion}" > $out/upstart-interface-version
|
||||||
echo -n "$nixosVersion" > $out/nixos-version
|
echo -n "$nixosVersion" > $out/nixos-version
|
||||||
|
|
||||||
mkdir $out/fine-tune
|
mkdir $out/fine-tune
|
||||||
|
@ -173,7 +173,7 @@ let
|
||||||
pkgs.gnugrep
|
pkgs.gnugrep
|
||||||
pkgs.findutils
|
pkgs.findutils
|
||||||
pkgs.diffutils
|
pkgs.diffutils
|
||||||
config.system.build.upstart # for initctl
|
pkgs.systemd
|
||||||
];
|
];
|
||||||
|
|
||||||
# Boot loaders
|
# Boot loaders
|
||||||
|
|
|
@ -56,7 +56,7 @@ fi
|
||||||
mkdir -m 0755 -p /etc
|
mkdir -m 0755 -p /etc
|
||||||
test -e /etc/fstab || touch /etc/fstab # to shut up mount
|
test -e /etc/fstab || touch /etc/fstab # to shut up mount
|
||||||
rm -f /etc/mtab* # not that we care about stale locks
|
rm -f /etc/mtab* # not that we care about stale locks
|
||||||
cat /proc/mounts > /etc/mtab
|
ln -s /proc/mounts /etc/mtab
|
||||||
|
|
||||||
|
|
||||||
# Process the kernel command line.
|
# Process the kernel command line.
|
||||||
|
@ -184,6 +184,12 @@ if [ -n "$debug2" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Start Upstart's init.
|
# FIXME: auto-loading of kernel modules in systemd doesn't work yet
|
||||||
echo "starting Upstart..."
|
# because it uses libkmod.
|
||||||
PATH=/var/run/current-system/upstart/sbin exec init --no-sessions ${debug2:+--verbose}
|
"$(cat /proc/sys/kernel/modprobe)" autofs4
|
||||||
|
"$(cat /proc/sys/kernel/modprobe)" ipv6
|
||||||
|
|
||||||
|
|
||||||
|
# Start systemd.
|
||||||
|
echo "starting systemd..."
|
||||||
|
PATH=/var/run/current-system/systemd/lib/systemd exec systemd --log-level debug --log-target=console --crash-shell
|
||||||
|
|
158
modules/system/boot/systemd.nix
Normal file
158
modules/system/boot/systemd.nix
Normal file
|
@ -0,0 +1,158 @@
|
||||||
|
{ config, pkgs, ... }:
|
||||||
|
|
||||||
|
with pkgs.lib;
|
||||||
|
|
||||||
|
let
|
||||||
|
|
||||||
|
systemd = pkgs.systemd;
|
||||||
|
|
||||||
|
makeUnit = name: text:
|
||||||
|
pkgs.writeTextFile { name = "unit"; inherit text; destination = "/${name}"; };
|
||||||
|
|
||||||
|
defaultTarget = makeUnit "default.target"
|
||||||
|
''
|
||||||
|
[Unit]
|
||||||
|
Description=Default System
|
||||||
|
Requires=getty.target
|
||||||
|
After=getty.target
|
||||||
|
Conflicts=rescue.target
|
||||||
|
AllowIsolate=yes
|
||||||
|
'';
|
||||||
|
|
||||||
|
gettyTarget = makeUnit "getty.target"
|
||||||
|
''
|
||||||
|
[Unit]
|
||||||
|
Description=Login Prompts
|
||||||
|
Requires=getty@tty1.service getty@tty2.service
|
||||||
|
After=getty@tty1.service getty@tty2.service
|
||||||
|
'';
|
||||||
|
|
||||||
|
gettyService = makeUnit "getty@.service"
|
||||||
|
''
|
||||||
|
[Unit]
|
||||||
|
Description=Getty on %I
|
||||||
|
#BindTo=dev-%i.device
|
||||||
|
#After=dev-%i.device systemd-user-sessions.service plymouth-quit-wait.service
|
||||||
|
Before=getty.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Environment=TERM=linux
|
||||||
|
ExecStart=-${pkgs.utillinux}/sbin/agetty --noclear --login-program ${pkgs.shadow}/bin/login %I 38400
|
||||||
|
Restart=always
|
||||||
|
RestartSec=0
|
||||||
|
UtmpIdentifier=%I
|
||||||
|
TTYPath=/dev/%I
|
||||||
|
TTYReset=yes
|
||||||
|
TTYVHangup=yes
|
||||||
|
TTYVTDisallocate=yes
|
||||||
|
KillMode=process
|
||||||
|
IgnoreSIGPIPE=no
|
||||||
|
|
||||||
|
# Unset locale for the console getty since the console has problems
|
||||||
|
# displaying some internationalized messages.
|
||||||
|
Environment=LANG= LANGUAGE= LC_CTYPE= LC_NUMERIC= LC_TIME= LC_COLLATE= LC_MONETARY= LC_MESSAGES= LC_PAPER= LC_NAME= LC_ADDRESS= LC_TELEPHONE= LC_MEASUREMENT= LC_IDENTIFICATION=
|
||||||
|
|
||||||
|
# Some login implementations ignore SIGTERM, so we send SIGHUP
|
||||||
|
# instead, to ensure that login terminates cleanly.
|
||||||
|
KillSignal=SIGHUP
|
||||||
|
'';
|
||||||
|
|
||||||
|
rescueTarget = makeUnit "rescue.target"
|
||||||
|
''
|
||||||
|
[Unit]
|
||||||
|
Description=Rescue Mode
|
||||||
|
Requires=rescue.service
|
||||||
|
After=rescue.service
|
||||||
|
AllowIsolate=yes
|
||||||
|
'';
|
||||||
|
|
||||||
|
rescueService = makeUnit "rescue.service"
|
||||||
|
''
|
||||||
|
[Unit]
|
||||||
|
Description=Rescue Shell
|
||||||
|
DefaultDependencies=no
|
||||||
|
#After=basic.target
|
||||||
|
#Before=shutdown.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Environment=HOME=/root
|
||||||
|
WorkingDirectory=/root
|
||||||
|
ExecStartPre=-${pkgs.coreutils}/bin/echo 'Welcome to rescue mode. Use "systemctl default" or ^D to enter default mode.'
|
||||||
|
#ExecStart=-/sbin/sulogin
|
||||||
|
ExecStart=-${pkgs.bashInteractive}/bin/bash --login
|
||||||
|
ExecStopPost=-${systemd}/bin/systemctl --fail --no-block default
|
||||||
|
StandardInput=tty-force
|
||||||
|
StandardOutput=inherit
|
||||||
|
StandardError=inherit
|
||||||
|
KillMode=process
|
||||||
|
|
||||||
|
# Bash ignores SIGTERM, so we send SIGHUP instead, to ensure that bash
|
||||||
|
# terminates cleanly.
|
||||||
|
KillSignal=SIGHUP
|
||||||
|
'';
|
||||||
|
|
||||||
|
upstreamUnits =
|
||||||
|
[ "systemd-journald.socket"
|
||||||
|
"systemd-journald.service"
|
||||||
|
"basic.target"
|
||||||
|
"sysinit.target"
|
||||||
|
"sysinit.target.wants"
|
||||||
|
"sockets.target"
|
||||||
|
"sockets.target.wants"
|
||||||
|
|
||||||
|
# Filesystems.
|
||||||
|
"local-fs.target"
|
||||||
|
"local-fs.target.wants"
|
||||||
|
"local-fs-pre.target"
|
||||||
|
"remote-fs.target"
|
||||||
|
"remote-fs-pre.target"
|
||||||
|
"swap.target"
|
||||||
|
"media.mount"
|
||||||
|
"dev-mqueue.mount"
|
||||||
|
|
||||||
|
# Reboot stuff.
|
||||||
|
"reboot.target"
|
||||||
|
"reboot.service"
|
||||||
|
"poweroff.target"
|
||||||
|
"poweroff.service"
|
||||||
|
"halt.target"
|
||||||
|
"halt.service"
|
||||||
|
"ctrl-alt-del.target"
|
||||||
|
"shutdown.target"
|
||||||
|
"umount.target"
|
||||||
|
"final.target"
|
||||||
|
];
|
||||||
|
|
||||||
|
systemUnits = pkgs.runCommand "system-units" { }
|
||||||
|
''
|
||||||
|
mkdir -p $out/system
|
||||||
|
for i in ${toString upstreamUnits}; do
|
||||||
|
fn=${systemd}/example/systemd/system/$i
|
||||||
|
echo $fn
|
||||||
|
[ -e $fn ]
|
||||||
|
ln -s $fn $out/system
|
||||||
|
done
|
||||||
|
for i in ${toString [ defaultTarget gettyTarget gettyService rescueTarget rescueService ]}; do
|
||||||
|
cp $i/* $out/system
|
||||||
|
done
|
||||||
|
''; # */
|
||||||
|
|
||||||
|
in
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
###### implementation
|
||||||
|
|
||||||
|
config = {
|
||||||
|
|
||||||
|
environment.systemPackages = [ systemd ];
|
||||||
|
|
||||||
|
environment.etc =
|
||||||
|
[ { source = systemUnits;
|
||||||
|
target = "systemd";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue