1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2024-12-14 11:57:55 +00:00

firefox: add container support

This commit is contained in:
Damien Cassou 2023-10-13 08:34:32 +02:00 committed by Robert Helgesson
parent 858fe2f09a
commit 54586daa59
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
5 changed files with 155 additions and 3 deletions

View file

@ -59,6 +59,24 @@ let
${extraPrefs}
'';
mkContainersJson = containers:
let
containerToIdentity = _: container: {
userContextId = container.id;
name = container.name;
icon = container.icon;
color = container.color;
public = true;
};
in ''
${builtins.toJSON {
version = 4;
lastUserContextId =
elemAt (mapAttrsToList (_: container: container.id) containers) 0;
identities = mapAttrsToList containerToIdentity containers;
}}
'';
firefoxBookmarksFile = bookmarks:
let
indent = level:
@ -457,6 +475,83 @@ in {
};
};
containers = mkOption {
type = types.attrsOf (types.submodule ({ name, ... }: {
options = {
name = mkOption {
type = types.str;
default = name;
description = "Container name, e.g., shopping.";
};
id = mkOption {
type = types.ints.unsigned;
default = 0;
description = ''
Container ID. This should be set to a unique number per container in this profile.
'';
};
# List of colors at
# https://searchfox.org/mozilla-central/rev/5ad226c7379b0564c76dc3b54b44985356f94c5a/toolkit/components/extensions/parent/ext-contextualIdentities.js#32
color = mkOption {
type = types.enum [
"blue"
"turquoise"
"green"
"yellow"
"orange"
"red"
"pink"
"purple"
"toolbar"
];
default = "pink";
description = "Container color.";
};
icon = mkOption {
type = types.enum [
"briefcase"
"cart"
"circle"
"dollar"
"fence"
"fingerprint"
"gift"
"vacation"
"food"
"fruit"
"pet"
"tree"
"chill"
];
default = "fruit";
description = "Container icon.";
};
};
}));
default = { };
example = {
"shopping" = {
id = 1;
color = "blue";
icon = "cart";
};
"dangerous" = {
id = 2;
color = "red";
icon = "fruit";
};
};
description = ''
Attribute set of container configurations. See
[Multi-Account
Containers](https://support.mozilla.org/en-US/kb/containers)
for more information.
'';
};
extensions = mkOption {
type = types.listOf types.package;
default = [ ];
@ -514,7 +609,9 @@ in {
})
(mkNoDuplicateAssertion cfg.profiles "profile")
];
] ++ (mapAttrsToList
(_: profile: mkNoDuplicateAssertion profile.containers "container")
cfg.profiles);
warnings = optional (cfg.enableGnomeExtensions or false) ''
Using 'programs.firefox.enableGnomeExtensions' has been deprecated and
@ -560,6 +657,11 @@ in {
mkUserJs profile.settings profile.extraConfig profile.bookmarks;
};
"${profilesPath}/${profile.path}/containers.json" =
mkIf (profile.containers != { }) {
text = mkContainersJson profile.containers;
};
"${profilesPath}/${profile.path}/search.json.mozlz4" = mkIf
(profile.search.default != null || profile.search.order != [ ]
|| profile.search.engines != { }) {

View file

@ -3,4 +3,5 @@
firefox-state-version-19_09 = ./state-version-19_09.nix;
firefox-deprecated-native-messenger = ./deprecated-native-messenger.nix;
firefox-duplicate-profile-ids = ./duplicate-profile-ids.nix;
firefox-duplicate-container-ids = ./duplicate-container-ids.nix;
}

View file

@ -0,0 +1,35 @@
{ config, lib, ... }:
{
imports = [ ./setup-firefox-mock-overlay.nix ];
config = lib.mkIf config.test.enableBig {
test.asserts.assertions.expected = [''
Must not have a Firefox container with an existing ID but
- ID 9 is used by dangerous, shopping''];
programs.firefox = {
enable = true;
profiles = {
my-profile = {
isDefault = true;
id = 1;
containers = {
"shopping" = {
id = 9;
color = "blue";
icon = "circle";
};
"dangerous" = {
id = 9;
color = "red";
icon = "circle";
};
};
};
};
};
};
}

View file

@ -0,0 +1 @@
{"identities":[{"color":"yellow","icon":"circle","name":"shopping","public":true,"userContextId":6}],"lastUserContextId":6,"version":4}

View file

@ -1,7 +1,5 @@
{ config, lib, pkgs, ... }:
with lib;
{
imports = [ ./setup-firefox-mock-overlay.nix ];
@ -142,6 +140,17 @@ with lib;
};
};
};
profiles.containers = {
id = 5;
containers = {
"shopping" = {
id = 6;
icon = "circle";
color = "yellow";
};
};
};
};
nmt.script = ''
@ -155,6 +164,10 @@ with lib;
home-files/.mozilla/firefox/test/user.js \
${./profile-settings-expected-user.js}
assertFileContent \
home-files/.mozilla/firefox/containers/containers.json \
${./profile-settings-expected-containers.json}
bookmarksUserJs=$(normalizeStorePaths \
home-files/.mozilla/firefox/bookmarks/user.js)