liminix

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

recovery.nix (3127B)


      1 {
      2   config,
      3   pkgs,
      4   lib,
      5   ...
      6 }:
      7 let
      8   svc = config.system.service;
      9   inherit (pkgs.pseudofile) dir symlink;
     10   inherit (pkgs.liminix.services) oneshot target;
     11   some-util-linux = pkgs.runCommand "some-util-linux" { } ''
     12     mkdir -p $out/bin
     13     cd ${pkgs.util-linux-small}/bin
     14     cp fdisk sfdisk mkswap $out/bin
     15   '';
     16 in
     17 rec {
     18   imports = [
     19     ../modules/network
     20     ../modules/ssh
     21     ../modules/usb.nix
     22     ../modules/schnapps
     23     ../modules/outputs/mtdimage.nix
     24     ../modules/outputs/mbrimage.nix
     25     ../modules/outputs/tftpboot.nix
     26     ../modules/outputs/ubifs.nix
     27     ../modules/outputs/ubimage.nix
     28     ../modules/outputs/jffs2.nix
     29     ../modules/outputs/ext4fs.nix
     30     ../modules/dhcp4c
     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.dhcp4c.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   rootOptions = lib.mkForce "";
     96 
     97   # sda is most likely correct for the boot-from-USB case. For tftp
     98   # it's overridden by the boot.scr anyway, so maybe it all works out
     99   hardware.rootDevice = lib.mkForce "/dev/sda1";
    100 
    101   users.root = {
    102     # the password is "secret". Use mkpasswd -m sha512crypt to
    103     # create this hashed password string
    104     passwd = "$6$y7WZ5hM6l5nriLmo$5AJlmzQZ6WA.7uBC7S8L4o19ESR28Dg25v64/vDvvCN01Ms9QoHeGByj8lGlJ4/b.dbwR9Hq2KXurSnLigt1W1";
    105 
    106     openssh.authorizedKeys.keys =
    107       let
    108         fromBuild = (
    109           builtins.readFile ((builtins.toPath (builtins.getEnv "HOME")) + "/.ssh/authorized_keys")
    110         );
    111       in
    112       lib.splitString "\n" fromBuild;
    113   };
    114 
    115   defaultProfile.packages = with pkgs; [
    116     e2fsprogs # ext4
    117     btrfs-progs
    118     mtdutils # mtd, jffs2, ubifs
    119     dtc # you never know when you might need device tree stuff
    120     some-util-linux
    121     libubootenv # fw_{set,print}env
    122     pciutils
    123   ];
    124 }