How to apply a patch to a file in home directory?

I’m trying to patch a pre-existing file installed by cinnamon, this is the patch:

--- .config/cinnamon/spices/grouped-window-list@cinnamon.org/2.json	2023-07-26 12:57:00.707368221 +0200
+++ .config/cinnamon/spices/grouped-window-list@cinnamon.org/2.json	2023-07-26 12:57:11.376397587 +0200
@@ -120,7 +120,7 @@
             "Window title": 3,
             "Window title (only for the focused window)": 4
         },
-        "value": 1
+        "value": 3
     },
     "scroll-behavior": {
         "type": "combobox",

I’m pretty new to NixOS and have no idea how to achieve something like that.

1 Like

Are you using home-manager? If so, you could try xdg.configFile

I am. The file is some 355 lines while this is the only relevant change, so I don’t want to copy it whole.

You probably could use home-manager’s activation script, but I’d argue just copying the entire file and using xdg.configFile.<name>.source and xdg.configFile.<name>.target is less likely to break on file changes.

EDIT: Alternatively, if that file is included in the cinnamon package you can apply patches to it there with something like:

nixpkgs.overlays = [
  (final: prev: {
    cinnamon = prev.cinnamon.overrideAttrs (o: {
      patches = (o.patches or [ ]) ++ [
        ./mypatch.patch
      ];
    });
  })
];

Do you know where that file is being copied from?

I found a JSON schema it’s (probably) generated from:

/nix/store/0ra07jnzschj04m8mlbvv3gmzxqz2kin-system-path/share/cinnamon/applets/grouped-window-list@cinnamon.org/settings-schema.json

"title-display": {
    "type": "combobox",
    "default": 1,
    "description": "Button label",
    "options": {
      "None": 1,
      "Application name": 2,
      "Window title": 3,
      "Window title (only for the focused window)": 4
    }
  },

The default could probably be changed and I guess on a new system it will get generated correctly (would that be a fair assumption?).

@pinpox Which file should I use for the patch? I don’t fully understand overlays yet, should it be a relative path, or an absolute one without the /nix/store/*-system-path?

What am I doing wrong?

  nixpkgs.overlays = [
    (let
      pinnedPkgs = import(pkgs.fetchFromGitHub {
        owner = "NixOS";
        repo = "nixpkgs";
        rev = "b6bbc53029a31f788ffed9ea2d459f0bb0f0fbfc";
        sha256 = "sha256-JVFoTY3rs1uDHbh0llRb1BcTNx26fGSLSiPmjojT+KY=";
      }) {};
    in
    final: prev: {
      docker = pinnedPkgs.docker;
    })
    (final: prev: {
      cinnamon = prev.cinnamon.overrideAttrs (old: {
        patches = (old.patches or []) ++ [
          (prev.fetchpatch {
            url = "https://raw.githubusercontent.com/RikudouSage/RikudouSage/main/nixos/patches/cinnamon.patch";
            hash = "07sx98d422589gxr8wflfpkdd0k44kbagxl3b51i56ky2wfix7rc";
          })
        ];
      });
    })
  ];

I get this error:

building Nix...
building the system configuration...
error: attribute 'overrideAttrs' missing

       at /etc/nixos/configuration.nix:77:18:

           76|     (final: prev: {
           77|       cinnamon = prev.cinnamon.overrideAttrs (old: {
             |                  ^
           78|         patches = (old.patches or []) ++ [
(use '--show-trace' to show detailed location information)

Found a solution with help from people on Matrix:

  nixpkgs.overlays = [
    (final: prev: {
      cinnamon = prev.cinnamon // {
        cinnamon-common = prev.cinnamon.cinnamon-common.overrideAttrs (old: {
          patches = (old.patches or []) ++ [
            (prev.fetchpatch {
              url = "https://raw.githubusercontent.com/RikudouSage/RikudouSage/main/nixos/patches/cinnamon.patch";
              hash = "sha256-RcTfxTUDwoMvJDkE0s7+F0W1AYEgImoKVh29bI+qa08=";
            })
          ];
        });
      };
    })
  ];

Note that it doesn’t work for the current system, but my goal was to have it recreated on a new system, so that’s good enough solution for me.

1 Like