nix-community / home-manager

Manage a user environment using Nix [maintainer=@rycee]
https://nix-community.github.io/home-manager/
MIT License
6.67k stars 1.75k forks source link

bug: search.json.mozlz4 symlink being replaced by file #3698

Open OleMussmann opened 1 year ago

OleMussmann commented 1 year ago

Are you following the right branch?

Is there an existing issue for this?

Issue description

Firefox causes home-manager to fail restarting.

After restarting Firefox, the search.json.mozlz4 symlink is replaced by a file. This causes the home-manager to fail with:

Existing file '/home/[user]/.mozilla/firefox/default/search.json.mozlz4' is in the way of '/nix/store/[hash]-home-manager-files/.mozilla/firefox/default/search.json.mozlz4'
Please move the above files and try again or use 'home-manager switch -b backup' to back up existing files automatically.

I use home-manager as a module in NixOS. The home-manager command is thus not available, and nixos-rebuild switch --flake does not have a -b backup flag. The only way out is indeed to manually remove search.json.mozlz4. Then the symlink is re-created.

NixOS 22.11.20230222.c95bf18 (Raccoon) Home-manager rev 2cb27c79117a2a75ff3416c3199a2dc57af6a527

Maintainer CC

@rycee @kira-bruneau

System information

- system: `"x86_64-linux"`
 - host os: `Linux 6.1.12, NixOS, 22.11 (Raccoon), 22.11.20230222.c95bf18`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.11.1`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
kira-bruneau commented 1 year ago

Oh yep, there's a programs.firefox.profiles.<name>.search.force option to handle this. Its not enabled by default because it can wipe out an existing search configuration.

The docs mention that this is recommened when customzing search, but do you think theres anything that could help make this more discoverable?

OleMussmann commented 1 year ago

Thanks @kira-bruneau , that indeed works nicely. I understand why it's not enabled by default.

I did not study all search related options before playing with it. Maybe the force option could be mentioned in any section that would need it?

sg-qwt commented 1 year ago

I'm not sure if this happens to anyone. But I do have a single profile setup with search being force enabled. But suddenly today, my default search has been changed to Bing without any notice after restarting firefox.

Did a flake update and rebuild, everything went back to normal again. So not sure if I can reproduce this. But I did lost my search profile at one point of time.

stale[bot] commented 1 year ago

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

* If this is resolved, please consider closing it so that the maintainers know not to focus on this. * If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

* If you are also experiencing this issue, please add details of your situation to help with the debugging process. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

sg-qwt commented 1 year ago

This happened again today, here's my setting: https://github.com/sg-qwt/nixos/blob/main/modules/profiles/firefox.nix

Suddenly somehow there's a Bing added into my search engines and it becomes my default. You can see all the hard coded engines with home-manager are still there. I'm pretty sure firefox is doing something shaddy this case, but I don't know which option can toggle that off. (Ps. I don't use firerfox sync or anything, I only use that profile on a single nixos machine, so that's impossible the Bing is synced from other machine.)

image

stale[bot] commented 11 months ago

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

* If this is resolved, please consider closing it so that the maintainers know not to focus on this. * If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

* If you are also experiencing this issue, please add details of your situation to help with the debugging process. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

thomaseizinger commented 8 months ago

I am running into a similar issue. For me, Firefox replaces the search.json.mozlz4 file upon start up. I did a little bit of digging and the file generated by home-manager is quite different from what Firefox puts in place:

This is what Firefox generates (I decompressed the mozlz4 file to JSON) by default on my machine:

{
    "version": 9,
    "engines": [
        {
            "id": "google@search.mozilla.orgdefault",
            "_name": "Google",
            "_isAppProvided": true,
            "_metaData": {
                "order": 1
            }
        },
        {
            "id": "wikipedia@search.mozilla.orgdefault",
            "_name": "Wikipedia (en)",
            "_isAppProvided": true,
            "_metaData": {
                "order": 6
            }
        },
        {
            "id": "bing@search.mozilla.orgdefault",
            "_name": "Bing",
            "_isAppProvided": true,
            "_metaData": {
                "order": 3
            }
        },
        {
            "id": "amazon@search.mozilla.orgau",
            "_name": "Amazon.com.au",
            "_isAppProvided": true,
            "_metaData": {
                "order": 2
            }
        },
        {
            "id": "ddg@search.mozilla.orgdefault",
            "_name": "DuckDuckGo",
            "_isAppProvided": true,
            "_metaData": {
                "order": 4
            }
        },
        {
            "id": "ebay@search.mozilla.orgau",
            "_name": "eBay",
            "_isAppProvided": true,
            "_metaData": {
                "order": 5
            }
        },
        {
            "id": "search@kagi.comdefault",
            "_name": "Kagi",
            "_loadPath": "[addon]search@kagi.com",
            "description": "A simple helper extension for setting Kagi as a default search engine, and automatically logging in to Kagi in incognito browsing windows.",
            "_iconURL": "moz-extension://a739de3a-89db-430a-a0ec-9ec32a96e127/icons/icon_32px.png",
            "_iconMapObj": {
                "{}": "moz-extension://a739de3a-89db-430a-a0ec-9ec32a96e127/icons/icon_180px.png"
            },
            "_metaData": {
                "order": 7
            },
            "_urls": [
                {
                    "params": [],
                    "rels": [],
                    "template": "https://kagi.com/search?q={searchTerms}"
                },
                {
                    "params": [],
                    "rels": [],
                    "template": "https://kagi.com/api/autosuggest?q={searchTerms}",
                    "type": "application/x-suggestions+json"
                }
            ],
            "_telemetryId": null,
            "_definedAliases": [
                "@kagi"
            ],
            "_extensionID": "search@kagi.com",
            "_locale": "default"
        }
    ],
    "metaData": {
        "useSavedOrder": true,
        "locale": "en-US",
        "region": "AU",
        "channel": "default",
        "experiment": "",
        "distroID": "nixos",
        "appDefaultEngineId": "google@search.mozilla.orgdefault"
    }
}

I'd like to set Kagi as my search engine using the following configuration:

programs.firefox = {
  enable = true;
  profiles.default = {
    search = {
      force = true;
      default = "Kagi";
    };
  };
};

This is the file that gets generated as a result:

{
    "engines": [
        {
            "_isAppProvided": true,
            "_metaData": {},
            "_name": "Kagi"
        }
    ],
    "metaData": {
        "current": "Kagi",
        "hash": "MvrjMMu1KsjzeFZZC6h8d/S4qV1wtYUna6dsR5kULFs=",
        "useSavedOrder": false
    },
    "version": 6
}

The immediate difference seems to be that home-manager generates version 6 whereas Firefox puts version 9 there. It appears to me that what happens is that Firefox "upgrades" the file a newer version and in the process, puts Google back as the default search engine.

It tried to naively set version to 9 but that didn't fix it, Firefox still completely replaces the file.

ryanwalder commented 7 months ago

I'm having the same issues with the search not saving Kagi as my preference (it then defaults to Google even though it's hidden) though my search.json.mozlz4 looks different to @thomaseizinger's.

Note: I've only been using nixos/hm for like 2 days so I could very easily be doing something incorrect :smile:

firefox.nix

{ config, pkgs, inputs, ... }:

{
  programs.firefox = {
    enable = true;
    profiles = {
      home = {
        isDefault = true;
        search = {
          force = true;
          default = "Kagi";
          engines = {
            "Wikipedia (en)".hidden = true;
            "Google".metaData.hidden = true;
            "Amazon.com".metaData.hidden = true;
            "Amazon.co.uk".metaData.hidden = true;
            "Bing".metaData.hidden = true;
            "eBay".metaData.hidden = true;
            "DuckDuckGo".metaData.hidden = true;
          };
        };
      };
    };
  };
};

search.json.mozlz4

{
    "engines": [
        {
            "_isAppProvided": true,
            "_metaData": {
                "hidden": true
            },
            "_name": "Amazon.co.uk"
        },
        {
            "_isAppProvided": true,
            "_metaData": {
                "hidden": true
            },
            "_name": "Amazon.com"
        },
        {
            "_isAppProvided": true,
            "_metaData": {
                "hidden": true
            },
            "_name": "Bing"
        },
        {
            "_isAppProvided": true,
            "_metaData": {
                "hidden": true
            },
            "_name": "DuckDuckGo"
        },
        {
            "_isAppProvided": true,
            "_metaData": {
                "hidden": true
            },
            "_name": "Google"
        },
        {
            "_isAppProvided": true,
            "_metaData": {},
            "_name": "Kagi"
        },
        {
            "_isAppProvided": false,
            "_loadPath": "[home-manager]/programs.firefox.profiles.home.search.engines.\"Wikipedia (en)\"",
            "_metaData": {},
            "_name": "Wikipedia (en)",
            "hidden": true
        },
        {
            "_isAppProvided": true,
            "_metaData": {
                "hidden": true
            },
            "_name": "eBay"
        }
    ],
    "metaData": {
        "current": "Kagi",
        "hash": "Pgrc7HKDMIFNrb5hXu95bPmjo0b9+V+G1Dq8D4jXN6M=",
        "useSavedOrder": false
    },
    "version": 6
}
stale[bot] commented 4 months ago

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

* If this is resolved, please consider closing it so that the maintainers know not to focus on this. * If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

* If you are also experiencing this issue, please add details of your situation to help with the debugging process. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.