make s6-rc-database a package
This commit is contained in:
parent
cd5afb22e7
commit
c6c6b51893
4 changed files with 44 additions and 31 deletions
|
@ -2,45 +2,24 @@ pkgs: config:
|
||||||
let
|
let
|
||||||
inherit (pkgs)
|
inherit (pkgs)
|
||||||
callPackage
|
callPackage
|
||||||
closureInfo
|
|
||||||
lib
|
lib
|
||||||
runCommand
|
runCommand
|
||||||
s6-rc
|
s6-rc
|
||||||
|
s6-init-files
|
||||||
stdenv
|
stdenv
|
||||||
stdenvNoCC
|
stdenvNoCC
|
||||||
writeScript
|
writeScript
|
||||||
writeText;
|
writeText;
|
||||||
|
|
||||||
# we need to generate s6 db, by generating closure of all
|
s6-rc-db = pkgs.s6-rc-database.override {
|
||||||
# config.services and calling s6-rc-compile on them
|
services = builtins.attrValues config.services;
|
||||||
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
|
|
||||||
s6-rc-compile $out/compiled $srcs
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
s6-pseudofiles = pkgs.s6-init-files;
|
|
||||||
profile = writeScript ".profile" ''
|
profile = writeScript ".profile" ''
|
||||||
PATH=${lib.makeBinPath (with pkgs; [ s6-init-bin busybox execline s6-linux-init s6-rc])}
|
PATH=${lib.makeBinPath (with pkgs; [ s6-init-bin busybox execline s6-linux-init s6-rc])}
|
||||||
export PATH
|
export PATH
|
||||||
'';
|
'';
|
||||||
|
|
||||||
pseudofiles = writeText "pseudofiles" ''
|
pseudofiles = writeText "pseudofiles" ''
|
||||||
/ d 0755 0 0
|
/ d 0755 0 0
|
||||||
/bin d 0755 0 0
|
/bin d 0755 0 0
|
||||||
|
@ -63,12 +42,14 @@ let
|
||||||
/bin/sh s 0755 0 0 ${pkgs.busybox}/bin/sh
|
/bin/sh s 0755 0 0 ${pkgs.busybox}/bin/sh
|
||||||
/bin/busybox s 0755 0 0 ${pkgs.busybox}/bin/busybox
|
/bin/busybox s 0755 0 0 ${pkgs.busybox}/bin/busybox
|
||||||
/etc/s6-rc d 0755 0 0
|
/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"
|
/etc/passwd f 0644 0 0 echo "root::0:0:root:/:/bin/sh"
|
||||||
/.profile s 0644 0 0 ${profile}
|
/.profile s 0644 0 0 ${profile}
|
||||||
'';
|
'';
|
||||||
storefs = callPackage <nixpkgs/nixos/lib/make-squashfs.nix> {
|
storefs = callPackage <nixpkgs/nixos/lib/make-squashfs.nix> {
|
||||||
storeContents = [ pseudofiles s6-pseudofiles s6db pkgs.s6-linux-init ] ++ config.packages ;
|
# add pseudofiles to store so that the packages they
|
||||||
|
# depend on are also added
|
||||||
|
storeContents = [ pseudofiles s6-init-files ] ++ config.packages ;
|
||||||
# comp = "xz -Xdict-size 100%"
|
# comp = "xz -Xdict-size 100%"
|
||||||
};
|
};
|
||||||
in runCommand "frob-squashfs" {
|
in runCommand "frob-squashfs" {
|
||||||
|
@ -77,6 +58,6 @@ in runCommand "frob-squashfs" {
|
||||||
cp ${storefs} ./store.img
|
cp ${storefs} ./store.img
|
||||||
chmod +w 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 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
|
cp store.img $out
|
||||||
''
|
''
|
||||||
|
|
|
@ -10,6 +10,8 @@ final: prev: {
|
||||||
|
|
||||||
s6-init-bin = final.callPackage ./pkgs/s6-init-bin {};
|
s6-init-bin = final.callPackage ./pkgs/s6-init-bin {};
|
||||||
|
|
||||||
|
s6-rc-database = final.callPackage ./pkgs/s6-rc-database {};
|
||||||
|
|
||||||
pppoe = prev.rpPPPoE.overrideAttrs (o: {
|
pppoe = prev.rpPPPoE.overrideAttrs (o: {
|
||||||
# use newer rp-pppoe, it builds cleanly
|
# use newer rp-pppoe, it builds cleanly
|
||||||
src = final.fetchFromGitHub {
|
src = final.fetchFromGitHub {
|
||||||
|
|
31
pkgs/s6-rc-database/default.nix
Normal file
31
pkgs/s6-rc-database/default.nix
Normal 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
|
||||||
|
'';
|
||||||
|
}
|
|
@ -10,7 +10,7 @@ trap cleanup EXIT
|
||||||
trap 'echo "command $(eval echo $BASH_COMMAND) failed with exit code $?"; exit $?' ERR
|
trap 'echo "command $(eval echo $BASH_COMMAND) failed with exit code $?"; exit $?' ERR
|
||||||
unsquashfs -q -d $dest_path -excludes smoke.img /dev
|
unsquashfs -q -d $dest_path -excludes smoke.img /dev
|
||||||
cd $dest_path;
|
cd $dest_path;
|
||||||
db=nix/store/*-s6-rc-db/compiled/
|
db=nix/store/*-s6-rc-database/compiled/
|
||||||
test -d $db
|
test -d $db
|
||||||
chmod -R +w $db
|
chmod -R +w $db
|
||||||
# check we have closure of config.services (lo.link.service exists only
|
# check we have closure of config.services (lo.link.service exists only
|
||||||
|
@ -21,5 +21,4 @@ echo OK
|
||||||
EOF
|
EOF
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
nix-shell -p s6-rc -p squashfsTools --run "$TESTS" || exit 1
|
nix-shell -p s6-rc -p squashfsTools --run "$TESTS" || exit 1
|
||||||
|
|
Loading…
Reference in a new issue