From 4830f943b423dc59dda9deafdc936abb404bbd0e Mon Sep 17 00:00:00 2001 From: caem Date: Sun, 12 Jan 2025 02:57:46 +0100 Subject: [PATCH] Moar progress --- .gitignore | 1 + hosts/puter/default.nix | 4 +- hosts/puter/persist.nix | 5 -- hosts/vm/default.nix | 50 +++++++++++++ hosts/vm/disko.nix | 64 +++++++++++++++++ hosts/vm/packages.nix | 14 ++++ install.sh | 72 +++++++++++++++++++ modules/home/caem/default.nix | 1 + modules/nixos/core/fonts.nix | 6 +- modules/nixos/hardware/gpu/graphics.nix | 9 +++ modules/nixos/hardware/gpu/nvidia/default.nix | 9 ++- 11 files changed, 219 insertions(+), 16 deletions(-) delete mode 100644 hosts/puter/persist.nix create mode 100644 hosts/vm/default.nix create mode 100644 hosts/vm/disko.nix create mode 100644 hosts/vm/packages.nix create mode 100644 modules/nixos/hardware/gpu/graphics.nix diff --git a/.gitignore b/.gitignore index 43f7455..9998018 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ secrets/ dotfiles/zsh/.zcompdump dotfiles/nvim/lazy-lock.json +result diff --git a/hosts/puter/default.nix b/hosts/puter/default.nix index 872a6c8..692d94b 100644 --- a/hosts/puter/default.nix +++ b/hosts/puter/default.nix @@ -2,11 +2,12 @@ { imports = [ - ./persist.nix ./disko.nix ./packages.nix ]; + users.allowNoPasswordLogin = true; /* DEBUG */ + time.timeZone = "Europe/Berlin"; networking = { @@ -19,6 +20,7 @@ efi.canTouchEfiVariables = true; grub = { enable = true; + device = "/dev/nvme0"; # [managed by install.sh] { grub device } efiSupport = true; gfxmodeEfi = "1920x1080"; }; diff --git a/hosts/puter/persist.nix b/hosts/puter/persist.nix deleted file mode 100644 index d8147ea..0000000 --- a/hosts/puter/persist.nix +++ /dev/null @@ -1,5 +0,0 @@ -{ ... }: - -{ - -} diff --git a/hosts/vm/default.nix b/hosts/vm/default.nix new file mode 100644 index 0000000..f10bcc1 --- /dev/null +++ b/hosts/vm/default.nix @@ -0,0 +1,50 @@ +{ pkgs, lib, ... }: + +{ + imports = [ + ./disko.nix + ./packages.nix + ]; + + users.allowNoPasswordLogin = true; /* DEBUG */ + + time.timeZone = "Europe/Berlin"; + + networking = { + hostName = "vm"; + useDHCP = lib.mkDefault true; + }; + + boot = { + loader = { + grub = { + enable = true; + device = "/dev/nvme0n1"; # [managed by install.sh] { grub device } + gfxmodeEfi = "1920x1080"; + }; + }; + + tmp.useTmpfs = true; + kernelPackages = pkgs.linuxPackages_xanmod_latest; + supportedFilesystems = [ "btfs" "vfat" "xfs" ]; + initrd = { + availableKernelModules = [ "nvme" "xhci_pci" "ahci" + "usbhid" "usb_storage" "sd_mod" ]; + }; + }; + + services = { + fstrim.enable = true; + btrfs.autoScrub.enable = true; + }; + + fileSystems = { + # These are system specific. If you have any additional drives that are not + # your root device you can add and mount them here. Added nofail so that you can + # install this configuration on a device without it exploding when you don't have + # these specific partitions. + }; + + system.stateVersion = "24.11"; # [managed by install.sh] { state version } +} + diff --git a/hosts/vm/disko.nix b/hosts/vm/disko.nix new file mode 100644 index 0000000..2b42347 --- /dev/null +++ b/hosts/vm/disko.nix @@ -0,0 +1,64 @@ +{ ... }: + +{ + disko.devices = { + disk = { + master = { + type = "disk"; + device = ""; # [managed by install.sh] { device } + content = { + type = "gpt"; + partitions = { + ESP = { + priority = 1; + name = "efi"; + start = "1M"; + end = "1024M"; + type = "EF00"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + mountOptions = [ + "umask=0077" + "noatime" + ]; + }; + }; + root = { + size = "100%"; + content = { + type = "btrfs"; + extraArgs = [ "-f" "-L nixos" ]; + postCreateHook = '' + TMP_MNT=$(mktemp -d) + MNT_PART="" # [managed by install.sh] { root partition } + mount "$MNT_PART" "$TMP_MNT" -o subvol=/ + trap 'umount "$TMP_MNT"; rm -rf "$TMP_MNT"' EXIT + btrfs subvolume snapshot "$TMP_MNT/root" "$TMP_MNT/blank" + ''; + subvolumes = { + "/root" = { + mountpoint = "/"; + mountOptions = [ + "noatime" + "compress=zstd" + ]; + }; + + "/nix" = { + mountpoint = "/nix"; + mountOptions = [ + "noatime" + "compress=zstd" + ]; + }; + }; + }; + }; + }; + }; + }; + }; + }; +} diff --git a/hosts/vm/packages.nix b/hosts/vm/packages.nix new file mode 100644 index 0000000..c83d3ca --- /dev/null +++ b/hosts/vm/packages.nix @@ -0,0 +1,14 @@ +{ ... }: + +{ + imports = let + modules = ../../modules/nixos; + in [ + "${modules}/core" + "${modules}/hardware/audio" + "${modules}/hardware/gpu/graphics.nix" + "${modules}/multimedia" + "${modules}/desktop/gnome" + ]; +} + diff --git a/install.sh b/install.sh index d0fe41b..b6a1907 100755 --- a/install.sh +++ b/install.sh @@ -6,3 +6,75 @@ # # This script aims to automate the deployment of my configuration # on a new machine. + +args_ensure_extra_arg() { + if [ -z "$2" ] || [ "$(echo "$2" | cut -c 1-1)" = "-" ]; then + >&2 echo "Argument '$1' requires an extra argument. Run --help for more info." + exit 1 + fi +} + +args_ensure_is_set() { + if [ -z "$2" ]; then + >&2 echo "Argument '$1' is required to be set. Please consult the README or run again with --help." + fi +} + +args() { + while [ -n "$1" ]; do + case "$1" in + "-h" | "--help") + echo "" + echo "$0 - Installation script for my NixOS configuration" + echo "" + echo "arguments:" + echo " -h|--help Print this and exit" + echo " -d|--device [device] (required) The device you want to install NixOS on to" + echo " -o|--host [hostname] (required) The host from ./hosts you want to install" + echo "" + echo "origin: https://github.com/c4em/dotnix" + echo "" + exit 0 + ;; + + "-d" | "--device") + args_ensure_extra_arg "$@" + if [ ! -b "$2" ]; then + >&2 echo "'$2' is not a valid block device. Make sure you selected the right drive" + exit 1 + fi + + DOTNIX_INSTALL_DEVICE="$2" + shift 2 + ;; + + "-o" | "--host") + args_ensure_extra_arg "$@" + + if [ ! -f "./hosts/$2" ]; then + >&2 echo "Invalid hostname '$2'. Make sure it exists in ./hosts" + exit 1 + fi + + DOTNIX_HOSTNAME="$2" + shift 2 + ;; + + *) + >&2 echo "Unrecognized argument '$1'. Run with --help to view accepted arguments." + exit 1 + ;; + esac + done + + args_ensure_is_set "--device" "$DOTNIX_INSTALL_DEVICE" + args_ensure_is_set "--host" "$DOTNIX_HOSTNAME" +} + +main () { + args "$@" +} + +set -e +main "$@" + diff --git a/modules/home/caem/default.nix b/modules/home/caem/default.nix index 626b4d7..b461d20 100644 --- a/modules/home/caem/default.nix +++ b/modules/home/caem/default.nix @@ -30,6 +30,7 @@ }; home.persistence."/nix/persist/home/caem" = { + allowOther = true; directories = [ "documents" "download" diff --git a/modules/nixos/core/fonts.nix b/modules/nixos/core/fonts.nix index 725fc4a..b2020bf 100644 --- a/modules/nixos/core/fonts.nix +++ b/modules/nixos/core/fonts.nix @@ -3,11 +3,7 @@ { fonts = { packages = with pkgs; [ - (nerdfonts.override { - fonts = [ - "GoMono" - ]; - }) + nerdfonts ipafont noto-fonts-emoji cantarell-fonts diff --git a/modules/nixos/hardware/gpu/graphics.nix b/modules/nixos/hardware/gpu/graphics.nix new file mode 100644 index 0000000..87d60ec --- /dev/null +++ b/modules/nixos/hardware/gpu/graphics.nix @@ -0,0 +1,9 @@ +{ ... }: +{ + hardware = { + graphics = { + enable = true; + enable32Bit = true; + }; + }; +} diff --git a/modules/nixos/hardware/gpu/nvidia/default.nix b/modules/nixos/hardware/gpu/nvidia/default.nix index a3cc450..4269d62 100644 --- a/modules/nixos/hardware/gpu/nvidia/default.nix +++ b/modules/nixos/hardware/gpu/nvidia/default.nix @@ -1,12 +1,11 @@ { config, ... }: { - hardware = { - graphics = { - enable = true; - enable32Bit = true; - }; + imports = [ + ../graphics.nix + ]; + hardware = { nvidia = { open = true; modesetting.enable = true;