recovery.nix (3108B)
1 { 2 config, 3 pkgs, 4 lib, 5 ... 6 }: 7 let 8 inherit (pkgs) serviceFns; 9 svc = config.system.service; 10 inherit (pkgs.pseudofile) dir symlink; 11 inherit (pkgs.liminix.services) oneshot target; 12 some-util-linux = pkgs.runCommand "some-util-linux" { } '' 13 mkdir -p $out/bin 14 cd ${pkgs.util-linux-small}/bin 15 cp fdisk sfdisk mkswap $out/bin 16 ''; 17 in 18 rec { 19 imports = [ 20 ../modules/network 21 ../modules/ssh 22 ../modules/usb.nix 23 ../modules/schnapps 24 ../modules/outputs/mtdimage.nix 25 ../modules/outputs/mbrimage.nix 26 ../modules/outputs/tftpboot.nix 27 ../modules/outputs/ubifs.nix 28 ../modules/outputs/ubimage.nix 29 ../modules/outputs/jffs2.nix 30 ../modules/outputs/ext4fs.nix 31 ]; 32 33 kernel.config = { 34 BTRFS_FS = "y"; 35 }; 36 37 boot.tftp = { 38 ipaddr = "10.0.0.8"; # my address 39 serverip = "10.0.0.1"; # build machine or other tftp server 40 freeSpaceBytes = 1024 * 1024 * 4; 41 }; 42 boot.loader.extlinux.enable = true; 43 44 hostname = "liminix-recovery"; 45 46 services.dhcpc = svc.network.dhcp.client.build { 47 interface = config.hardware.networkInterfaces.lan2; 48 49 # don't start DHCP until the hostname is configured, 50 # so it can identify itself to the DHCP server 51 dependencies = [ config.services.hostname ]; 52 }; 53 54 services.sshd = svc.ssh.build { 55 dependencies = [ config.services.growfs ]; 56 }; 57 58 services.defaultroute4 = svc.network.route.build { 59 via = "$(output ${services.dhcpc} router)"; 60 target = "default"; 61 dependencies = [ services.dhcpc ]; 62 }; 63 64 services.resolvconf = oneshot rec { 65 dependencies = [ services.dhcpc ]; 66 name = "resolvconf"; 67 up = '' 68 ( in_outputs ${name} 69 for i in $(output ${services.dhcpc} dns); do 70 echo "nameserver $i" > resolv.conf 71 done 72 ) 73 ''; 74 }; 75 76 services.growfs = 77 let 78 name = "growfs"; 79 in 80 oneshot { 81 inherit name; 82 up = '' 83 device=$(grep /persist /proc/1/mountinfo | cut -f9 -d' ') 84 ${pkgs.e2fsprogs}/bin/resize2fs $device 85 ''; 86 }; 87 88 filesystem = dir { 89 etc = dir { 90 "resolv.conf" = symlink "${services.resolvconf}/.outputs/resolv.conf"; 91 }; 92 mnt = dir { }; 93 }; 94 rootfsType = "ext4"; 95 96 # sda is most likely correct for the boot-from-USB case. For tftp 97 # it's overridden by the boot.scr anyway, so maybe it all works out 98 hardware.rootDevice = lib.mkForce "/dev/sda1"; 99 100 users.root = { 101 # the password is "secret". Use mkpasswd -m sha512crypt to 102 # create this hashed password string 103 passwd = "$6$y7WZ5hM6l5nriLmo$5AJlmzQZ6WA.7uBC7S8L4o19ESR28Dg25v64/vDvvCN01Ms9QoHeGByj8lGlJ4/b.dbwR9Hq2KXurSnLigt1W1"; 104 105 openssh.authorizedKeys.keys = 106 let 107 fromBuild = ( 108 builtins.readFile ((builtins.toPath (builtins.getEnv "HOME")) + "/.ssh/authorized_keys") 109 ); 110 in 111 lib.splitString "\n" fromBuild; 112 }; 113 114 defaultProfile.packages = with pkgs; [ 115 e2fsprogs # ext4 116 btrfs-progs 117 mtdutils # mtd, jffs2, ubifs 118 dtc # you never know when you might need device tree stuff 119 some-util-linux 120 libubootenv # fw_{set,print}env 121 pciutils 122 ]; 123 }