Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2024-12-18 23:29:49 +00:00
parent e23e71560f
commit bcad2979bf
10 changed files with 146 additions and 117 deletions

View File

@@ -19,6 +19,7 @@
after = [ "cryptsetup.target" ]; after = [ "cryptsetup.target" ];
unitConfig.DefaultDependencies = false; unitConfig.DefaultDependencies = false;
serviceConfig.Type = "oneshot"; serviceConfig.Type = "oneshot";
environment.DEVICE = config.environment.impermanence.device;
script = builtins.readFile ./scripts/wipe.sh; script = builtins.readFile ./scripts/wipe.sh;
}; };
}; };

View File

@@ -43,9 +43,19 @@ let
) [ ] parents; ) [ ] parents;
in in
{ {
options.environment.persistence = options.environment =
with lib; with lib;
with types; with types;
{
impermanence.device = mkOption {
type = str;
default = config.disko.devices.disk.main.content.partitions.root.content.name;
description = ''
LUKS BTRFS partition to wipe on boot.
'';
};
persistence =
let let
isPathLike = strings.hasPrefix "/"; isPathLike = strings.hasPrefix "/";
in in
@@ -163,6 +173,7 @@ in
default = { }; default = { };
description = "Persistence config."; description = "Persistence config.";
}; };
};
config = config =
let let

View File

@@ -6,8 +6,13 @@ delete_subvolume_recursively() {
btrfs subvolume delete "$1" btrfs subvolume delete "$1"
} }
if [[ -z "$DEVICE" ]]; then
echo "Error: DEVICE variable is not set."
exit 1
fi
mkdir -p /mnt/btrfs mkdir -p /mnt/btrfs
mount /dev/mapper/luks /mnt/btrfs mount "/dev/mapper/$DEVICE" /mnt/btrfs
if [[ -e /mnt/btrfs/@ ]]; then if [[ -e /mnt/btrfs/@ ]]; then
mkdir -p /mnt/btrfs/@.bak mkdir -p /mnt/btrfs/@.bak

View File

@@ -16,7 +16,10 @@
description = "Start Default Virtual Network for Libvirt"; description = "Start Default Virtual Network for Libvirt";
script = "${config.virtualisation.libvirtd.package}/bin/virsh net-start default"; script = "${config.virtualisation.libvirtd.package}/bin/virsh net-start default";
preStop = "${config.virtualisation.libvirtd.package}/bin/virsh net-destroy default"; preStop = "${config.virtualisation.libvirtd.package}/bin/virsh net-destroy default";
serviceConfig.Type = "oneshot"; serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
};
wantedBy = [ "libvirtd.service" ]; wantedBy = [ "libvirtd.service" ];
after = [ "libvirtd.service" ]; after = [ "libvirtd.service" ];
}; };

View File

@@ -16,8 +16,13 @@ if [[ -e /mnt/btrfs && -n $(mountpoint -q /mnt/btrfs) ]]; then
exit 1 exit 1
fi fi
if [[ -z "$DEVICE" ]]; then
echo "Error: DEVICE variable is not set."
exit 1
fi
mkdir -p /mnt/btrfs mkdir -p /mnt/btrfs
mount /dev/mapper/luks /mnt/btrfs mount "/dev/mapper/$DEVICE" /mnt/btrfs
if [[ -e /mnt/btrfs/@.bak ]]; then if [[ -e /mnt/btrfs/@.bak ]]; then
if [[ -n "$(ls -A /mnt/btrfs/@.bak)" ]]; then if [[ -n "$(ls -A /mnt/btrfs/@.bak)" ]]; then

View File

@@ -1,4 +1,4 @@
{ pkgs, ... }: { config, pkgs, ... }:
{ {
environment.systemPackages = [ environment.systemPackages = [
(pkgs.writeShellApplication { (pkgs.writeShellApplication {
@@ -10,6 +10,7 @@
btrfs-progs btrfs-progs
nix nix
]; ];
runtimeEnv.DEVICE = config.environment.impermanence.device;
text = builtins.readFile ./cleanup.sh; text = builtins.readFile ./cleanup.sh;
}) })
]; ];

View File

@@ -38,7 +38,7 @@
name = "root"; name = "root";
size = "100%"; size = "100%";
content = { content = {
name = "luks"; name = "main";
type = "luks"; type = "luks";
settings = { settings = {
allowDiscards = true; allowDiscards = true;

View File

@@ -1,4 +1,5 @@
{ {
config,
inputs, inputs,
lib, lib,
pkgs, pkgs,
@@ -23,7 +24,6 @@
../common/system/configs/git ../common/system/configs/git
../common/system/configs/gpg-agent ../common/system/configs/gpg-agent
../common/system/configs/impermanence ../common/system/configs/impermanence
../common/system/configs/libvirt
../common/system/configs/lsof ../common/system/configs/lsof
../common/system/configs/ncdu ../common/system/configs/ncdu
../common/system/configs/neovim ../common/system/configs/neovim
@@ -51,7 +51,7 @@
./users/nikara ./users/nikara
]; ];
networking.hostName = "sas"; networking.hostName = "elara";
i18n.defaultLocale = "en_US.UTF-8"; i18n.defaultLocale = "en_US.UTF-8";
sops.defaultSopsFile = ./secrets/secrets.yaml; sops.defaultSopsFile = ./secrets/secrets.yaml;
@@ -110,6 +110,9 @@
]; ];
}; };
environment.impermanence.device =
config.disko.devices.disk.usb.content.partitions.root.content.name;
nixpkgs = { nixpkgs = {
hostPlatform = "x86_64-linux"; hostPlatform = "x86_64-linux";

View File

@@ -4,7 +4,7 @@
}: }:
{ {
disko.devices = { disko.devices = {
disk.main = { disk.usb = {
inherit device; inherit device;
type = "disk"; type = "disk";
content = { content = {
@@ -30,7 +30,7 @@
name = "root"; name = "root";
size = "100%"; size = "100%";
content = { content = {
name = "luks"; name = "usb";
type = "luks"; type = "luks";
settings = { settings = {
allowDiscards = true; allowDiscards = true;

View File

@@ -109,7 +109,7 @@ in
"globalprotect/gateway".sopsFile = ../../../../secrets/sas/secrets.yaml; "globalprotect/gateway".sopsFile = ../../../../secrets/sas/secrets.yaml;
}; };
theme.wallpaper = ../../../../static/wallpapers/clouds.png; theme.wallpaper = ../../../../static/wallpapers/snow.jpg;
programs.obsidian.vaults."Documents/Obsidian/master".enable = true; programs.obsidian.vaults."Documents/Obsidian/master".enable = true;
}; };