outputs.nix (3932B)
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 tplink-safeloader = mkOption { 64 type = types.package; 65 }; 66 u-boot = mkOption { 67 type = types.package; 68 }; 69 manifest = mkOption { 70 type = types.package; 71 internal = true; 72 description = '' 73 Debugging aid. JSON rendition of config.filesystem, on 74 which can run "nix-store -q --tree" on it and find 75 out what's in the image, which is nice if it's unexpectedly huge 76 ''; 77 }; 78 rootdir = mkOption { 79 type = types.package; 80 internal = true; 81 description = '' 82 directory of files to package into root filesystem 83 ''; 84 }; 85 bootablerootdir = mkOption { 86 type = types.package; 87 internal = true; 88 description = '' 89 directory of files to package into root filesystem, including 90 a kernel and appropriate associated gubbins for the 91 selected bootloader 92 ''; 93 }; 94 rootfs = mkOption { 95 type = types.package; 96 internal = true; 97 description = '' 98 root filesystem (squashfs or jffs2) image 99 ''; 100 }; 101 }; 102 }; 103 config = { 104 system.outputs = rec { 105 dtb = liminix.builders.dtb { 106 inherit (config.boot) commandLine; 107 dts = config.hardware.dts.src; 108 includes = config.hardware.dts.includes ++ [ 109 "${o.kernel.headers}/include" 110 ]; 111 }; 112 uimage = liminix.builders.uimage { 113 commandLine = concatStringsSep " " config.boot.commandLine; 114 inherit (config.hardware) loadAddress entryPoint; 115 inherit (config.boot) imageFormat; 116 inherit (o) kernel dtb; 117 }; 118 rootdir = 119 let 120 inherit (pkgs.pkgsBuildBuild) runCommand; 121 in runCommand "mktree" { } '' 122 mkdir -p $out/nix/store/ $out/secrets $out/boot 123 cp ${o.systemConfiguration}/bin/activate $out/activate 124 ln -s ${pkgs.s6-init-bin}/bin/init $out/init 125 mkdir -p $out/nix/store 126 for path in $(cat ${o.systemConfiguration}/etc/nix-store-paths) ; do 127 (cd $out && cp -a $path .$path) 128 done 129 ''; 130 bootablerootdir = 131 let inherit (pkgs.pkgsBuildBuild) runCommand; 132 in runCommand "add-slash-boot" { } '' 133 cp -a ${o.rootdir} $out 134 ${if config.boot.loader.extlinux.enable 135 then "(cd $out && chmod -R +w . && rmdir boot && cp -a ${o.extlinux} boot)" 136 else "" 137 } 138 ''; 139 manifest = writeText "manifest.json" (builtins.toJSON config.filesystem.contents); 140 }; 141 }; 142 }