From: Alyssa Ross <hi@alyssa.is>
To: devel@spectrum-os.org
Subject: [PATCH nixpkgs 08/16] spectrumPackages.rootfs: add s6-rc support
Date: Sun, 11 Apr 2021 11:57:32 +0000 [thread overview]
Message-ID: <20210411115740.29615-9-hi@alyssa.is> (raw)
In-Reply-To: <20210411115740.29615-1-hi@alyssa.is>
This allows specifying s6-rc services (which can have dependencies,
and be taken up and down) in the same way that s6 services (which are
merely supervised) are declared.
This removes the spectrumcmd mechanism to clean up the boot process --
it could be reintroduced as an s6-rc service if required.
---
.../linux/spectrum/rootfs/default.nix | 43 +++++++++++++++----
.../linux/spectrum/rootfs/generic.nix | 15 ++++---
.../linux/spectrum/rootfs/rc-services.nix | 26 +++++++++++
.../linux/spectrum/rootfs/stage1.nix | 22 +++-------
4 files changed, 77 insertions(+), 29 deletions(-)
create mode 100644 pkgs/os-specific/linux/spectrum/rootfs/rc-services.nix
diff --git a/pkgs/os-specific/linux/spectrum/rootfs/default.nix b/pkgs/os-specific/linux/spectrum/rootfs/default.nix
index 6f46ad8054b..70ddac4c545 100644
--- a/pkgs/os-specific/linux/spectrum/rootfs/default.nix
+++ b/pkgs/os-specific/linux/spectrum/rootfs/default.nix
@@ -35,17 +35,44 @@ makeRootfs {
${busybox}/bin/getty -i -n -l ${login} 38400 ttyS0
'';
- run = ''
- if { chown user /dev/wl0 }
+ rcServices.ok-all = {
+ type = writeText "ok-all-type" ''
+ bundle
+ '';
+ contents = writeText "ok-all-contents" ''
+ wayfire
+ '';
+ };
- s6-applyuidgid -u 1000 -g 1000
- export XDG_RUNTIME_DIR /run/user/1000
+ rcServices.wayfire = {
+ type = writeText "wayfire-type" ''
+ longrun
+ '';
+ run = writeScript "wayfire-run" ''
+ #! ${execline}/bin/execlineb -S0
- export PATH ${lib.makeBinPath path}
+ s6-applyuidgid -u 1000 -g 1000
- ${sommelier}/bin/sommelier
- wayfire -c ${wayfireConfig}
- '';
+ export HOME /
+ export PATH ${lib.makeBinPath path}
+ export XDG_RUNTIME_DIR /run/user/1000
+
+ ${sommelier}/bin/sommelier
+ wayfire -c ${wayfireConfig}
+ '';
+ dependencies = writeText "wayfire-dependencies" ''
+ wl0
+ '';
+ };
+
+ rcServices.wl0 = {
+ type = writeText "wl0-type" ''
+ oneshot
+ '';
+ up = writeText "wl0-run" ''
+ chown user /dev/wl0
+ '';
+ };
fonts = [ source-code-pro ];
}
diff --git a/pkgs/os-specific/linux/spectrum/rootfs/generic.nix b/pkgs/os-specific/linux/spectrum/rootfs/generic.nix
index 81fb80a614f..4122abf80c6 100644
--- a/pkgs/os-specific/linux/spectrum/rootfs/generic.nix
+++ b/pkgs/os-specific/linux/spectrum/rootfs/generic.nix
@@ -1,14 +1,14 @@
{ runCommandNoCC, writeScript, writeReferencesToFile, makeFontsConf, lib
-, dash, execline, s6, s6-portable-utils, s6-linux-utils, s6-linux-init, busybox
+, dash, execline, s6, s6-rc, s6-portable-utils, s6-linux-utils, s6-linux-init, busybox
, mesa, squashfs-tools-ng
}:
-{ services, run, fonts ? [], path ? [] }:
+{ services, rcServices ? {}, fonts ? [], path ? [] }:
let
- makeStage1 = import ./stage1.nix {
+ stage1 = import ./stage1.nix {
inherit writeScript lib
- execline s6 s6-portable-utils s6-linux-utils s6-linux-init busybox mesa
+ execline s6 s6-rc s6-portable-utils s6-linux-utils s6-linux-init busybox mesa
path;
};
@@ -16,6 +16,10 @@ let
inherit runCommandNoCC writeScript lib execline;
};
+ makeRcServicesDir = import ./rc-services.nix {
+ inherit runCommandNoCC lib s6-rc;
+ };
+
fontsConf = makeFontsConf { fontDirectories = fonts; };
squashfs = runCommandNoCC "root-squashfs" {} ''
@@ -34,7 +38,7 @@ let
mkdir bin sbin dev proc run sys tmp
ln -s ${dash}/bin/dash bin/sh
- ln -s ${makeStage1 { inherit run; }} sbin/init
+ ln -s ${stage1} sbin/init
cp -r ${./etc} etc
chmod u+w etc
@@ -43,6 +47,7 @@ let
touch etc/login.defs
cp -r ${makeServicesDir { inherit services; }} etc/service
+ cp -r ${makeRcServicesDir { services = rcServices; }} etc/s6-rc
'';
in
rootfs
diff --git a/pkgs/os-specific/linux/spectrum/rootfs/rc-services.nix b/pkgs/os-specific/linux/spectrum/rootfs/rc-services.nix
new file mode 100644
index 00000000000..4c942189c5e
--- /dev/null
+++ b/pkgs/os-specific/linux/spectrum/rootfs/rc-services.nix
@@ -0,0 +1,26 @@
+{ runCommandNoCC, lib, s6-rc }:
+
+{ services ? [] }:
+
+let
+ inherit (lib) concatStrings escapeShellArg mapAttrsToList optionalString;
+
+ source = runCommandNoCC "s6-services-source" {} ''
+ mkdir $out
+ ${concatStrings (mapAttrsToList (name: attrs: ''
+ mkdir $out/${name}
+ ${concatStrings (mapAttrsToList (key: value: ''
+ cp ${value} $out/${name}/${key}
+ '') attrs)}
+ '') services)}
+ '';
+
+ s6RcCompile = { fdhuser ? null }: source:
+ runCommandNoCC "s6-rc-compile" {} ''
+ ${s6-rc}/bin/s6-rc-compile \
+ ${optionalString (fdhuser != null) "-h ${escapeShellArg fdhuser}"} \
+ $out ${source}
+ '';
+in
+
+s6RcCompile {} source
diff --git a/pkgs/os-specific/linux/spectrum/rootfs/stage1.nix b/pkgs/os-specific/linux/spectrum/rootfs/stage1.nix
index 6caf9ff93b8..13de2d09876 100644
--- a/pkgs/os-specific/linux/spectrum/rootfs/stage1.nix
+++ b/pkgs/os-specific/linux/spectrum/rootfs/stage1.nix
@@ -1,13 +1,11 @@
{ writeScript, lib
-, execline, s6, s6-portable-utils, s6-linux-utils, s6-linux-init, busybox, mesa
+, execline, s6, s6-rc, s6-portable-utils, s6-linux-utils, s6-linux-init, busybox, mesa
, path ? []
}:
-{ run ? "true" }:
-
let
path' = path ++ [
- s6 s6-portable-utils s6-linux-utils s6-linux-init busybox execline
+ s6 s6-rc s6-portable-utils s6-linux-utils s6-linux-init busybox execline
];
in
@@ -16,8 +14,6 @@ writeScript "init-stage1" ''
export PATH ${lib.makeBinPath path'}
${s6}/bin/s6-setsid -qb --
- importas -i spectrumcmd spectrumcmd
-
umask 022
if { s6-mount -t tmpfs -o mode=0755 tmpfs /run }
if { s6-hiercopy /etc/service /run/service }
@@ -25,6 +21,9 @@ writeScript "init-stage1" ''
background {
s6-setsid --
+
+ if { s6-rc-init -c /etc/s6-rc /run/service }
+
if { s6-mkdir -p /run/user/0 /dev/pts /dev/shm }
if { install -o user -g user -d /run/user/1000 }
if { s6-mount -t devpts -o gid=4,mode=620 none /dev/pts }
@@ -33,16 +32,7 @@ writeScript "init-stage1" ''
if { s6-mount -t sysfs none /sys }
if { s6-ln -s ${mesa.drivers} /run/opengl-driver }
- export HOME /
- export XDG_RUNTIME_DIR /run/user/0
- foreground {
- ifelse { test -n $spectrumcmd }
- { pipeline { heredoc 0 $spectrumcmd base64 -d } /bin/sh }
- ${run}
- }
- importas -i ? ?
- if { s6-echo STATUS: $? }
- s6-svscanctl -6 /run/service
+ s6-rc change ok-all
}
unexport !
--
2.30.0
next prev parent reply other threads:[~2021-04-11 11:59 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-11 11:57 [PATCH nixpkgs 00/16] Inter-guest networking Alyssa Ross
2021-04-11 11:57 ` [PATCH nixpkgs 01/16] linux: enable Xen everywhere it can be Alyssa Ross
2021-04-11 11:57 ` [PATCH nixpkgs 02/16] cloud-hypervisor: 0.8.0 -> 0.14.1 Alyssa Ross
2021-04-11 11:57 ` [PATCH nixpkgs 03/16] mdevd: init at 0.1.3.0 Alyssa Ross
2021-04-11 11:57 ` [PATCH nixpkgs 04/16] spectrumPackages.linux_vm: fix cloud-hypervisor hotplug Alyssa Ross
2021-04-11 11:57 ` [PATCH nixpkgs 05/16] spectrumPackages.linux_vm: allow config overrides Alyssa Ross
2021-04-11 11:57 ` [PATCH nixpkgs 06/16] crosvm: support setting guest MAC from --tap-fd Alyssa Ross
2021-04-11 11:57 ` [PATCH nixpkgs 07/16] spectrumPackages: export makeRootfs Alyssa Ross
2021-04-11 11:57 ` Alyssa Ross [this message]
2021-04-11 11:57 ` [PATCH nixpkgs 09/16] spectrumPackages.rootfs: make /var/lib and /var/run Alyssa Ross
2021-04-11 11:57 ` [PATCH nixpkgs 10/16] spectrumPackages.rootfs: add dbus configuration Alyssa Ross
2021-04-11 11:57 ` [PATCH nixpkgs 11/16] spectrumPackages.rootfs: add connman dbus services Alyssa Ross
2021-04-11 11:57 ` [PATCH nixpkgs 12/16] spectrumPackages.sys-vms.comp: init Alyssa Ross
2021-04-11 11:57 ` [PATCH nixpkgs 13/16] spectrumPackages.makeRootfs: move to default.nix Alyssa Ross
2021-04-11 11:57 ` [PATCH nixpkgs 14/16] spectrumPackages.sys-vms.net: init Alyssa Ross
2021-04-14 20:49 ` Alyssa Ross
2021-04-11 11:57 ` [PATCH nixpkgs 15/16] spectrumPackages.sys-vms.app: init Alyssa Ross
2021-04-11 11:57 ` [PATCH nixpkgs 16/16] spectrumPackages.spectrum-testhost: init Alyssa Ross
2021-04-14 22:15 ` [PATCH nixpkgs 00/16] Inter-guest networking Cole Helbling
2021-04-14 23:56 ` Alyssa Ross
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210411115740.29615-9-hi@alyssa.is \
--to=hi@alyssa.is \
--cc=devel@spectrum-os.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://spectrum-os.org/git/crosvm
https://spectrum-os.org/git/doc
https://spectrum-os.org/git/mktuntap
https://spectrum-os.org/git/nixpkgs
https://spectrum-os.org/git/spectrum
https://spectrum-os.org/git/ucspi-vsock
https://spectrum-os.org/git/www
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).