Modularize code
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
22
hosts/common/configs/persist/default.nix
Normal file
22
hosts/common/configs/persist/default.nix
Normal file
@@ -0,0 +1,22 @@
|
||||
{ inputs, lib, ... }:
|
||||
|
||||
{
|
||||
imports = [ inputs.impermanence.nixosModules.impermanence ];
|
||||
|
||||
fileSystems."/persist".neededForBoot = true;
|
||||
boot.initrd.postDeviceCommands = lib.mkAfter (builtins.readFile ./impermanence.sh);
|
||||
|
||||
environment.persistence."/persist" = {
|
||||
hideMounts = true;
|
||||
directories = [
|
||||
"/etc/nixos"
|
||||
"/etc/NetworkManager/system-connections"
|
||||
"/var/lib/nixos"
|
||||
"/var/lib/systemd/coredump"
|
||||
"/var/log"
|
||||
];
|
||||
files = [
|
||||
"/etc/machine-id"
|
||||
];
|
||||
};
|
||||
}
|
25
hosts/common/configs/persist/impermanence.sh
Normal file
25
hosts/common/configs/persist/impermanence.sh
Normal file
@@ -0,0 +1,25 @@
|
||||
delete_subvolume_recursively() {
|
||||
IFS=$'\n'
|
||||
for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do
|
||||
delete_subvolume_recursively "/mnt/btrfs/$i"
|
||||
done
|
||||
btrfs subvolume delete "$1"
|
||||
}
|
||||
|
||||
mkdir -p /mnt/btrfs
|
||||
mount /dev/mapper/luks /mnt/btrfs
|
||||
|
||||
if [[ -e /mnt/btrfs/root ]]; then
|
||||
mkdir -p /mnt/btrfs/root.bak
|
||||
timestamp=$(date --date="@$(stat -c %Y /mnt/btrfs/root)" "+%Y-%m-%-d_%H:%M:%S")
|
||||
mv /mnt/btrfs/root "/mnt/btrfs/root.bak/$timestamp"
|
||||
fi
|
||||
|
||||
find /mnt/btrfs/root.bak/ -maxdepth 1 -mtime +14 | while IFS= read -r i; do
|
||||
delete_subvolume_recursively "$i"
|
||||
done
|
||||
|
||||
btrfs subvolume create /mnt/btrfs/root
|
||||
|
||||
umount /mnt/btrfs
|
||||
rmdir /mnt/btrfs
|
16
hosts/common/configs/sops/default.nix
Normal file
16
hosts/common/configs/sops/default.nix
Normal file
@@ -0,0 +1,16 @@
|
||||
{ inputs, pkgs, ... }:
|
||||
|
||||
{
|
||||
imports = [ inputs.sops-nix.nixosModules.sops ];
|
||||
|
||||
environment = {
|
||||
persistence."/persist".files = [ "/etc/ssh/ssh_host_ed25519_key" ];
|
||||
systemPackages = with pkgs; [ sops ];
|
||||
};
|
||||
|
||||
sops.age = {
|
||||
generateKey = true;
|
||||
sshKeyPaths = [ "/persist/etc/ssh/ssh_host_ed25519_key" ];
|
||||
keyFile = "/var/lib/sops-nix/key.txt";
|
||||
};
|
||||
}
|
@@ -3,4 +3,6 @@
|
||||
enable = true;
|
||||
histFile = "/var/lib/zsh/history";
|
||||
};
|
||||
|
||||
environment.persistence."/persist".directories = [ "/var/lib/zsh" ];
|
||||
}
|
||||
|
Reference in New Issue
Block a user