1
0

Compare commits

...

3 Commits

Author SHA1 Message Date
1c14bb63fa callPackageify make-image.nix 2022-09-26 16:19:14 +01:00
c6c6b51893 make s6-rc-database a package 2022-09-26 15:59:21 +01:00
cd5afb22e7 remove static busybox 2022-09-26 14:46:06 +01:00
5 changed files with 68 additions and 53 deletions

View File

@ -10,12 +10,11 @@ let
<liminix-config>
] nixpkgs.pkgs;
finalConfig = config // {
packages = (with nixpkgs.pkgs; [ s6-rc ]) ++
packages = (with nixpkgs.pkgs; [ s6-init-files s6-rc ]) ++
config.systemPackages ++
(builtins.attrValues config.services)
;
(builtins.attrValues config.services);
};
squashfs = (import ./make-image.nix) nixpkgs finalConfig;
squashfs = (nixpkgs.pkgs.callPackage ./make-image.nix {}) finalConfig;
kernel = nixpkgs.pkgs.callPackage ./kernel {
inherit (finalConfig.kernel) config;
};

View File

@ -1,47 +1,30 @@
pkgs: config:
let
inherit (pkgs)
callPackage
closureInfo
lib
runCommand
s6-rc
{
stdenv
stdenvNoCC
writeScript
writeText;
, busybox
, buildPackages
, callPackage
, execline
, lib
, runCommand
, s6-init-bin
, s6-init-files
, s6-linux-init
, s6-rc
, s6-rc-database
, stdenvNoCC
, writeScript
, writeText
} : config :
let
s6-rc-db = s6-rc-database.override {
services = builtins.attrValues config.services;
};
# we need to generate s6 db, by generating closure of all
# config.services and calling s6-rc-compile on them
allServices = closureInfo {
rootPaths = builtins.attrValues config.services;
};
s6db = stdenvNoCC.mkDerivation {
name = "s6-rc-db";
nativeBuildInputs = [pkgs.buildPackages.s6-rc];
builder = writeText "find-s6-services" ''
source $stdenv/setup
mkdir -p $out
srcs=""
shopt -s nullglob
for i in $(cat ${allServices}/store-paths ); do
if test -d $i; then
for j in $i/* ; do
if test -f $j/type ; then
srcs="$srcs $i"
fi
done
fi
done
echo s6-rc-compile $out/compiled $srcs
s6-rc-compile $out/compiled $srcs
'';
};
s6-pseudofiles = pkgs.s6-init-files;
profile = writeScript ".profile" ''
PATH=${lib.makeBinPath (with pkgs; [ s6-init-bin busybox execline s6-linux-init s6-rc])}
PATH=${lib.makeBinPath ([ s6-init-bin busybox execline s6-linux-init s6-rc])}
export PATH
'';
pseudofiles = writeText "pseudofiles" ''
/ d 0755 0 0
/bin d 0755 0 0
@ -60,24 +43,25 @@ let
/sys d 0555 root root
/dev/pts d 0755 0 0
/etc/init.d d 0755 0 0
/bin/init s 0755 0 0 ${pkgs.s6-init-bin}/bin/init
/bin/sh s 0755 0 0 ${pkgs.pkgsStatic.busybox}/bin/sh
/bin/busybox s 0755 0 0 ${pkgs.busybox}/bin/busybox
/bin/init s 0755 0 0 ${s6-init-bin}/bin/init
/bin/sh s 0755 0 0 ${busybox}/bin/sh
/bin/busybox s 0755 0 0 ${busybox}/bin/busybox
/etc/s6-rc d 0755 0 0
/etc/s6-rc/compiled s 0755 0 0 ${s6db}/compiled
/etc/s6-rc/compiled s 0755 0 0 ${s6-rc-db}/compiled
/etc/passwd f 0644 0 0 echo "root::0:0:root:/:/bin/sh"
/.profile s 0644 0 0 ${profile}
'';
storefs = callPackage <nixpkgs/nixos/lib/make-squashfs.nix> {
storeContents = [ pseudofiles pkgs.strace s6-pseudofiles pkgs.pkgsStatic.busybox s6db pkgs.s6-linux-init ] ++ config.packages ;
# comp = "xz -Xdict-size 100%"
# add pseudofiles to store so that the packages they
# depend on are also added
storeContents = [ pseudofiles s6-init-files ] ++ config.packages ;
};
in runCommand "frob-squashfs" {
nativeBuildInputs = with pkgs.buildPackages; [ squashfsTools qprint ];
nativeBuildInputs = with buildPackages; [ squashfsTools qprint ];
} ''
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-pseudofiles}
mksquashfs - store.img -no-recovery -quiet -no-progress -root-becomes nix -pf ${pseudofiles} -pf ${s6-init-files}
cp store.img $out
''

View File

@ -10,6 +10,8 @@ final: prev: {
s6-init-bin = final.callPackage ./pkgs/s6-init-bin {};
s6-rc-database = final.callPackage ./pkgs/s6-rc-database {};
pppoe = prev.rpPPPoE.overrideAttrs (o: {
# use newer rp-pppoe, it builds cleanly
src = final.fetchFromGitHub {

View File

@ -0,0 +1,31 @@
# generate s6-rc database, by generating closure of all
# config.services and calling s6-rc-compile on them
{
stdenvNoCC
, buildPackages
, closureInfo
, writeText
, services ? []
}:
let closure-info = closureInfo { rootPaths = services; };
in stdenvNoCC.mkDerivation {
name = "s6-rc-database";
nativeBuildInputs = [buildPackages.s6-rc];
builder = writeText "find-s6-services" ''
source $stdenv/setup
mkdir -p $out
srcs=""
shopt -s nullglob
for i in $(cat ${closure-info}/store-paths ); do
if test -d $i; then
for j in $i/* ; do
if test -f $j/type ; then
srcs="$srcs $i"
fi
done
fi
done
s6-rc-compile $out/compiled $srcs
'';
}

View File

@ -10,7 +10,7 @@ trap cleanup EXIT
trap 'echo "command $(eval echo $BASH_COMMAND) failed with exit code $?"; exit $?' ERR
unsquashfs -q -d $dest_path -excludes smoke.img /dev
cd $dest_path;
db=nix/store/*-s6-rc-db/compiled/
db=nix/store/*-s6-rc-database/compiled/
test -d $db
chmod -R +w $db
# check we have closure of config.services (lo.link.service exists only
@ -21,5 +21,4 @@ echo OK
EOF
)
nix-shell -p s6-rc -p squashfsTools --run "$TESTS" || exit 1