diff --git a/hosts/common/system/configs/impermanence/default.nix b/hosts/common/system/configs/impermanence/default.nix index aab33c3..6413e00 100644 --- a/hosts/common/system/configs/impermanence/default.nix +++ b/hosts/common/system/configs/impermanence/default.nix @@ -19,6 +19,7 @@ after = [ "cryptsetup.target" ]; unitConfig.DefaultDependencies = false; serviceConfig.Type = "oneshot"; + environment.DEVICE = config.environment.impermanence.device; script = builtins.readFile ./scripts/wipe.sh; }; }; diff --git a/hosts/common/system/configs/impermanence/options.nix b/hosts/common/system/configs/impermanence/options.nix index 4ed697e..76c27d4 100644 --- a/hosts/common/system/configs/impermanence/options.nix +++ b/hosts/common/system/configs/impermanence/options.nix @@ -43,125 +43,136 @@ let ) [ ] parents; in { - options.environment.persistence = + options.environment = with lib; with types; - let - isPathLike = strings.hasPrefix "/"; - in - mkOption { - type = ( - addCheck (attrsOf ( - attrsOf ( - submodule ( - { name, config, ... }: - { - options = { - enable = mkOption { - type = bool; - default = true; - description = "Whether to enable the item."; - }; + { + impermanence.device = mkOption { + type = str; + default = config.disko.devices.disk.main.content.partitions.root.content.name; + description = '' + LUKS BTRFS partition to wipe on boot. + ''; + }; - service = mkOption { - type = str; - readOnly = true; - description = '' - Systemd service that prepares and syncs the item. - Can be used as a dependency in other units. - ''; - }; + persistence = + let + isPathLike = strings.hasPrefix "/"; + in + mkOption { + type = ( + addCheck (attrsOf ( + attrsOf ( + submodule ( + { name, config, ... }: + { + options = { + enable = mkOption { + type = bool; + default = true; + description = "Whether to enable the item."; + }; - mount = mkOption { - type = str; - readOnly = true; - description = '' - Systemd mount that binds the item. - Can be used as a dependency in other units. - ''; - }; + service = mkOption { + type = str; + readOnly = true; + description = '' + Systemd service that prepares and syncs the item. + Can be used as a dependency in other units. + ''; + }; - _path = mkOption { - type = str; - internal = true; - default = name; - }; + mount = mkOption { + type = str; + readOnly = true; + description = '' + Systemd mount that binds the item. + Can be used as a dependency in other units. + ''; + }; - _sourceRoot = mkOption { - type = str; - internal = true; - }; + _path = mkOption { + type = str; + internal = true; + default = name; + }; - _source = mkOption { - type = str; - internal = true; - }; + _sourceRoot = mkOption { + type = str; + internal = true; + }; - _targetRoot = mkOption { - type = str; - internal = true; - }; + _source = mkOption { + type = str; + internal = true; + }; - _target = mkOption { - type = str; - internal = true; - }; - }; - } - ) - ) - )) (attrs: lists.all isPathLike (builtins.attrNames attrs)) - ); - apply = - ps: - builtins.mapAttrs ( - persistence: items: - builtins.mapAttrs ( - _: config: - let - _path = config._path; + _targetRoot = mkOption { + type = str; + internal = true; + }; - _sourceRoot = persistence; - - _source = mergePaths [ - _sourceRoot - _path - ]; - - _targetRoot = + _target = mkOption { + type = str; + internal = true; + }; + }; + } + ) + ) + )) (attrs: lists.all isPathLike (builtins.attrNames attrs)) + ); + apply = + ps: + builtins.mapAttrs ( + persistence: items: + builtins.mapAttrs ( + _: config: let - parents = lists.reverseList (parentsOf _path); - in - lists.foldl' ( - acc: parent: - if acc == "/" then - lists.findFirst ( - otherPersistence: lists.any (other: parent == other) (builtins.attrNames ps.${otherPersistence}) - ) "/" (builtins.attrNames ps) - else - acc - ) "/" parents; + _path = config._path; - _target = mergePaths [ - _targetRoot - _path - ]; - in - config - // { - inherit - _sourceRoot - _source - _targetRoot - _target - ; - service = "${utils.escapeSystemdPath _target}.service"; - mount = "${utils.escapeSystemdPath _target}.mount"; - } - ) items - ) ps; - default = { }; - description = "Persistence config."; + _sourceRoot = persistence; + + _source = mergePaths [ + _sourceRoot + _path + ]; + + _targetRoot = + let + parents = lists.reverseList (parentsOf _path); + in + lists.foldl' ( + acc: parent: + if acc == "/" then + lists.findFirst ( + otherPersistence: lists.any (other: parent == other) (builtins.attrNames ps.${otherPersistence}) + ) "/" (builtins.attrNames ps) + else + acc + ) "/" parents; + + _target = mergePaths [ + _targetRoot + _path + ]; + in + config + // { + inherit + _sourceRoot + _source + _targetRoot + _target + ; + service = "${utils.escapeSystemdPath _target}.service"; + mount = "${utils.escapeSystemdPath _target}.mount"; + } + ) items + ) ps; + default = { }; + description = "Persistence config."; + }; }; config = diff --git a/hosts/common/system/configs/impermanence/scripts/wipe.sh b/hosts/common/system/configs/impermanence/scripts/wipe.sh index e975786..27cd0d4 100644 --- a/hosts/common/system/configs/impermanence/scripts/wipe.sh +++ b/hosts/common/system/configs/impermanence/scripts/wipe.sh @@ -6,8 +6,13 @@ delete_subvolume_recursively() { btrfs subvolume delete "$1" } +if [[ -z "$DEVICE" ]]; then + echo "Error: DEVICE variable is not set." + exit 1 +fi + mkdir -p /mnt/btrfs -mount /dev/mapper/luks /mnt/btrfs +mount "/dev/mapper/$DEVICE" /mnt/btrfs if [[ -e /mnt/btrfs/@ ]]; then mkdir -p /mnt/btrfs/@.bak diff --git a/hosts/common/system/configs/libvirt/default.nix b/hosts/common/system/configs/libvirt/default.nix index e1b2afc..2ed7f27 100644 --- a/hosts/common/system/configs/libvirt/default.nix +++ b/hosts/common/system/configs/libvirt/default.nix @@ -16,7 +16,10 @@ description = "Start Default Virtual Network for Libvirt"; script = "${config.virtualisation.libvirtd.package}/bin/virsh net-start default"; preStop = "${config.virtualisation.libvirtd.package}/bin/virsh net-destroy default"; - serviceConfig.Type = "oneshot"; + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + }; wantedBy = [ "libvirtd.service" ]; after = [ "libvirtd.service" ]; }; diff --git a/hosts/common/system/configs/nix-cleanup/cleanup.sh b/hosts/common/system/configs/nix-cleanup/cleanup.sh index e238235..ef48a72 100644 --- a/hosts/common/system/configs/nix-cleanup/cleanup.sh +++ b/hosts/common/system/configs/nix-cleanup/cleanup.sh @@ -16,8 +16,13 @@ if [[ -e /mnt/btrfs && -n $(mountpoint -q /mnt/btrfs) ]]; then exit 1 fi +if [[ -z "$DEVICE" ]]; then + echo "Error: DEVICE variable is not set." + exit 1 +fi + mkdir -p /mnt/btrfs -mount /dev/mapper/luks /mnt/btrfs +mount "/dev/mapper/$DEVICE" /mnt/btrfs if [[ -e /mnt/btrfs/@.bak ]]; then if [[ -n "$(ls -A /mnt/btrfs/@.bak)" ]]; then diff --git a/hosts/common/system/configs/nix-cleanup/default.nix b/hosts/common/system/configs/nix-cleanup/default.nix index a31b72c..18d9305 100644 --- a/hosts/common/system/configs/nix-cleanup/default.nix +++ b/hosts/common/system/configs/nix-cleanup/default.nix @@ -1,4 +1,4 @@ -{ pkgs, ... }: +{ config, pkgs, ... }: { environment.systemPackages = [ (pkgs.writeShellApplication { @@ -10,6 +10,7 @@ btrfs-progs nix ]; + runtimeEnv.DEVICE = config.environment.impermanence.device; text = builtins.readFile ./cleanup.sh; }) ]; diff --git a/hosts/eirene/format.nix b/hosts/eirene/format.nix index 2cc4505..7ce4f97 100644 --- a/hosts/eirene/format.nix +++ b/hosts/eirene/format.nix @@ -38,7 +38,7 @@ name = "root"; size = "100%"; content = { - name = "luks"; + name = "main"; type = "luks"; settings = { allowDiscards = true; diff --git a/hosts/elara/default.nix b/hosts/elara/default.nix index 6758c34..65cbc7f 100644 --- a/hosts/elara/default.nix +++ b/hosts/elara/default.nix @@ -1,4 +1,5 @@ { + config, inputs, lib, pkgs, @@ -23,7 +24,6 @@ ../common/system/configs/git ../common/system/configs/gpg-agent ../common/system/configs/impermanence - ../common/system/configs/libvirt ../common/system/configs/lsof ../common/system/configs/ncdu ../common/system/configs/neovim @@ -51,7 +51,7 @@ ./users/nikara ]; - networking.hostName = "sas"; + networking.hostName = "elara"; i18n.defaultLocale = "en_US.UTF-8"; sops.defaultSopsFile = ./secrets/secrets.yaml; @@ -110,6 +110,9 @@ ]; }; + environment.impermanence.device = + config.disko.devices.disk.usb.content.partitions.root.content.name; + nixpkgs = { hostPlatform = "x86_64-linux"; diff --git a/hosts/elara/format.nix b/hosts/elara/format.nix index cda3b82..3895ded 100644 --- a/hosts/elara/format.nix +++ b/hosts/elara/format.nix @@ -4,7 +4,7 @@ }: { disko.devices = { - disk.main = { + disk.usb = { inherit device; type = "disk"; content = { @@ -30,7 +30,7 @@ name = "root"; size = "100%"; content = { - name = "luks"; + name = "usb"; type = "luks"; settings = { allowDiscards = true; diff --git a/hosts/elara/users/nikara/default.nix b/hosts/elara/users/nikara/default.nix index 50cea12..d6bd9d5 100644 --- a/hosts/elara/users/nikara/default.nix +++ b/hosts/elara/users/nikara/default.nix @@ -109,7 +109,7 @@ in "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; };