mirror of
https://github.com/nix-community/home-manager
synced 2024-11-30 06:59:45 +01:00
firefox: add container support
This commit is contained in:
parent
858fe2f09a
commit
54586daa59
5 changed files with 155 additions and 3 deletions
|
@ -59,6 +59,24 @@ let
|
||||||
${extraPrefs}
|
${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:
|
firefoxBookmarksFile = bookmarks:
|
||||||
let
|
let
|
||||||
indent = level:
|
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 {
|
extensions = mkOption {
|
||||||
type = types.listOf types.package;
|
type = types.listOf types.package;
|
||||||
default = [ ];
|
default = [ ];
|
||||||
|
@ -514,7 +609,9 @@ in {
|
||||||
})
|
})
|
||||||
|
|
||||||
(mkNoDuplicateAssertion cfg.profiles "profile")
|
(mkNoDuplicateAssertion cfg.profiles "profile")
|
||||||
];
|
] ++ (mapAttrsToList
|
||||||
|
(_: profile: mkNoDuplicateAssertion profile.containers "container")
|
||||||
|
cfg.profiles);
|
||||||
|
|
||||||
warnings = optional (cfg.enableGnomeExtensions or false) ''
|
warnings = optional (cfg.enableGnomeExtensions or false) ''
|
||||||
Using 'programs.firefox.enableGnomeExtensions' has been deprecated and
|
Using 'programs.firefox.enableGnomeExtensions' has been deprecated and
|
||||||
|
@ -560,6 +657,11 @@ in {
|
||||||
mkUserJs profile.settings profile.extraConfig profile.bookmarks;
|
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
|
"${profilesPath}/${profile.path}/search.json.mozlz4" = mkIf
|
||||||
(profile.search.default != null || profile.search.order != [ ]
|
(profile.search.default != null || profile.search.order != [ ]
|
||||||
|| profile.search.engines != { }) {
|
|| profile.search.engines != { }) {
|
||||||
|
|
|
@ -3,4 +3,5 @@
|
||||||
firefox-state-version-19_09 = ./state-version-19_09.nix;
|
firefox-state-version-19_09 = ./state-version-19_09.nix;
|
||||||
firefox-deprecated-native-messenger = ./deprecated-native-messenger.nix;
|
firefox-deprecated-native-messenger = ./deprecated-native-messenger.nix;
|
||||||
firefox-duplicate-profile-ids = ./duplicate-profile-ids.nix;
|
firefox-duplicate-profile-ids = ./duplicate-profile-ids.nix;
|
||||||
|
firefox-duplicate-container-ids = ./duplicate-container-ids.nix;
|
||||||
}
|
}
|
||||||
|
|
35
tests/modules/programs/firefox/duplicate-container-ids.nix
Normal file
35
tests/modules/programs/firefox/duplicate-container-ids.nix
Normal 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";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
{"identities":[{"color":"yellow","icon":"circle","name":"shopping","public":true,"userContextId":6}],"lastUserContextId":6,"version":4}
|
|
@ -1,7 +1,5 @@
|
||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
with lib;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
imports = [ ./setup-firefox-mock-overlay.nix ];
|
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 = ''
|
nmt.script = ''
|
||||||
|
@ -155,6 +164,10 @@ with lib;
|
||||||
home-files/.mozilla/firefox/test/user.js \
|
home-files/.mozilla/firefox/test/user.js \
|
||||||
${./profile-settings-expected-user.js}
|
${./profile-settings-expected-user.js}
|
||||||
|
|
||||||
|
assertFileContent \
|
||||||
|
home-files/.mozilla/firefox/containers/containers.json \
|
||||||
|
${./profile-settings-expected-containers.json}
|
||||||
|
|
||||||
bookmarksUserJs=$(normalizeStorePaths \
|
bookmarksUserJs=$(normalizeStorePaths \
|
||||||
home-files/.mozilla/firefox/bookmarks/user.js)
|
home-files/.mozilla/firefox/bookmarks/user.js)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue