liminix

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

initramfs.nix (1564B)


      1 {
      2   config
      3 , pkgs
      4 , lib
      5 , ...
      6 }:
      7 let
      8   inherit (lib) mkEnableOption mkOption mkIf types;
      9   inherit (pkgs) runCommand callPackage writeText;
     10 in
     11 {
     12   options = {
     13     boot.initramfs = {
     14       enable = mkEnableOption "initramfs";
     15     };
     16     system.outputs = {
     17       initramfs = mkOption {
     18         type = types.package;
     19         internal = true;
     20         description = ''
     21           Initramfs image capable of mounting the real root
     22           filesystem
     23         '';
     24       };
     25       systemConfiguration = mkOption {
     26         type = types.package;
     27         description = ''
     28           pkgs.systemconfig for the configured filesystem,
     29           contains 'activate' and 'init' commands
     30         '';
     31         internal = true;
     32       };
     33     };
     34   };
     35   config = mkIf config.boot.initramfs.enable {
     36     kernel.config = {
     37       BLK_DEV_INITRD = "y";
     38       INITRAMFS_SOURCE = builtins.toJSON "${config.system.outputs.initramfs}";
     39 #      INITRAMFS_COMPRESSION_LZO = "y";
     40     };
     41 
     42     system.outputs = {
     43       initramfs =
     44         let inherit (pkgs.pkgsBuildBuild) gen_init_cpio;
     45         in 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       systemConfiguration =
     57         pkgs.systemconfig config.filesystem.contents;
     58     };
     59   };
     60 }