diff --git a/flake.nix b/flake.nix index 7da388c..1d66787 100644 --- a/flake.nix +++ b/flake.nix @@ -13,10 +13,10 @@ { formatter = forAllSystems (system: nixos.legacyPackages.${system}.nixfmt-tree); - hmModules = import ./modules/home-manager self.lib; + hmModules = import ./modules/home-manager self.lib.hylonix; lib = import ./lib (nixos.lib // self.lib); - nixosModules = import ./modules/nixos self.lib; + nixosModules = import ./modules/nixos self.lib.hylonix; }; } diff --git a/lib/default.nix b/lib/default.nix index aa298b3..88086be 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -23,7 +23,9 @@ lib: { f; recursiveMergeAll = builtins.foldl' lib.hylonix.recursiveMerge null; + + compose = lib.trivial.flip (lib.foldr lib.trivial.id); }; - inherit (lib.hylonix) recursiveMerge recursiveMergeAll; + inherit (lib.hylonix) compose recursiveMerge recursiveMergeAll; } diff --git a/modules/home-manager/gecko-browser/gecko-lib/extensions.nix b/modules/home-manager/gecko-browser/gecko-lib/extensions.nix index 8e32fe6..f1cbbaa 100644 --- a/modules/home-manager/gecko-browser/gecko-lib/extensions.nix +++ b/modules/home-manager/gecko-browser/gecko-lib/extensions.nix @@ -1,6 +1,7 @@ { pkgs, lib, + sLib, info, ... }: @@ -12,24 +13,28 @@ let options = { packages = lib.mkOption { type = - lib.types.listOf - <| lib.types.either lib.types.package - <| lib.types.submodule { - options = { - name = lib.mkOption { - type = lib.types.str; - default = name; - example = "ublock-origin"; - description = "The short name of the extension. To find the short name look at the extension's download link."; - }; + sLib.compose + [ + lib.types.listOf + (lib.types.either lib.types.package) + (lib.types.submodule) + ] + { + options = { + name = lib.mkOption { + type = lib.types.str; + default = name; + example = "ublock-origin"; + description = "The short name of the extension. To find the short name look at the extension's download link."; + }; - guid = lib.mkOption { - type = lib.types.str; - example = "uBlock0@raymondhill.net"; - description = "The guid of the extension. To find the guid go to https://addons.mozilla.org/api/v5/addons/addon/\${shortName}/"; + guid = lib.mkOption { + type = lib.types.str; + example = "uBlock0@raymondhill.net"; + description = "The guid of the extension. To find the guid go to https://addons.mozilla.org/api/v5/addons/addon/\${shortName}/"; + }; }; }; - }; default = [ ]; description = '' Extensions to install for this profile. Takes either a package or a description of an extension. @@ -65,37 +70,37 @@ let x: x // lib.optionalAttrs (x ? adminSettings) { - adminSettings = + adminSettings = sLib.compose [ builtins.toJSON - <| ( + ( y: y // lib.optionalAttrs (y ? userFilters) { userFilters = builtins.concatStringsSep "\n" y.userFilters; } ) - <| ( + ( y: y // lib.optionalAttrs (y ? urlFilteringString) { urlFilteringString = builtins.concatStringsSep "\n" y.urlFilteringString; } ) - <| ( + ( y: y // lib.optionalAttrs (y ? hostnameSwitchesString) { hostnameSwitchesString = builtins.concatStringsSep "\n" y.hostnameSwitchesString; } ) - <| ( + ( y: y // lib.optionalAttrs (y ? dynamicFilteringString) { dynamicFilteringString = builtins.concatStringsSep "\n" y.dynamicFilteringString; } ) - <| x.adminSettings; + ] x.adminSettings; }; }; magic = guid: magicInfo.${guid} or lib.trivial.id; @@ -123,9 +128,9 @@ in { policies = { "3rdparty".Extensions = extensions.settings; - ExtensionSettings = + ExtensionSettings = sLib.compose [ builtins.listToAttrs - <| builtins.map ( + (builtins.map ( withExtension (x: { name = x.addonId; @@ -143,8 +148,8 @@ in install_url = "https://addons.mozilla.org/firefox/downloads/latest/${x.name}/latest.xpi"; }; }) - ) - <| extensions.packages; + )) + ] extensions.packages; }; prefs."extensions.autoDisableScopes" = 0; }; @@ -152,6 +157,6 @@ in postprocess = { policies, ... }: lib.optionalAttrs (policies ? "3rdparty".Extensions) { - policies."3rdparty".Extensions = builtins.mapAttrs magic <| policies."3rdparty".Extensions or { }; + policies."3rdparty".Extensions = builtins.mapAttrs magic (policies."3rdparty".Extensions or { }); }; } diff --git a/modules/home-manager/gecko-browser/gecko-lib/prefs.nix b/modules/home-manager/gecko-browser/gecko-lib/prefs.nix index 4980cde..d45a3d5 100644 --- a/modules/home-manager/gecko-browser/gecko-lib/prefs.nix +++ b/modules/home-manager/gecko-browser/gecko-lib/prefs.nix @@ -1,6 +1,7 @@ { pkgs, lib, + sLib, info, ... }: @@ -35,15 +36,15 @@ in postprocess = { lockPref, prefs, ... }: { - prefs = - builtins.concatStringsSep "\n" - <| (x: [ "// Generated by ${info.name} module" ] ++ x) - <| lib.mapAttrsToList ( + prefs = sLib.compose [ + (builtins.concatStringsSep "\n") + (x: [ "// Generated by ${info.name} module" ] ++ x) + (lib.mapAttrsToList ( let prefFunc = if lockPref then "lockPref" else "user_pref"; in key: val: ''${prefFunc}("${key}", ${builtins.toJSON val});'' - ) - <| prefs; + )) + ] prefs; }; } diff --git a/modules/home-manager/gecko-browser/gecko-lib/profiles.nix b/modules/home-manager/gecko-browser/gecko-lib/profiles.nix index 7722c57..d7f5936 100644 --- a/modules/home-manager/gecko-browser/gecko-lib/profiles.nix +++ b/modules/home-manager/gecko-browser/gecko-lib/profiles.nix @@ -14,9 +14,17 @@ let builtins.concatMap (y: builtins.concatMap (x: f x y) xs) ys; # (Lib -> Profile -> c) -> ProfileSettings -> [c] - mapLibAndProfile = f: x: mapProduct f allLibs <| builtins.attrValues <| x; + mapLibAndProfile = + f: + sLib.compose [ + (mapProduct f allLibs) + builtins.attrValues + ]; - allLibs = builtins.attrValues <| lib.filterAttrs (k: _: k != "profiles") <| geckoLib; + allLibs = sLib.compose [ + builtins.attrValues + (lib.filterAttrs (k: _: k != "profiles")) + ] geckoLib; allLibs' = allLibs ++ [ geckoLib.profiles ]; submodule = @@ -63,24 +71,23 @@ let writeProfilesIni = configPath: profileSettings: { name = "${configPath}/profiles.ini"; - value.text = - lib.generators.toINI { } - <| - lib.mapAttrs' ( - _: v: - lib.nameValuePair "Profile${builtins.toString v.id}" { - Name = v.name; - Path = v.path; - IsRelative = 1; - Default = if v.isDefault then 1 else 0; - } - ) profileSettings - // { - General = { - StartWithLastProfile = 1; - Version = 2; - }; + value.text = lib.generators.toINI { } ( + lib.mapAttrs' ( + _: v: + lib.nameValuePair "Profile${builtins.toString v.id}" { + Name = v.name; + Path = v.path; + IsRelative = 1; + Default = if v.isDefault then 1 else 0; + } + ) profileSettings + // { + General = { + StartWithLastProfile = 1; + Version = 2; }; + } + ); }; in { @@ -92,30 +99,31 @@ in getDefaultProfileName = profileSettings: - builtins.head - <| builtins.filter (x: profileSettings.${x}.isDefault) - <| builtins.attrNames - <| profileSettings; + sLib.compose [ + builtins.head + (builtins.filter (x: profileSettings.${x}.isDefault)) + builtins.attrNames + ] profileSettings; process = { languagePacks, ... }: let - extractVersion = + extractVersion = sLib.compose [ (x: if x == [ ] then info.base.version else builtins.head x) - <| builtins.match "([^-]*)-.*" - <| info.base.version; + (builtins.match "([^-]*)-.*") + ] info.base.version; in { - policies.ExtensionSettings = + policies.ExtensionSettings = sLib.compose [ builtins.listToAttrs - <| builtins.map (lang: { + (builtins.map (lang: { name = "langpack-${lang}@firefox.mozilla.org"; value = { installation_mode = "force_installed"; install_url = "https://releases.mozilla.org/pub/firefox/releases/${extractVersion}/linux-x86_64/xpi/${lang}.xpi"; }; - }) - <| languagePacks; + })) + ] languagePacks; }; assertions = profiles: [ @@ -124,12 +132,12 @@ in message = "No profiles are defined."; } { - assertion = + assertion = sLib.compose [ (x: x == 1) - <| builtins.length - <| builtins.filter (x: profiles.${x}.isDefault) - <| builtins.attrNames - <| profiles; + builtins.length + (builtins.filter (x: profiles.${x}.isDefault)) + builtins.attrNames + ] profiles; message = "One, and only one, profile must be marked as 'isDefault'. If you have not set this option on any profile, then one and only one profile must have id '0'."; } ]; @@ -141,15 +149,21 @@ in let processLevel = level: userConfig: - sLib.recursiveMergeAll - <| (x: [ userConfig ] ++ x) - <| builtins.map (myLib: (myLib.${level} or (_: { })) userConfig) - <| allLibs'; + sLib.compose [ + sLib.recursiveMergeAll + (x: [ userConfig ] ++ x) + (builtins.map (myLib: (myLib.${level} or (_: { })) userConfig)) + ] allLibs'; # Internal libraries can create their own configuration that needs to be merged # into the user configuration (the user's takes priority). Generate that config. finalConfig = builtins.mapAttrs ( - _: v: processLevel "postprocess" <| processLevel "process" <| processLevel "preprocess" <| v + _: + sLib.compose [ + (processLevel "postprocess") + (processLevel "process") + (processLevel "preprocess") + ] ) profiles; in { diff --git a/modules/home-manager/gecko-browser/gecko-lib/search.nix b/modules/home-manager/gecko-browser/gecko-lib/search.nix index 50292d6..87c9e84 100644 --- a/modules/home-manager/gecko-browser/gecko-lib/search.nix +++ b/modules/home-manager/gecko-browser/gecko-lib/search.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ lib, sLib, ... }: let submodule = @@ -80,8 +80,10 @@ let icon, }: let - params = - builtins.concatStringsSep "&" <| builtins.map (x: "${x.key}=${x.value}") <| searchUri.params; + params = sLib.compose [ + (builtins.concatStringsSep "&") + (builtins.map (x: "${x.key}=${x.value}")) + ] searchUri.params; in { Name = name; diff --git a/modules/home-manager/gecko-browser/gecko-lib/site-settings.nix b/modules/home-manager/gecko-browser/gecko-lib/site-settings.nix index b9ff736..21dc972 100644 --- a/modules/home-manager/gecko-browser/gecko-lib/site-settings.nix +++ b/modules/home-manager/gecko-browser/gecko-lib/site-settings.nix @@ -150,15 +150,16 @@ in filterCookies = x: - builtins.concatLists - <| lib.mapAttrsToList ( - k: v: - if builtins.elem v.cookies x then - [ "https://${k}/" ] ++ lib.optional (!v.https-only) "http://${k}/" - else - [ ] - ) - <| site; + sLib.compose [ + builtins.concatLists + (lib.mapAttrsToList ( + k: v: + if builtins.elem v.cookies x then + [ "https://${k}/" ] ++ lib.optional (!v.https-only) "http://${k}/" + else + [ ] + )) + ] site; makeUboConf = domain: config: { adminSettings = { @@ -204,7 +205,8 @@ in true ]; }; - extensions.settings."uBlock0@raymondhill.net" = - sLib.recursiveMergeAll <| [ (makeUboConf "*" default) ] ++ lib.mapAttrsToList makeUboConf site; + extensions.settings."uBlock0@raymondhill.net" = sLib.recursiveMergeAll ( + [ (makeUboConf "*" default) ] ++ lib.mapAttrsToList makeUboConf site + ); }; }