]> git.scottworley.com Git - nixos-qemu-vm-isolation/commitdiff
Make patch-overlays idempotent main
authorScott Worley <scottworley@scottworley.com>
Fri, 5 Jun 2026 18:54:14 +0000 (11:54 -0700)
committerScott Worley <scottworley@scottworley.com>
Fri, 5 Jun 2026 18:56:08 +0000 (11:56 -0700)
overlays/squashfs-labels/default.nix

index 8a482d3163f924d181ee2f950ad16be4f62d4b68..a8ef85615cff8b97f381b39d059d3103509cad0d 100644 (file)
@@ -1,12 +1,18 @@
 # We patch in support for squashfs labels because
 # https://github.com/NixOS/nixpkgs/pull/236656 requires filesystems to have labels and
 # https://github.com/plougher/squashfs-tools/issues/59 squashfs doesn't support labels
 # We patch in support for squashfs labels because
 # https://github.com/NixOS/nixpkgs/pull/236656 requires filesystems to have labels and
 # https://github.com/plougher/squashfs-tools/issues/59 squashfs doesn't support labels
-final: prev: {
-  squashfsTools = prev.squashfsTools.overrideAttrs (old: {
-    patches = (old.patches or [ ]) ++ [ ./squashfs-tools-label.patch ];
-  });
-
-  util-linux = prev.util-linux.overrideAttrs (old: {
-    patches = (old.patches or [ ]) ++ [ ./util-linux-squashfs-label.patch ];
-  });
+final: prev:
+let
+  idempontenlyAddPatch =
+    pkg: patch:
+    if builtins.elem patch (pkg.drvAttrs.patches or [ ]) then
+      pkg
+    else
+      pkg.overrideAttrs (old: {
+        patches = (old.patches or [ ]) ++ [ patch ];
+      });
+in
+{
+  squashfsTools = idempontenlyAddPatch prev.squashfsTools ./squashfs-tools-label.patch;
+  util-linux = idempontenlyAddPatch prev.util-linux ./util-linux-squashfs-label.patch;
 }
 }