liminix

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

initramfs.nix (1304B)


      1 {
      2   config,
      3   pkgs,
      4   lib,
      5   ...
      6 }:
      7 let
      8   inherit (lib)
      9     mkEnableOption
     10     mkOption
     11     mkIf
     12     types
     13     ;
     14   inherit (pkgs) runCommand;
     15 in
     16 {
     17   imports = [ ./system-configuration.nix ];
     18   options = {
     19     boot.initramfs = {
     20       enable = mkEnableOption "initramfs";
     21     };
     22     system.outputs = {
     23       initramfs = mkOption {
     24         type = types.package;
     25         internal = true;
     26         description = ''
     27           Initramfs image capable of mounting the real root
     28           filesystem
     29         '';
     30       };
     31     };
     32   };
     33   config = mkIf config.boot.initramfs.enable {
     34     kernel.config = {
     35       BLK_DEV_INITRD = "y";
     36       INITRAMFS_SOURCE = builtins.toJSON "${config.system.outputs.initramfs}";
     37       #      INITRAMFS_COMPRESSION_LZO = "y";
     38     };
     39 
     40     system.outputs = {
     41       initramfs =
     42         let
     43           inherit (pkgs.pkgsBuildBuild) gen_init_cpio;
     44         in
     45         runCommand "initramfs.cpio" { } ''
     46           cat << SPECIALS | ${gen_init_cpio}/bin/gen_init_cpio /dev/stdin > $out
     47           dir /proc 0755 0 0
     48           dir /dev 0755 0 0
     49           nod /dev/console 0600 0 0 c 5 1
     50           dir /target 0755 0 0
     51           dir /target/persist 0755 0 0
     52           dir /target/nix 0755 0 0
     53           file /init ${pkgs.preinit}/bin/preinit 0755 0 0
     54           SPECIALS
     55         '';
     56     };
     57   };
     58 }