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.
50 lines
956 B
Nix
50 lines
956 B
Nix
{
|
|
pkgs,
|
|
lib,
|
|
sLib,
|
|
info,
|
|
...
|
|
}:
|
|
|
|
let
|
|
type = lib.types.attrsOf (
|
|
lib.types.oneOf [
|
|
lib.types.int
|
|
lib.types.bool
|
|
lib.types.str
|
|
]
|
|
);
|
|
in
|
|
{
|
|
inherit type;
|
|
|
|
options = {
|
|
prefs = lib.mkOption {
|
|
inherit type;
|
|
default = { };
|
|
description = "User preferences.";
|
|
};
|
|
|
|
lockPref = lib.mkOption {
|
|
type = lib.types.bool;
|
|
default = false;
|
|
example = true;
|
|
description = "When adding user preferences, determine whether to use lockPref over user_pref";
|
|
};
|
|
};
|
|
|
|
postprocess =
|
|
{ lockPref, prefs, ... }:
|
|
{
|
|
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;
|
|
};
|
|
}
|