Removed pipe operator.

The pipe operator '<|' was added in Nix 2.24 as experimental. In typical
nix community fashion, an eternity has passed, it's still experimental, and
they're still arguing about it. Thus, in order not to burden any users of
this flake, they have been removed.

To get this done quickly a utility function has been added called 'compose'.
It is 'lib.trivial.pipe' written in reverse. This eliminates any bugs and
performance regressions from unnecessary thunk evaluation.
This commit is contained in:
hylodon 2026-02-23 22:08:18 +00:00
parent 0f0c4c7727
commit 2a5ced3905
7 changed files with 115 additions and 89 deletions

View file

@ -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;
};
}

View file

@ -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;
}

View file

@ -1,6 +1,7 @@
{
pkgs,
lib,
sLib,
info,
...
}:
@ -12,9 +13,13 @@ let
options = {
packages = lib.mkOption {
type =
sLib.compose
[
lib.types.listOf
<| lib.types.either lib.types.package
<| lib.types.submodule {
(lib.types.either lib.types.package)
(lib.types.submodule)
]
{
options = {
name = lib.mkOption {
type = lib.types.str;
@ -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 { });
};
}

View file

@ -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;
};
}

View file

@ -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,9 +71,7 @@ let
writeProfilesIni = configPath: profileSettings: {
name = "${configPath}/profiles.ini";
value.text =
lib.generators.toINI { }
<|
value.text = lib.generators.toINI { } (
lib.mapAttrs' (
_: v:
lib.nameValuePair "Profile${builtins.toString v.id}" {
@ -80,7 +86,8 @@ let
StartWithLastProfile = 1;
Version = 2;
};
};
}
);
};
in
{
@ -92,30 +99,31 @@ in
getDefaultProfileName =
profileSettings:
sLib.compose [
builtins.head
<| builtins.filter (x: profileSettings.${x}.isDefault)
<| builtins.attrNames
<| profileSettings;
(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.compose [
sLib.recursiveMergeAll
<| (x: [ userConfig ] ++ x)
<| builtins.map (myLib: (myLib.${level} or (_: { })) userConfig)
<| allLibs';
(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
{

View file

@ -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;

View file

@ -150,15 +150,16 @@ in
filterCookies =
x:
sLib.compose [
builtins.concatLists
<| lib.mapAttrsToList (
(lib.mapAttrsToList (
k: v:
if builtins.elem v.cookies x then
[ "https://${k}/" ] ++ lib.optional (!v.https-only) "http://${k}/"
else
[ ]
)
<| site;
))
] 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
);
};
}