!wfudwzqQUiJYJnqfSY:nixos.org

NixOS Module System

202 Members
47 Servers

Load older messages


SenderMessageTime
5 Jun 2026
@hsjobeki:matrix.orghsjobekiSee: https://github.com/NixOS/nix/pull/13986 19:53:47
@hsjobeki:matrix.orghsjobekiTo many things to do ^^19:53:57
@mattsturg:matrix.orgMatt Sturgeonhttps://github.com/NixOS/nixpkgs/pull/52855620:17:06
@hsjobeki:matrix.orghsjobekiWe can also save on lexical scope: https://github.com/NixOS/nixpkgs/pull/52856320:27:44
@hsjobeki:matrix.orghsjobekiwith lib; with types; is used in a lot of files.20:28:16
@hsjobeki:matrix.orghsjobeki * broad with lib; with types; is used in a lot of files. 20:28:40
@hsjobeki:matrix.orghsjobeki I really want to forbid the with statement :/ 20:29:22
6 Jun 2026
@maxisthespy:matrix.orgMaxisthespyWhat profiling tool is this01:39:43
@llakala:matrix.orgllakalaNIX_SHOW_STATS=104:37:29
@llakala:matrix.orgllakala

compared via this jq script i wrote

def prettify: {
  "attrset": {
    "lookups": .nrLookups,
    "merges": .nrOpUpdates,
    "mergeCopies": .nrOpUpdateValuesCopied
  },
  "list": {
    "concats": .list.concats,
  },
  "parser": {
    expressions: .nrExprs
  },
  "memory": {
    "envs": .envs.bytes,
    "list": .list.bytes,
    "sets": .sets.bytes,
    "symbols": .symbols.bytes,
    "values": .values.bytes,
    "total": .envs.bytes + .list.bytes + .sets.bytes + .symbols.bytes + .values.bytes
  },
  "speed": {
    "primops": .nrPrimOpCalls,
    "functionCalls": .nrFunctionCalls,
    "thunksMade": .nrThunks,
    "thunksAvoided": .nrAvoided,
  }
};

def display_number:
if . == 0 then
  null
else
  if . > 0 then
    "+" + (. | tostring) + "%"
  else
    (. | tostring) + "%"
  end
end;

def percentage(places):
  # Round to the nearest n decimal places (after the decimal place)
  . * pow(10; places + 2) | round / pow(10; places) | tostring;

def display_percentage:
  if . == 0 then
    null
  else
    if . > 0 then
      "+" + (. | percentage(2)) + "%"
    else
      (. | percentage(2)) + "%"
    end
  end;


