From acd2d93ad81ffad72c067e0cbf90bee809276951 Mon Sep 17 00:00:00 2001 From: Raghuram Subramani Date: Thu, 10 Oct 2024 10:03:42 +0530 Subject: (impermanence): Modularize config. --- flake.nix | 1 - machines/x/configuration.nix | 55 +++++++------------------------------------ modules/core/global.nix | 3 +++ modules/core/impermanence.nix | 45 +++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 48 deletions(-) create mode 100644 modules/core/impermanence.nix diff --git a/flake.nix b/flake.nix index ab858e1..13d3f81 100644 --- a/flake.nix +++ b/flake.nix @@ -32,7 +32,6 @@ specialArgs = { inherit inputs; }; modules = [ inputs.disko.nixosModules.default - (import ./disko.nix { device = "/dev/nvme0n1"; }) ./machines/x/configuration.nix diff --git a/machines/x/configuration.nix b/machines/x/configuration.nix index 64da9ac..19305a1 100644 --- a/machines/x/configuration.nix +++ b/machines/x/configuration.nix @@ -1,11 +1,17 @@ { lib, inputs, pkgs, ... }: -{ +let + drive = "/dev/nvme0n1"; +in { imports = [ ./hardware-configuration.nix inputs.home-manager.nixosModules.default + + (import ../../disko.nix { device = drive; }) + ] ++ (map (path: ../../modules/${path}) [ "core/global.nix" + "core/impermanence.nix" "amdgpu.nix" "amd.nix" @@ -33,57 +39,12 @@ grub = { enable = true; efiSupport = true; - device = "/dev/nvme0n1"; + device = drive; }; }; - boot.initrd.postDeviceCommands = lib.mkAfter '' - mkdir /btrfs_tmp - mount /dev/root_vg/root /btrfs_tmp - if [[ -e /btrfs_tmp/root ]]; then - mkdir -p /btrfs_tmp/old_roots - timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/root)" "+%Y-%m-%-d_%H:%M:%S") - mv /btrfs_tmp/root "/btrfs_tmp/old_roots/$timestamp" - fi - - delete_subvolume_recursively() { - IFS=$'\n' - for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do - delete_subvolume_recursively "/btrfs_tmp/$i" - done - btrfs subvolume delete "$1" - } - - for i in $(find /btrfs_tmp/old_roots/ -maxdepth 1 -mtime +30); do - delete_subvolume_recursively "$i" - done - - btrfs subvolume create /btrfs_tmp/root - umount /btrfs_tmp - ''; - - fileSystems."/persist".neededForBoot = true; - environment.persistence."/persist/system" = { - hideMounts = true; - directories = [ - "/etc/nixos" - "/var/log" - "/var/lib/bluetooth" - "/var/lib/nixos" - "/var/lib/systemd/coredump" - "/etc/NetworkManager/system-connections" - ]; - files = [ - "/etc/machine-id" - { file = "/var/keys/secret_file"; parentDirectory = { mode = "u=rwx,g=,o="; }; } - ]; - }; - boot.extraModprobeConfig = "options kvm_amd nested=1"; - nixpkgs.config.allowUnfree = true; - nixpkgs.config.allowUnfreePredicate = _: true; - services.fstrim.enable = true; networking.hostName = "x"; diff --git a/modules/core/global.nix b/modules/core/global.nix index 7d372ab..71c82f0 100644 --- a/modules/core/global.nix +++ b/modules/core/global.nix @@ -15,6 +15,9 @@ in { "L+ ${nix_path} - - - - ${pkgs.path}" ]; + nixpkgs.config.allowUnfree = true; + nixpkgs.config.allowUnfreePredicate = _: true; + environment.systemPackages = with pkgs; [ man-pages man-pages-posix diff --git a/modules/core/impermanence.nix b/modules/core/impermanence.nix new file mode 100644 index 0000000..c5f3009 --- /dev/null +++ b/modules/core/impermanence.nix @@ -0,0 +1,45 @@ +{ pkgs, lib, ... }: + +{ + boot.initrd.postDeviceCommands = lib.mkAfter '' + mkdir /btrfs_tmp + mount /dev/root_vg/root /btrfs_tmp + if [[ -e /btrfs_tmp/root ]]; then + mkdir -p /btrfs_tmp/old_roots + timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/root)" "+%Y-%m-%-d_%H:%M:%S") + mv /btrfs_tmp/root "/btrfs_tmp/old_roots/$timestamp" + fi + + delete_subvolume_recursively() { + IFS=$'\n' + for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do + delete_subvolume_recursively "/btrfs_tmp/$i" + done + btrfs subvolume delete "$1" + } + + for i in $(find /btrfs_tmp/old_roots/ -maxdepth 1 -mtime +30); do + delete_subvolume_recursively "$i" + done + + btrfs subvolume create /btrfs_tmp/root + umount /btrfs_tmp + ''; + + fileSystems."/persist".neededForBoot = true; + environment.persistence."/persist/system" = { + hideMounts = true; + directories = [ + "/etc/nixos" + "/var/log" + "/var/lib/bluetooth" + "/var/lib/nixos" + "/var/lib/systemd/coredump" + "/etc/NetworkManager/system-connections" + ]; + files = [ + "/etc/machine-id" + { file = "/var/keys/secret_file"; parentDirectory = { mode = "u=rwx,g=,o="; }; } + ]; + }; +} -- cgit v1.2.3