From 7665a7f89b304581a4a49c81ce0a6ebf305e6c24 Mon Sep 17 00:00:00 2001 From: Patrick Date: Fri, 12 Jul 2024 21:42:01 +0200 Subject: [PATCH] feat: impermanence prune script --- config/basic/impermanence.nix | 50 +++++++++++++++++++++ hosts/patricknix/default.nix | 1 - pkgs/scripts/default.nix | 1 + pkgs/scripts/impermanence-orphan.nix | 17 +++++++ users/common/graphical/wayland/hyprland.nix | 32 +++++++------ users/patrick/impermanence.nix | 1 + 6 files changed, 88 insertions(+), 14 deletions(-) create mode 100644 pkgs/scripts/impermanence-orphan.nix diff --git a/config/basic/impermanence.nix b/config/basic/impermanence.nix index a6fac1e..96634f2 100644 --- a/config/basic/impermanence.nix +++ b/config/basic/impermanence.nix @@ -6,8 +6,58 @@ }: let onlyHost = lib.mkIf (!config.boot.isContainer); + prune = folder: + pkgs.writers.writePython3Bin "impermanence-prune" {} '' + import os + import sys + mounts = [${ + lib.concatStringsSep ", " + ((map (x: + "\"" + + ( + if x.home != null + then x.home + "/" + else "" + ) + + x.directory + + "\"") + config.environment.persistence.${folder}.directories) + ++ (map (x: + "\"" + + ( + if x.home != null + then x.home + "/" + else "" + ) + + x.file + + "\"") + config.environment.persistence.${folder}.files)) + }] # noqa: E501 + mounts = [os.path.normpath(x) for x in mounts] + mounts.sort() + real_mounts = mounts[:1] + for i in mounts[1:]: + if i.startswith(real_mounts[-1] + "/"): + continue + real_mounts.append(i) + erg = set() + for i in real_mounts: + dir = os.path.dirname(i) + try: + content = [dir + "/" + x for x in os.listdir("${folder}" + dir)] + for j in content: + if not any([x.startswith(j) for x in real_mounts]): + erg.add("${folder}" + j) + except PermissionError: + print(f"{dir} could not be accessed. Try running as root", + file=sys.stderr) + print("\n".join(erg)) + ''; in { # to allow all users to access hm managed persistent folders + lib.scripts.impermanence.pruneScripts = + lib.mapAttrs (k: _: prune k) + config.environment.persistence; programs.fuse.userAllowOther = true; services.openssh.hostKeys = lib.mkForce [ { diff --git a/hosts/patricknix/default.nix b/hosts/patricknix/default.nix index 1e0a013..8525fa6 100644 --- a/hosts/patricknix/default.nix +++ b/hosts/patricknix/default.nix @@ -43,7 +43,6 @@ services = { xserver.xkb = { layout = "de"; - variant = "bone"; }; libinput = { touchpad = lib.mkForce { diff --git a/pkgs/scripts/default.nix b/pkgs/scripts/default.nix index 2680317..98efb96 100644 --- a/pkgs/scripts/default.nix +++ b/pkgs/scripts/default.nix @@ -2,5 +2,6 @@ _final: prev: { scripts = { usbguardw = prev.callPackage ./usbguardw.nix {}; clone-term = prev.callPackage ./clone-term.nix {}; + impermanence-o = prev.callPackage ./impermanence-orphan.nix {}; }; } diff --git a/pkgs/scripts/impermanence-orphan.nix b/pkgs/scripts/impermanence-orphan.nix new file mode 100644 index 0000000..e9d031b --- /dev/null +++ b/pkgs/scripts/impermanence-orphan.nix @@ -0,0 +1,17 @@ +{writers}: +writers.writePython3Bin "find-orphaned" {} '' + import sys + import os + if len(sys.argv) != 2: + print("Please give a singular argument containing the folder to prune") + exit(1) + mountpoint = sys.argv[1] + if !os.path.exists(mountpoint)): + print("Argument has to exist") + exit(1) + with open("/proc/mounts", "r") as f: + mounts = [line.split() for line in f.readlines()] + toplevel = + current = [mountpoint] + print(os.listdir(mountpoint)) +'' diff --git a/users/common/graphical/wayland/hyprland.nix b/users/common/graphical/wayland/hyprland.nix index e30d2c3..eea1478 100644 --- a/users/common/graphical/wayland/hyprland.nix +++ b/users/common/graphical/wayland/hyprland.nix @@ -197,6 +197,16 @@ in { xwayland.force_zero_scaling = true; windowrulev2 = [ "immediate, class:^(cs2)$" + "workspace 2,class:^(firefox)$" + "workspace 3,class:^(thunderbird)$" + "workspace 4,class:^(bottles)$" + "workspace 4,class:^(steam)$" + "workspace 4,class:^(prismlauncher)$" + "workspace 6,class:^(discord)$" + "workspace 6,class:^(WebCord)$" + "workspace 6,class:^(TeamSpeak 3)$" + "workspace 7,class:^(signal)$" + "workspace 7,class:^(TelegramDesktop)$" ]; } (mkIf (nixosConfig.node.name == "desktopnix") { @@ -215,19 +225,6 @@ in { "GBM_BACKEND,nvidia-drm" "__GLX_VENDOR_LIBRARY_NAME,nvidia" ]; - windowrulev2 = [ - "workspace 2,class:^(firefox)$" - "workspace 3,class:^(thunderbird)$" - "workspace 4,class:^(bottles)$" - "workspace 4,class:^(steam)$" - "workspace 4,class:^(prismlauncher)$" - "workspace 6,class:^(discord)$" - "workspace 6,class:^(WebCord)$" - "workspace 6,class:^(TeamSpeak 3)$" - "workspace 7,class:^(signal)$" - "workspace 7,class:^(TelegramDesktop)$" - ]; - workspace = [ "1, monitor:DP-3, default:true" "2, monitor:DP-3" @@ -248,6 +245,15 @@ in { "Unknown-1, disable" ]; workspace = [ + "1, monitor:eDP-1, default:true" + "2, monitor:eDP-1" + "3, monitor:eDP-1" + "4, monitor:eDP-1" + "5, monitor:eDP-1" + "6, monitor:eDP-1" + "7, monitor:eDP-1" + "8, monitor:eDP-1" + "9, monitor:eDP-1" ]; }) ]; diff --git a/users/patrick/impermanence.nix b/users/patrick/impermanence.nix index 76652e3..b1e8be3 100644 --- a/users/patrick/impermanence.nix +++ b/users/patrick/impermanence.nix @@ -44,6 +44,7 @@ ".config/spotify" ".cache/spotify" ".local/share/cargo" + ".local/share/wallpapers" ]; }; "/panzer/state".directories =