[(.[] | prettify)] as [$stats_before, $stats_after] |
reduce ($stats_before | paths(numbers)) as $path (
  $stats_after;
    setpath(
      $path;
      getpath($path) as $after |
      ($stats_before | getpath($path)) as $before |
      if $before == 0 then
        false
      else
        (($after - $before) / $before) | display_percentage
      end
    )
)
04:38:08
@worldsgonemad:matrix.orgWorldsGoneMad joined the room.19:53:22
7 Jun 2026
@likiusinik:matrix.orgLikius Inik joined the room.05:17:04
8 Jun 2026
@nbp:mozilla.orgnbp I guess we could fix listOf by checking if the elemType may contain any submodule, and use the elemType.check then. However, we should make sure the error message does not add more confusion. Such as complaining that this is not an enumerated value, while we expect a list of enumerated values. 13:00:41
@nbp:mozilla.orgnbp * I guess we could fix listOf by skipping if the elemType may contain any submodule, and use the elemType.check then. However, we should make sure the error message does not add more confusion. Such as complaining that this is not an enumerated value, while we expect a list of enumerated values. 13:00:53
@nbp:mozilla.orgnbp * I guess we could fix listOf by skipping if the elemType may contain any submodule, and use the elemType.check otherwise. However, we should make sure the error message does not add more confusion. Such as complaining that this is not an enumerated value, while we expect a list of enumerated values. 13:01:05
@johnny:yatrix.orgJohnny joined the room.22:31:59
9 Jun 2026
@aurelivia:matrix.orgaurelivia joined the room.16:07:54
@aurelivia:matrix.orgaurelivia Hello, what do I have to do to get the mk... family of functions (mkMerge, mkIf, mkOveride, mkOrder, etc.) to work within a custom option type? I'm fairly certain my merge function just wraps around existing ones and yet all of them just come through in the output unchanged and I can't understand why 16:12:39
@aurelivia:matrix.orgaurelivia If I have a mkMerge at the level just above the option type then it all seems to work but anything further into it and it doesn't 16:14:55
@hsjobeki:matrix.orghsjobekiDo you have an example what your type is trying to do? 16:15:20
@aurelivia:matrix.orgaurelivia
  nodelike = lib.mkOptionType {
    name = "nodelike";
    description = "Something that acts like a node, with attributes, a value, and children.";
    descriptionClass = "noun";
    check = val: true;
    merge = loc: defs: if (builtins.length defs == 1)
      then (builtins.head defs).value
      else (builtins.foldl' (acc: def: let
        acc-def = { value = acc.val; file = acc.file; };
        fail = throw "The option `${lib.options.showOption loc}` has conflicting option types:${lib.options.showDefs [ acc-def def ]}";
      in if (acc.type == "list")
        then if (builtins.typeOf def.value) == "list"
          then { type = "list"; file = def.file; val = (lib.types.listOf nodelike).merge loc [ acc-def def ]; }
          else if (builtins.typeOf def.value) == "set"
            then {
              type = "list"; file = def.file;
              val = (lib.types.listOf nodelike).merge loc [
                acc-def
                { value = [ def.value ]; file = def.file; }
              ];
            } else fail
        else if (acc.type == "set")
          then if (builtins.typeOf def.value) == "set"
            then { type = "set"; file = def.file; val = (lib.types.attrsOf nodelike).merge loc [ acc-def def ]; }
            else if (builtins.typeOf def.value) == "list"
              then {
                type = "list"; file = def.file;
                val = (lib.types.listOf nodelike).merge loc [
                  { value = [ acc.val ]; file = acc.file; }
                  def
                ];
              } else fail
          else if (builtins.typeOf def.value) == acc.type
            then { type = acc.type; file = def.file; val = lib.options.mergeEqualOption loc [ acc-def def ]; }
            else fail
      ) (let h = builtins.head defs; in { type = builtins.typeOf h; file = h.file; val = h.value; }) (builtins.tail defs)).val;
  };
16:15:40
@aurelivia:matrix.orgaureliviabasically XML as Nix, where you can have lists of attrsets to define multiple of a node, and if a different option defines only one, I want it to handle that gracefully16:16:32
@aurelivia:matrix.orgaurelivia* basically XML as Nix, where you can have lists of attrsets to define multiple of a node, and if a different module defines only one, I want it to handle that gracefully16:17:53
@hsjobeki:matrix.orghsjobeki A bit hard to tell from breifly reading.
Usually you call mergeDefinitions loc type defs in your type
You dont call the merge functions of other types.
16:18:31
@aurelivia:matrix.orgaureliviaIIRC I based it off of what the merge functions for attrsOf and listOf do16:20:02
@aurelivia:matrix.orgaurelivia Do you mean instead of (lib.types.attrsOf nodelike).merge loc ..., to do mergeDefinitons loc (lib.types.attrsOf nodelike) ...? 16:21:18
@hsjobeki:matrix.orghsjobekiYes16:21:43
@aurelivia:matrix.orgaureliviaalright, I'll give that a try, thanks16:22:01
@hsjobeki:matrix.orghsjobekiYou need to pass the correct type to mergeDefinitions which will be used for merging the defs16:22:29
@hsjobeki:matrix.orghsjobeki

There are some more problems in your code.

h = builtins.head defs; # -> definition :: { file, value }
type = builtins.typeOf h; # -> attrs, always
16:26:03

Show newer messages


Back to Room ListRoom Version: 10