liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

ext4fs.nix (850B)


      1 {
      2   config
      3 , pkgs
      4 , lib
      5 , ...
      6 }:
      7 let
      8   inherit (lib) mkIf mkOption types;
      9   o = config.system.outputs;
     10 in
     11 {
     12   imports = [
     13     ./initramfs.nix
     14   ];
     15   config = mkIf (config.rootfsType == "ext4") {
     16     kernel.config = {
     17       EXT4_FS = "y";
     18       EXT4_USE_FOR_EXT2 = "y";
     19       FS_ENCRYPTION = "y";
     20     };
     21     boot.initramfs.enable = true;
     22     system.outputs = {
     23       rootfs =
     24         let
     25           inherit (pkgs.pkgsBuildBuild) runCommand e2fsprogs;
     26         in runCommand "mkfs.ext4" {
     27           depsBuildBuild = [ e2fsprogs ];
     28         } ''
     29           tree=${o.bootablerootdir}
     30           size=$(du -s --apparent-size --block-size 1024 $tree |cut -f1)
     31           # add 25% for filesystem overhead
     32           size=$(( 5 * $size / 4))
     33           dd if=/dev/zero of=$out bs=1024 count=$size
     34           mke2fs -t ext4 -j -d $tree $out
     35         '';
     36     };
     37   };
     38 }