Advertisement
Guest User

Untitled

a guest
May 5th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. #
  3. # Installs nixos with full disk encrypted root partition.
  4. #
  5. # - Prompts for password initially, after that no interaction should
  6. # be required.
  7. # - At the end it will prompt for a root password, could not make
  8. # echo-ing it into nixos-install work.
  9. # - Reserves 550MB for boot partition, rest for the root volume.
  10. # - After booting, log in as root user and set password for normal user.
  11. # - Removed LVM on Luks due to terrible (only 20%) write performance (???)
  12. #
  13. # USAGE:
  14. # 1. Fill in variables on top.
  15. # 2. $bash install.sh
  16. #
  17. set -euo pipefail
  18.  
  19. DISK="/dev/sda"
  20. BOOT="/dev/sda1"
  21. ROOT="/dev/sda2"
  22. NIXOS_USER=""
  23. HOSTNAME=""
  24. NIXOS_VERSION="19.03"
  25. CONSOLE_KEYMAP="us" # the default
  26. XKB_VARIANT="" # the default
  27. CRYPT_VOLUME="/dev/mapper/crypted-nixos"
  28.  
  29. ########################################################
  30. # No need to edit anything below for normal usage. #
  31. ########################################################
  32.  
  33. read -s -p "DISK Password: " PASSWORD
  34. echo
  35. read -s -p "Confirm: " CONFIRMATION
  36. echo
  37. if [ ! "$PASSWORD" = "$CONFIRMATION" ]; then
  38. echo "Didn't match. Try again."
  39. exit 1
  40. fi
  41.  
  42. echo "Creating partition table."
  43. (echo o # new table
  44. echo Y # yes
  45. echo n # new part
  46. echo # number 1
  47. echo # start
  48. echo '+550M' # end
  49. echo 'ef00' # EFI
  50. echo n # new part
  51. echo # number 2
  52. echo # start
  53. echo # end
  54. echo # linux
  55. echo w # write
  56. echo Y # yes
  57. ) | gdisk $DISK
  58.  
  59. echo "Setting up LUKS."
  60. echo $PASSWORD | cryptsetup luksFormat $ROOT
  61. echo "Opening crypt volume."
  62. echo $PASSWORD | cryptsetup luksOpen $ROOT crypted-nixos
  63.  
  64. echo "Formatting partitions."
  65. mkfs.fat -F 32 $BOOT
  66. mkfs.ext4 -L root $CRYPT_VOLUME
  67.  
  68. echo "Mounting partitions."
  69. mount $CRYPT_VOLUME /mnt
  70. mkdir -p /mnt/boot
  71. mount $BOOT /mnt/boot
  72.  
  73. nixos-generate-config --root /mnt
  74.  
  75. cat > /mnt/etc/nixos/configuration.nix <<EOF
  76. { config, pkgs, ... }:
  77.  
  78. {
  79.  
  80. imports = [ ./hardware-configuration.nix ];
  81.  
  82. boot.loader.systemd-boot.enable = true;
  83. boot.loader.efi.canTouchEfiVariables = true;
  84.  
  85. networking.hostName = "$HOSTNAME";
  86. networking.networkmanager.enable = true;
  87.  
  88. virtualisation.docker.enable = true;
  89.  
  90. services.openssh.enable = true;
  91.  
  92. services.haveged.enable = true;
  93.  
  94. services.avahi.enable = true;
  95. services.avahi.nssmdns = true;
  96. services.avahi.publish.enable = true;
  97. services.avahi.publish.addresses = true;
  98.  
  99. services.xserver.enable = true;
  100. services.xserver.displayManager.sddm.enable = true;
  101. services.xserver.desktopManager.plasma5.enable = true;
  102. services.xserver.libinput.enable = true;
  103.  
  104. i18n = {
  105. consoleKeyMap = "$CONSOLE_KEYMAP";
  106. defaultLocale = "en_US.UTF-8";
  107. };
  108.  
  109. nixpkgs.config = {
  110. allowUnfree = true;
  111. };
  112.  
  113. nix.autoOptimiseStore = true;
  114. nix.useSandbox = true;
  115.  
  116. security.pam.loginLimits = [
  117. { domain = "*"; type = "soft"; item = "nofile"; value = "65536"; }
  118. { domain = "*"; type = "hard"; item = "nofile"; value = "200000"; }
  119. { domain = "*"; type = "-"; item = "nproc"; value = "20000"; }
  120. ];
  121.  
  122. time.timeZone = "Asia/Hong_Kong";
  123.  
  124. environment.systemPackages = with pkgs; [
  125. git
  126. wget vim gzip
  127. firefox
  128. gnupg
  129. gparted
  130. ];
  131.  
  132. # Some programs need SUID wrappers, can be configured further or are
  133. # started in user sessions.
  134. programs.bash.enableCompletion = true;
  135. programs.gnupg.agent = { enable = true; enableSSHSupport = true; };
  136. programs.fish.enable = true;
  137.  
  138. # Define a user account. Don't forget to set a password with ‘passwd’.
  139. users.extraUsers.$NIXOS_USER = {
  140. isNormalUser = true;
  141. uid = 1000;
  142. shell = pkgs.fish;
  143. extraGroups = [ "wheel" "networkmanager" "docker" ];
  144. };
  145.  
  146. system.stateVersion = "$NIXOS_VERSION"; # Did you read the comment?
  147. }
  148. EOF
  149.  
  150. nixos-install
  151.  
  152. echo "Reboot now, good luck!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement