diff --git a/modules/home/desktop/browser/firefox/default.nix b/modules/home/desktop/browser/firefox/default.nix index ab4f2e0..7dce597 100644 --- a/modules/home/desktop/browser/firefox/default.nix +++ b/modules/home/desktop/browser/firefox/default.nix @@ -1,12 +1,30 @@ { osConfig, lib, ... }: +let + inherit (builtins) map listToAttrs; + inherit (lib.lists) findFirstIndex; + cfg = osConfig.desktop.browser.firefox; + profileCfg = id: { + inherit id; + }; + profiles = listToAttrs ( + map (name: { + inherit name; + # If there are duplicate profile names, findFirstIndex will cause issues. + # We sanitize the input in nixosModules.desktop to avoid this. + value = profileCfg (findFirstIndex (x: x == name) null cfg.syncedProfiles); + }) cfg.syncedProfiles + ); +in { - config = lib.mkIf (osConfig.desktop.browser == "firefox") { + config = lib.mkIf cfg.enable { home.persistence."/persist/home/rafiq".directories = [ ".mozilla/firefox" ]; home.sessionVariables.BROWSER = "firefox"; programs.firefox = { enable = true; - profiles.rafiq.id = 0; - profiles.test.id = 1; + inherit profiles; + }; + stylix.targets.firefox = { + profileNames = cfg.syncedProfiles; }; }; } diff --git a/modules/nixos/desktop/browser/default.nix b/modules/nixos/desktop/browser/default.nix new file mode 100644 index 0000000..2122f44 --- /dev/null +++ b/modules/nixos/desktop/browser/default.nix @@ -0,0 +1,25 @@ +{ lib, config, ... }: +let + inherit (lib) mkEnableOption mkOption; + inherit (lib.types) listOf str; + inherit (lib.lists) allUnique; + cfg = config.desktop.browser; +in +{ + options.desktop.browser = { + firefox = { + enable = mkEnableOption ""; + syncedProfiles = mkOption { + type = listOf str; + default = [ ]; + }; + }; + }; + + config.assertions = [ + { + assertion = allUnique cfg.firefox.syncedProfiles; + message = "desktop.browser.firefox.syncedProfiles has duplicate elements."; + } + ]; +} diff --git a/modules/nixos/desktop/default.nix b/modules/nixos/desktop/default.nix index badd341..914e768 100644 --- a/modules/nixos/desktop/default.nix +++ b/modules/nixos/desktop/default.nix @@ -18,7 +18,6 @@ }; windowManager = lib.pantheon.mkStrOption; lockscreen = lib.pantheon.mkStrOption; - browser = lib.pantheon.mkStrOption; terminal = lib.pantheon.mkStrOption; notification-daemon = lib.pantheon.mkStrOption; launcher = lib.pantheon.mkStrOption; diff --git a/systems/x86_64-linux/desktop.nix b/systems/x86_64-linux/desktop.nix new file mode 100644 index 0000000..d35d20f --- /dev/null +++ b/systems/x86_64-linux/desktop.nix @@ -0,0 +1,28 @@ +{ + desktop = { + browser.firefox = { + enable = true; + syncedProfiles = [ + "rafiq" + "test" + ]; + }; + windowManager = "hyprland"; + terminal = "ghostty"; + lockscreen = "hyprlock"; + notification-daemon = "mako"; + launcher = "fuzzel"; + status-bar = "waybar"; + media-player = "vlc"; + mainMonitor = { + id = "desc:OOO AN-270W04K"; + scale = "2"; + resolution = "3840x2160"; + refresh-rate = "60"; + }; + enableSpotifyd = true; + enableSteam = true; + enableVR = true; + enableSunshine = true; + }; +} diff --git a/systems/x86_64-linux/mellinoe/default.nix b/systems/x86_64-linux/mellinoe/default.nix index e3f89df..26d95fd 100644 --- a/systems/x86_64-linux/mellinoe/default.nix +++ b/systems/x86_64-linux/mellinoe/default.nix @@ -1,5 +1,8 @@ -{ lib, ... }: { + imports = [ + ../common.nix + ../desktop.nix + ]; system = { hostname = "mellinoe"; @@ -14,20 +17,4 @@ }; platform = "intel"; }; - - desktop = { - windowManager = "hyprland"; - browser = "firefox"; - terminal = "ghostty"; - lockscreen = "hyprlock"; - notification-daemon = "mako"; - launcher = "fuzzel"; - status-bar = "waybar"; - mainMonitor = { - id = "BOE 0x088B"; - scale = "2"; - resolution = "1920x1280"; - refresh-rate = "60"; - }; - }; } diff --git a/systems/x86_64-linux/nemesis/default.nix b/systems/x86_64-linux/nemesis/default.nix index f8b4af4..185f794 100644 --- a/systems/x86_64-linux/nemesis/default.nix +++ b/systems/x86_64-linux/nemesis/default.nix @@ -1,9 +1,8 @@ { - lib, - ... -}: -{ - imports = lib.singleton ../common.nix; + imports = [ + ../common.nix + ../desktop.nix + ]; system = { hostname = "nemesis"; @@ -20,27 +19,6 @@ gpu = "nvidia"; }; - desktop = { - windowManager = "hyprland"; - browser = "firefox"; - terminal = "ghostty"; - lockscreen = "hyprlock"; - notification-daemon = "mako"; - launcher = "fuzzel"; - status-bar = "waybar"; - media-player = "vlc"; - mainMonitor = { - id = "desc:OOO AN-270W04K"; - scale = "2"; - resolution = "3840x2160"; - refresh-rate = "60"; - }; - enableSpotifyd = true; - enableSteam = true; - enableVR = true; - enableSunshine = true; - }; - services = { tor = { enable = true;