commit 797aa30c475b7317e774c783ee58cbe854060fb2
parent 85f7f7293dc0bb6146c97dc5c97bb66d655cd40d
Author: Daniel Barlow <dan@telent.net>
Date: Tue, 27 Sep 2022 10:19:44 +0100
make s6-init-files into a module
Diffstat:
10 files changed, 161 insertions(+), 172 deletions(-)
diff --git a/default.nix b/default.nix
@@ -8,10 +8,10 @@ let
./modules/base.nix
({ lib, ... } : { config = { inherit (device) kernel; }; })
<liminix-config>
- ./modules/s6-rc.nix
+ ./modules/s6
] nixpkgs.pkgs;
finalConfig = config // {
- packages = (with nixpkgs.pkgs; [ s6-init-files s6-rc ]) ++
+ packages = (with nixpkgs.pkgs; [ s6-rc ]) ++
config.systemPackages ++
(builtins.attrValues config.services);
};
diff --git a/make-image.nix b/make-image.nix
@@ -5,7 +5,6 @@
, callPackage
, pseudofile
, runCommand
-, s6-init-files
, writeText
} : config :
let
@@ -39,7 +38,6 @@ let
# depend on are also added
storeContents = [
pseudofiles
- s6-init-files
config-pseudofiles
] ++ config.packages ;
};
@@ -49,6 +47,6 @@ in runCommand "frob-squashfs" {
cp ${storefs} ./store.img
chmod +w store.img
mksquashfs - store.img -no-recovery -quiet -no-progress -root-becomes store -p "/ d 0755 0 0"
- mksquashfs - store.img -no-recovery -quiet -no-progress -root-becomes nix -pf ${pseudofiles} -pf ${s6-init-files} -pf ${config-pseudofiles}
+ mksquashfs - store.img -no-recovery -quiet -no-progress -root-becomes nix -pf ${pseudofiles} -pf ${config-pseudofiles}
cp store.img $out
''
diff --git a/modules/s6-rc.nix b/modules/s6-rc.nix
@@ -1,21 +0,0 @@
-{ config, pkgs, ... }:
-let
- s6-rc-db = pkgs.s6-rc-database.override {
- services = builtins.attrValues config.services;
- };
- inherit (pkgs.pseudofile) dir symlink;
- inherit (pkgs) s6-init-bin;
-in {
- config = {
- environment = dir {
- etc = dir {
- s6-rc = dir {
- compiled = symlink "${s6-rc-db}/compiled";
- };
- };
- bin = dir {
- init = symlink "${s6-init-bin}/bin/init";
- };
- };
- };
-}
diff --git a/modules/s6/default.nix b/modules/s6/default.nix
@@ -0,0 +1,158 @@
+{ config, pkgs, ... }:
+let
+ inherit (pkgs)
+ busybox
+ execline
+ s6
+ s6-init-bin
+ s6-linux-init
+ stdenvNoCC;
+ inherit (pkgs.pseudofile) dir symlink;
+
+ s6-rc-db = pkgs.s6-rc-database.override {
+ services = builtins.attrValues config.services;
+ };
+ s6-init-scripts = stdenvNoCC.mkDerivation {
+ name = "s6-scripts";
+ src = ./scripts;
+ phases = ["unpackPhase" "installPhase" ];
+ buildInputs = [busybox];
+ installPhase = ''
+ mkdir $out
+ cp -r $src $out/scripts
+ chmod -R +w $out
+ patchShebangs $out/scripts
+ '';
+ };
+ service = dir {
+ s6-linux-init-runleveld = dir {
+ notification-fd = { file = "3"; };
+ run = {
+ file = ''
+ #!${execline}/bin/execlineb -P
+ ${execline}/bin/fdmove -c 2 1
+ ${execline}/bin/fdmove 1 3
+ ${s6}/bin/s6-ipcserver -1 -a 0700 -c 1 -- s
+ ${s6}/bin/s6-sudod -dt30000 -- "/etc/s6-linux-init/current"/scripts/runlevel
+ '';
+ mode = "0755";
+ };
+ };
+ s6-linux-init-shutdownd = dir {
+ fifo = {
+ type = "i";
+ subtype = "f";
+ mode = "0600";
+ };
+ run = {
+ file = ''
+ #!${execline}/bin/execlineb -P
+ ${s6-linux-init}/bin/s6-linux-init-shutdownd -c "/etc/s6-linux-init/current" -g 3000
+ '';
+ mode = "0755";
+ };
+ };
+ s6-svscan-log = dir {
+ fifo = {
+ type = "i";
+ subtype = "f";
+ mode = "0600";
+ };
+ notification-fd = { file = "3"; };
+ run = {
+ file = ''
+ #!${execline}/bin/execlineb -P
+ ${execline}/bin/redirfd -w 1 /dev/null
+ ${execline}/bin/redirfd -rnb 0 fifo
+ ${s6}/bin/s6-log -bpd3 -- t /run/uncaught-logs
+ '';
+ mode = "0755";
+ };
+ };
+ getty = dir {
+ run = {
+ file = ''
+ #!${execline}/bin/execlineb -P
+ ${busybox}/bin/getty -l ${busybox}/bin/login 38400 /dev/console
+ '';
+ mode = "0755";
+ };
+ };
+ ".s6-svscan" =
+ let
+ quit = message: ''
+ #!${execline}/bin/execlineb -P
+ ${execline}/bin/redirfd -w 2 /dev/console
+ ${execline}/bin/fdmove -c 1 2
+ ${execline}/bin/foreground { ${s6-linux-init}/bin/s6-linux-init-echo -- ${message} }
+ ${s6-linux-init}/bin/s6-linux-init-hpr -fr
+ '';
+ shutdown = action: ''
+ #!${execline}/bin/execlineb -P
+ ${s6-linux-init}/bin/s6-linux-init-hpr -a #{action} -- now
+ '';
+ empty = "#!${execline}/bin/execlineb -P\n";
+ in dir {
+ crash = {
+ file = quit "s6-svscan crashed. Rebooting.";
+ mode = "0755";
+ };
+ finish = {
+ file = quit "s6-svscan exited. Rebooting.";
+ mode = "0755";
+ };
+ SIGINT = {
+ file = shutdown "-r";
+ mode = "0755";
+ };
+ SIGPWR = {
+ file = shutdown "-p";
+ mode = "0755";
+ };
+ SIGQUIT = {
+ file = empty;
+ mode = "0755";
+ };
+ SIGTERM = {
+ file = empty;
+ mode = "0755";
+ };
+ SIGUSR1 = {
+ file = shutdown "-p";
+ mode = "0755";
+ };
+ SIGUSR2 = {
+ file = shutdown "-h";
+ mode = "0755";
+ };
+ SIGWINCH = {
+ file = empty;
+ mode = "0755";
+ };
+
+ };
+ };
+in {
+ config = {
+ environment = dir {
+ etc = dir {
+ s6-rc = dir {
+ compiled = symlink "${s6-rc-db}/compiled";
+ };
+ s6-linux-init = dir {
+ current = dir {
+ scripts = symlink "${s6-init-scripts}/scripts";
+ env = dir {};
+ run-image = dir {
+ uncaught-logs = (dir {}) // {mode = "2750";};
+ inherit service;
+ };
+ };
+ };
+ };
+ bin = dir {
+ init = symlink "${s6-init-bin}/bin/init";
+ };
+ };
+ };
+}
diff --git a/pkgs/s6-init-files/scripts/rc.init b/modules/s6/scripts/rc.init
diff --git a/pkgs/s6-init-files/scripts/rc.shutdown b/modules/s6/scripts/rc.shutdown
diff --git a/pkgs/s6-init-files/scripts/rc.shutdown.final b/modules/s6/scripts/rc.shutdown.final
diff --git a/pkgs/s6-init-files/scripts/runlevel b/modules/s6/scripts/runlevel
diff --git a/overlay.nix b/overlay.nix
@@ -1,15 +1,12 @@
final: prev: {
pseudofile = final.callPackage ./pkgs/pseudofile {};
- s6-init-files = final.callPackage ./pkgs/s6-init-files {};
strace = prev.strace.override { libunwind = null; };
liminix = {
services = final.callPackage ./pkgs/liminix-tools/services {};
networking = final.callPackage ./pkgs/liminix-tools/networking {};
};
writeAshScript = final.callPackage ./pkgs/write-ash-script {};
-
s6-init-bin = final.callPackage ./pkgs/s6-init-bin {};
-
s6-rc-database = final.callPackage ./pkgs/s6-rc-database {};
pppoe = prev.rpPPPoE.overrideAttrs (o: {
diff --git a/pkgs/s6-init-files/default.nix b/pkgs/s6-init-files/default.nix
@@ -1,143 +0,0 @@
-{
- execline
-, s6
-, s6-linux-init
-, s6-rc
-, pseudofile
-, lib
-, stdenvNoCC
-, busybox
-} :
-let
- initscripts = stdenvNoCC.mkDerivation {
- name = "s6-scripts";
- src = ./scripts;
- phases = ["unpackPhase" "installPhase" ];
- buildInputs = [busybox];
- installPhase = ''
- mkdir $out
- cp -r $src $out/scripts
- chmod -R +w $out
- patchShebangs $out/scripts
- '';
- };
- inherit (pseudofile) dir symlink;
- scripts = symlink "${initscripts}/scripts";
- env = dir {};
- run-image = dir {
- service = dir {
- s6-linux-init-runleveld = dir {
- notification-fd = { file = "3"; };
- run = {
- file = ''
- #!${execline}/bin/execlineb -P
- ${execline}/bin/fdmove -c 2 1
- ${execline}/bin/fdmove 1 3
- ${s6}/bin/s6-ipcserver -1 -a 0700 -c 1 -- s
- ${s6}/bin/s6-sudod -dt30000 -- "/etc/s6-linux-init/current"/scripts/runlevel
- '';
- mode = "0755";
- };
- };
- s6-linux-init-shutdownd = dir {
- fifo = {
- type = "i";
- subtype = "f";
- mode = "0600";
- };
- run = {
- file = ''
- #!${execline}/bin/execlineb -P
- ${s6-linux-init}/bin/s6-linux-init-shutdownd -c "/etc/s6-linux-init/current" -g 3000
- '';
- mode = "0755";
- };
-
- };
- s6-svscan-log = dir {
- fifo = {
- type = "i";
- subtype = "f";
- mode = "0600";
- };
- notification-fd = { file = "3"; };
- run = {
- file = ''
- #!${execline}/bin/execlineb -P
- ${execline}/bin/redirfd -w 1 /dev/null
- ${execline}/bin/redirfd -rnb 0 fifo
- ${s6}/bin/s6-log -bpd3 -- t /run/uncaught-logs
- '';
- mode = "0755";
- };
- };
- getty = dir {
- run = {
- file = ''
- #!${execline}/bin/execlineb -P
- ${busybox}/bin/getty -l ${busybox}/bin/login 38400 /dev/console
- '';
- mode = "0755";
- };
- };
- ".s6-svscan" =
- let
- quit = message: ''
- #!${execline}/bin/execlineb -P
- ${execline}/bin/redirfd -w 2 /dev/console
- ${execline}/bin/fdmove -c 1 2
- ${execline}/bin/foreground { ${s6-linux-init}/bin/s6-linux-init-echo -- ${message} }
- ${s6-linux-init}/bin/s6-linux-init-hpr -fr
- '';
- shutdown = action: ''
- #!${execline}/bin/execlineb -P
- ${s6-linux-init}/bin/s6-linux-init-hpr -a #{action} -- now
- '';
- empty = "#!${execline}/bin/execlineb -P\n";
- in dir {
- crash = {
- file = quit "s6-svscan crashed. Rebooting.";
- mode = "0755";
- };
- finish = {
- file = quit "s6-svscan exited. Rebooting.";
- mode = "0755";
- };
- SIGINT = {
- file = shutdown "-r";
- mode = "0755";
- };
- SIGPWR = {
- file = shutdown "-p";
- mode = "0755";
- };
- SIGQUIT = {
- file = empty;
- mode = "0755";
- };
- SIGTERM = {
- file = empty;
- mode = "0755";
- };
- SIGUSR1 = {
- file = shutdown "-p";
- mode = "0755";
- };
- SIGUSR2 = {
- file = shutdown "-h";
- mode = "0755";
- };
- SIGWINCH = {
- file = empty;
- mode = "0755";
- };
-
- };
- };
- uncaught-logs = (dir {}) // {mode = "2750";};
- };
- structure = { etc = dir { s6-linux-init = dir { current = dir {
- inherit scripts env run-image;
- };};};};
-
-in pseudofile.write "pseudo.s6-init" structure