liminix

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

recovery.nix (3173B)


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