ZFS: Difference between revisions

imported>Aidalgol
Rewrite section on installing on ZFS root
imported>Dotlambda
m fix indentation
Line 410: Line 410:


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
boot = {
boot = {
  initrd.network = {
  initrd.network = {
    # This will use udhcp to get an ip address.
    # This will use udhcp to get an ip address.
    # Make sure you have added the kernel module for your network driver to `boot.initrd.availableKernelModules`,  
    # Make sure you have added the kernel module for your network driver to `boot.initrd.availableKernelModules`,  
    # so your initrd can load it!
    # so your initrd can load it!
    # Static ip addresses might be configured using the ip argument in kernel command line:
    # Static ip addresses might be configured using the ip argument in kernel command line:
    # https://www.kernel.org/doc/Documentation/filesystems/nfs/nfsroot.txt
    # https://www.kernel.org/doc/Documentation/filesystems/nfs/nfsroot.txt
    enable = true;
    enable = true;
    ssh = {
    ssh = {
        enable = true;
      enable = true;
        # To prevent ssh clients from freaking out because a different host key is used,
      # To prevent ssh clients from freaking out because a different host key is used,
        # a different port for ssh is useful (assuming the same host has also a regular sshd running)
      # a different port for ssh is useful (assuming the same host has also a regular sshd running)
        port = 2222;  
      port = 2222;  
        # hostKeys paths must be unquoted strings, otherwise you'll run into issues with boot.initrd.secrets
      # hostKeys paths must be unquoted strings, otherwise you'll run into issues with boot.initrd.secrets
        # the keys are copied to initrd from the path specified; multiple keys can be set
      # the keys are copied to initrd from the path specified; multiple keys can be set
        # you can generate any number of host keys using  
      # you can generate any number of host keys using  
        # `ssh-keygen -t ed25519 -N "" -f /path/to/ssh_host_ed25519_key`
      # `ssh-keygen -t ed25519 -N "" -f /path/to/ssh_host_ed25519_key`
        hostKeys = [ /path/to/ssh_host_rsa_key ];
      hostKeys = [ /path/to/ssh_host_rsa_key ];
        # public ssh key used for login
      # public ssh key used for login
        authorizedKeys = [ "ssh-rsa AAAA..." ];
      authorizedKeys = [ "ssh-rsa AAAA..." ];
    };
    };
    # this will automatically load the zfs password prompt on login
    # this will automatically load the zfs password prompt on login
    # and kill the other prompt so boot can continue
    # and kill the other prompt so boot can continue
    postCommands = ''
    postCommands = ''
      cat <<EOF > /root/.profile  
      cat <<EOF > /root/.profile  
      if pgrep -x "zfs" > /dev/null  
      if pgrep -x "zfs" > /dev/null  
      then  
      then  
        zfs load-key -a  
        zfs load-key -a  
        killall zfs  
        killall zfs  
      else  
      else  
        echo "zfs not running -- maybe the pool is taking some time to load for some unforseen reason."  
        echo "zfs not running -- maybe the pool is taking some time to load for some unforseen reason."  
      fi  
      fi  
      EOF  
      EOF  
    '';
    '';
  };
  };
};
};
</syntaxHighlight>
</syntaxHighlight>