liminix

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

outputs.nix (3856B)


      1 {
      2   config
      3 , pkgs
      4 , lib
      5 , ...
      6 }:
      7 let
      8   inherit (lib) mkOption types concatStringsSep;
      9   inherit (pkgs) liminix callPackage writeText;
     10   o = config.system.outputs;
     11 in
     12 {
     13   imports = [
     14     ./squashfs.nix
     15     ./outputs/vmroot.nix
     16     ./outputs/extlinux.nix
     17   ];
     18   options = {
     19     system.outputs = {
     20       # the convention here is to mark an output as "internal" if
     21       # it's not a complete system (kernel plus userland, or installer)
     22       # but only part of one.
     23       kernel = mkOption {
     24         type = types.package;
     25         internal  = true;
     26         description = ''
     27           kernel
     28           ******
     29 
     30           Kernel vmlinux file (usually ELF)
     31         '';
     32       };
     33       zimage = mkOption {
     34         type = types.package;
     35         internal = true;
     36         description = ''
     37           zimage
     38           ******
     39 
     40           Kernel in compressed self-extracting package
     41         '';
     42       };
     43       dtb = mkOption {
     44         type = types.package;
     45         internal  = true;
     46         description = ''
     47           dtb
     48           ***
     49 
     50           Compiled device tree (FDT) for the target device
     51         '';
     52       };
     53       uimage = mkOption {
     54         type = types.package;
     55         internal  = true;
     56         description = ''
     57           uimage
     58           ******
     59 
     60           Combined kernel and FDT in uImage (U-Boot compatible) format
     61         '';
     62       };
     63       u-boot = mkOption {
     64         type = types.package;
     65       };
     66       manifest = mkOption {
     67         type = types.package;
     68         internal  = true;
     69         description = ''
     70           Debugging aid. JSON rendition of config.filesystem, on
     71           which can run "nix-store -q --tree" on it and find
     72           out what's in the image, which is nice if it's unexpectedly huge
     73         '';
     74       };
     75       rootdir = mkOption {
     76         type = types.package;
     77         internal = true;
     78         description = ''
     79           directory of files to package into root filesystem
     80         '';
     81       };
     82       bootablerootdir = mkOption {
     83         type = types.package;
     84         internal = true;
     85         description = ''
     86           directory of files to package into root filesystem, including
     87           a kernel and appropriate associated gubbins for the
     88           selected bootloader
     89         '';
     90       };
     91       rootfs = mkOption {
     92         type = types.package;
     93         internal = true;
     94         description = ''
     95           root filesystem (squashfs or jffs2) image
     96         '';
     97       };
     98     };
     99   };
    100   config = {
    101     system.outputs = rec {
    102       dtb = liminix.builders.dtb {
    103         inherit (config.boot) commandLine;
    104         dts = config.hardware.dts.src;
    105         includes = config.hardware.dts.includes ++ [
    106           "${o.kernel.headers}/include"
    107         ];
    108       };
    109       uimage = liminix.builders.uimage {
    110         commandLine = concatStringsSep " " config.boot.commandLine;
    111         inherit (config.hardware) loadAddress entryPoint;
    112         inherit (config.boot) imageFormat;
    113         inherit (o) kernel dtb;
    114       };
    115       rootdir =
    116         let
    117           inherit (pkgs.pkgsBuildBuild) runCommand;
    118         in runCommand "mktree" { } ''
    119           mkdir -p $out/nix/store/ $out/secrets $out/boot
    120           cp ${o.systemConfiguration}/bin/activate $out/activate
    121           ln -s ${pkgs.s6-init-bin}/bin/init $out/init
    122           mkdir -p $out/nix/store
    123           for path in $(cat ${o.systemConfiguration}/etc/nix-store-paths) ; do
    124             (cd $out && cp -a $path .$path)
    125           done
    126         '';
    127       bootablerootdir =
    128         let inherit (pkgs.pkgsBuildBuild) runCommand;
    129         in runCommand "add-slash-boot" { } ''
    130           cp -a ${o.rootdir} $out
    131           ${if config.boot.loader.extlinux.enable
    132             then "(cd $out && chmod -R +w . && rmdir boot && cp -a ${o.extlinux} boot)"
    133             else ""
    134            }
    135          '';
    136       manifest = writeText "manifest.json" (builtins.toJSON config.filesystem.contents);
    137     };
    138   };
    139 }