-
Notifications
You must be signed in to change notification settings - Fork 39
/
runit.nix
80 lines (76 loc) · 2.21 KB
/
runit.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
{ pkgs, lib, config, ... }:
let
sshd_config = pkgs.writeText "sshd_config" ''
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
Port 22
PidFile /run/sshd.pid
Protocol 2
PermitRootLogin yes
PasswordAuthentication yes
AuthorizedKeysFile /etc/ssh/authorized_keys.d/%u
'';
compat = pkgs.runCommand "runit-compat" {} ''
mkdir -p $out/bin/
cat << EOF > $out/bin/poweroff
#!/bin/sh
exec runit-init 0
EOF
cat << EOF > $out/bin/reboot
#!/bin/sh
exec runit-init 6
EOF
chmod +x $out/bin/{poweroff,reboot}
'';
in
{
environment.systemPackages = [ compat ];
environment.etc = lib.mkMerge [
{
"runit/1".source = pkgs.writeScript "1" ''
#!${pkgs.runtimeShell}
${lib.optionalString config.not-os.simpleStaticIp ''
ip addr add 10.0.2.15 dev eth0
ip link set eth0 up
ip route add 10.0.2.0/24 dev eth0
ip route add default via 10.0.2.2 dev eth0
''}
mkdir /bin/
ln -s ${pkgs.runtimeShell} /bin/sh
${lib.optionalString (config.networking.timeServers != []) ''
${pkgs.ntp}/bin/ntpdate ${toString config.networking.timeServers}
''}
# disable DPMS on tty's
echo -ne "\033[9;0]" > /dev/tty0
touch /etc/runit/stopit
chmod 0 /etc/runit/stopit
${if true then "" else "${pkgs.dhcpcd}/sbin/dhcpcd"}
'';
"runit/2".source = pkgs.writeScript "2" ''
#!${pkgs.runtimeShell}
cat /proc/uptime
exec runsvdir -P /etc/service
'';
"runit/3".source = pkgs.writeScript "3" ''
#!${pkgs.runtimeShell}
echo and down we go
'';
"service/sshd/run".source = pkgs.writeScript "sshd_run" ''
#!${pkgs.runtimeShell}
${pkgs.openssh}/bin/sshd -f ${sshd_config}
'';
"service/nix/run".source = pkgs.writeScript "nix" ''
#!${pkgs.runtimeShell}
nix-store --load-db < /nix/store/nix-path-registration
nix-daemon
'';
}
(lib.mkIf config.not-os.rngd {
"service/rngd/run".source = pkgs.writeScript "rngd" ''
#!${pkgs.runtimeShell}
export PATH=$PATH:${pkgs.rng-tools}/bin
exec rngd -r /dev/hwrng
'';
})
];
}