liminix/pkgs/levitate/default.nix
Raito Bezarius c515e4354b
Some checks failed
build liminix / test_shell_customization (push) Has been cancelled
build liminix / build_zyxel-nwa50ax_mips (push) Has been cancelled
build liminix / build_vm_qemu_mips (push) Has been cancelled
build liminix / test_hostapd (push) Has been cancelled
fix: do not redefine pkgs and lim for levitated system
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-12-07 16:15:12 +01:00

86 lines
2.2 KiB
Nix

{
writeScriptBin
, writeScript
, systemconfig
, stdenv
, execline
, lib
, config ? {}
, liminix
, pseudofile
, pkgs
} :
let
inherit (pseudofile) dir symlink;
inherit (liminix.services) oneshot;
paramConfig = config;
newRoot = "/run/maintenance";
sysconfig =
let
doChroot = writeScript "exec" ''
#!${execline}/bin/execlineb -P
cd ${newRoot}
foreground { mount --move ${newRoot} / }
redirfd -r 0 /dev/console
redirfd -w 1 /dev/console
fdmove -c 2 1
emptyenv chroot . /bin/init
'';
base = {...} : {
config = {
services = {
banner = oneshot {
name = "banner";
up = "cat /etc/banner > /dev/console";
down = "true";
};
};
filesystem = dir {
exec = symlink doChroot;
etc = dir {
banner = symlink (pkgs.writeText "banner" ''
LADIES AND GENTLEMEN WE ARE FLOATING IN SPACE
Most services are disabled. The system is operating
with a ram-based root filesystem, making it safe to
overwrite the flash devices in order to perform
upgrades and maintenance.
Don't forget to reboot when you have finished.
'');
};
};
};
};
eval = lib.evalModules {
modules = [
../../modules/base.nix
../../modules/users.nix
../../modules/busybox.nix
../../modules/hostname.nix
../../modules/misc/assertions.nix
../../modules/nixpkgs.nix
base
{
# Inherit from that target system host platform.
nixpkgs.hostPlatform = stdenv.hostPlatform;
# Force our own package set.
nixpkgs.pkgs = lib.mkForce pkgs;
}
({ ... } : paramConfig)
../../modules/s6
];
};
in systemconfig eval.config.filesystem.contents;
in writeScriptBin "levitate" ''
#!/bin/sh
destdir=${newRoot}
mkdir -p $destdir $destdir/nix/store
for path in $(cat ${sysconfig}/etc/nix-store-paths) ; do
(cd $destdir && cp -a $path .$path)
done
${sysconfig}/bin/activate $destdir
''