liminix/make-image.nix

30 lines
846 B
Nix
Raw Normal View History

2022-09-26 17:19:14 +02:00
{
stdenv
, busybox
, buildPackages
, callPackage
, pseudofile
2022-09-26 17:19:14 +02:00
, runCommand
, writeText
} : config :
let
config-pseudofiles = pseudofile.write "config.etc"
(config.environment.contents);
storefs = callPackage <nixpkgs/nixos/lib/make-squashfs.nix> {
# add pseudofiles as packages to store so that the packages they
2022-09-26 16:59:21 +02:00
# depend on are also added
storeContents = [
config-pseudofiles
] ++ config.packages ;
};
in runCommand "frob-squashfs" {
2022-09-26 17:19:14 +02:00
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 -p "/ d 0755 0 0" -pf ${config-pseudofiles}
cp store.img $out
''