diff options
| author | Raghuram Subramani <raghus2247@gmail.com> | 2024-10-10 10:03:42 +0530 |
|---|---|---|
| committer | Raghuram Subramani <raghus2247@gmail.com> | 2024-10-10 10:03:42 +0530 |
| commit | acd2d93ad81ffad72c067e0cbf90bee809276951 (patch) | |
| tree | 9d2e7564a153d485a7bf4dbe9c84de18573e41a5 /modules | |
| parent | 5587dc4f07576e73a7fabcb527c108d00752cbe7 (diff) | |
(impermanence): Modularize config.
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/core/global.nix | 3 | ||||
| -rw-r--r-- | modules/core/impermanence.nix | 45 |
2 files changed, 48 insertions, 0 deletions
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="; }; } + ]; + }; +} |
