2023-11-06 22:52:31 +01:00
|
|
|
{
|
|
|
|
config
|
|
|
|
, pkgs
|
|
|
|
, lib
|
|
|
|
, ...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
inherit (lib) mkIf mkOption types;
|
2023-12-05 18:29:01 +01:00
|
|
|
o = config.system.outputs;
|
2023-11-06 22:52:31 +01:00
|
|
|
in
|
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
./initramfs.nix
|
|
|
|
];
|
|
|
|
config = mkIf (config.rootfsType == "ext4") {
|
|
|
|
kernel.config = {
|
|
|
|
EXT4_FS = "y";
|
|
|
|
EXT4_USE_FOR_EXT2 = "y";
|
|
|
|
FS_ENCRYPTION = "y";
|
|
|
|
};
|
|
|
|
boot.initramfs.enable = true;
|
2023-12-05 18:29:01 +01:00
|
|
|
system.outputs = {
|
2023-11-06 22:52:31 +01:00
|
|
|
systemConfiguration =
|
|
|
|
pkgs.systemconfig config.filesystem.contents;
|
|
|
|
rootfs =
|
|
|
|
let
|
|
|
|
inherit (pkgs.pkgsBuildBuild) runCommand e2fsprogs;
|
|
|
|
in runCommand "mkfs.ext4" {
|
|
|
|
depsBuildBuild = [ e2fsprogs ];
|
|
|
|
} ''
|
2023-12-05 18:29:01 +01:00
|
|
|
cp -a ${o.rootfsFiles} tmp
|
|
|
|
${if config.boot.loader.extlinux.enable
|
2023-12-06 00:16:53 +01:00
|
|
|
then "(cd tmp && chmod -R +w . && rmdir boot && cp -a ${o.extlinux} boot)"
|
2023-12-05 18:29:01 +01:00
|
|
|
else ""
|
|
|
|
}
|
|
|
|
size=$(du -s --apparent-size --block-size 1024 tmp |cut -f1)
|
2023-11-06 22:52:31 +01:00
|
|
|
# add 25% for filesystem overhead
|
|
|
|
size=$(( 5 * $size / 4))
|
|
|
|
dd if=/dev/zero of=$out bs=1024 count=$size
|
2023-12-05 18:29:01 +01:00
|
|
|
mke2fs -t ext4 -j -d tmp $out
|
2023-11-06 22:52:31 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|