base.nix (4987B)
1 { lib, pkgs, config, ...}: 2 let 3 inherit (lib) mkEnableOption mkOption types isDerivation hasAttr ; 4 inherit (pkgs.pseudofile) dir symlink; 5 inherit (pkgs.liminix.networking) address interface; 6 inherit (pkgs.liminix.services) bundle; 7 8 type_service = pkgs.liminix.lib.types.service; 9 10 in { 11 options = { 12 # analogous to nixos systemPackages, but we don't symlink into 13 # /run/current-system, we just add the paths in /etc/profile 14 defaultProfile = { 15 packages = mkOption { 16 type = types.listOf types.package; 17 }; 18 }; 19 services = mkOption { 20 type = types.attrsOf type_service; 21 }; 22 filesystem = mkOption { type = types.anything; }; 23 rootfsType = mkOption { 24 default = "squashfs"; 25 type = types.str; 26 }; 27 kernel = { 28 src = mkOption { type = types.package; } ; 29 modular = mkOption { 30 type = types.bool; 31 default = true; 32 description = "support loadable kernel modules"; 33 }; 34 extraPatchPhase = mkOption { 35 default = "true"; 36 type = types.lines; 37 } ; 38 config = mkOption { 39 # mostly the values are y n or m, but sometimes 40 # other strings are also used 41 type = types.attrsOf types.nonEmptyStr; 42 }; 43 }; 44 boot = { 45 commandLine = mkOption { 46 type = types.listOf types.nonEmptyStr; 47 default = []; 48 }; 49 tftp = { 50 loadAddress = mkOption { type = types.str; }; 51 # These names match the uboot environment variables. I reserve 52 # the right to change them if I think of better ones. 53 ipaddr = mkOption { type = types.str; }; 54 serverip = mkOption { type = types.str; }; 55 }; 56 }; 57 }; 58 config = { 59 defaultProfile.packages = with pkgs; 60 [ s6 s6-init-bin execline s6-linux-init s6-rc ]; 61 62 hardware.networkInterfaces = { 63 lo = 64 let iface = interface { type = "loopback"; device = "lo";}; 65 in bundle { 66 name = "loopback"; 67 contents = [ 68 (address iface { family = "inet4"; address ="127.0.0.1"; prefixLength = 8;}) 69 (address iface { family = "inet6"; address ="::1"; prefixLength = 128;}) 70 ]; 71 }; 72 }; 73 74 kernel = rec { 75 modular = true; # disabling this is not yet supported 76 config = { 77 IKCONFIG = "y"; 78 IKCONFIG_PROC = "y"; 79 PROC_FS = "y"; 80 81 KEXEC = "y"; 82 MODULES = if modular then "y" else "n"; 83 MODULE_SIG = if modular then "y" else "n"; 84 DEBUG_FS = "y"; 85 86 MIPS_BOOTLOADER_CMDLINE_REQUIRE_COOKIE = "y"; 87 MIPS_BOOTLOADER_CMDLINE_COOKIE = "\"liminix\""; 88 MIPS_CMDLINE_DTB_EXTEND = "y"; 89 90 # basic networking protocols 91 NET = "y"; 92 UNIX = "y"; 93 INET = "y"; 94 IPV6 = "y"; 95 PACKET = "y"; # for ppp, tcpdump ... 96 SYSVIPC= "y"; 97 98 # disabling this option causes the kernel to use an "empty" 99 # initramfs instead: it has a /dev/console node and not much 100 # else. Note that pid 1 is started *before* the root 101 # filesystem is mounted and it expects /dev/console to be 102 # present already 103 BLK_DEV_INITRD = lib.mkDefault "n"; # overriden by initramfs module 104 105 # s6-linux-init mounts this on /dev 106 DEVTMPFS = "y"; 107 # some or all of these may be fix for "tmpfs: Unknown parameter 'mode'" error 108 TMPFS = "y"; 109 TMPFS_POSIX_ACL = "y"; 110 TMPFS_XATTR = "y"; 111 112 FW_LOADER = "y"; 113 FW_LOADER_COMPRESS = "y"; 114 # We don't have a user helper, so we get multiple 60s pauses 115 # at boot time unless we disable trying to call it. 116 # https://lkml.org/lkml/2013/8/5/175 117 FW_LOADER_USER_HELPER = "n"; 118 }; 119 }; 120 boot.commandLine = [ 121 "console=ttyS0,115200 panic=10 oops=panic init=/bin/init loglevel=8" 122 "root=${config.hardware.rootDevice}" 123 "rootfstype=${config.rootfsType}" 124 "fw_devlink=off" 125 ]; 126 users.root = { 127 uid = 0; gid= 0; gecos = "Root of all evaluation"; 128 dir = "/home/root/"; 129 passwd = lib.mkDefault ""; 130 shell = "/bin/sh"; 131 }; 132 groups = { 133 root = { 134 gid = 0; usernames = ["root"]; 135 }; 136 system = { 137 gid = 1; usernames = ["root"]; 138 }; 139 }; 140 141 filesystem = dir { 142 dev = 143 let node = type: major: minor: mode : { inherit type major minor mode; }; 144 in dir { 145 null = node "c" "1" "3" "0666"; 146 zero = node "c" "1" "5" "0666"; 147 tty = node "c" "5" "0" "0666"; 148 console = node "c" "5" "1" "0600"; 149 pts = dir {}; 150 }; 151 etc = let 152 profile = symlink 153 (pkgs.writeScript ".profile" '' 154 PATH=${lib.makeBinPath config.defaultProfile.packages}:/bin 155 export PATH 156 ''); 157 in dir { 158 inherit profile; 159 ashrc = profile; 160 }; 161 162 proc = dir {}; 163 run = dir {}; 164 sys = dir {}; 165 }; 166 }; 167 }