!wfudwzqQUiJYJnqfSY:nixos.org

NixOS Module System

156 Members
31 Servers

Load older messages


SenderMessageTime
18 Jan 2026
@nam3l33ss:matrix.org·☽•Nameless☆•777 · ± changed their profile picture.14:58:52
@isabel:isabelroses.comisabel changed their profile picture.20:43:36
19 Jan 2026
@mpuppe:matrix.orgmpuppe joined the room.21:20:37
21 Jan 2026
@bake.monorail:matrix.orgbake.monorail is there anything more specific than types.str I can use for a version number that I will later compare with lib.versionAtLeast? 20:39:57
@mattsturg:matrix.orgMatt Sturgeon

In string types we have strMatching, however that expects a regex not a predicate function.

The general solution is addCheck (see extending types), however the examples there don't show that you typically also want to extend/override the type's description.

20:46:28
@bake.monorail:matrix.orgbake.monorail yeah, I went with strMatching, but I was hoping to have a type matching exactly what versionAtLeast would accept, but I guess there's no such a thing 20:50:21
@bake.monorail:matrix.orgbake.monorail versionAtLeast under the hood uses builtins.compareVersions, which seems to accept anything, probably it has a last-resort method comparison that's just lexicographic comparison 20:53:24
8 Feb 2024
@aciceri:nixos.devzrsk joined the room.10:38:02
15 Feb 2024
@a-kenji:matrix.orga-kenji joined the room.19:15:14
16 Feb 2024
@qyriad:matrix.orgQyriad joined the room.14:56:15
@mr-qubo:matrix.orgmr-qubo joined the room.14:59:24
@mr-qubo:matrix.orgmr-qubo

I recently stumbled upon similar issue when working on home-manager. https://discourse.nixos.org/t/is-it-possible-to-define-systemd-services-in-a-submodule/39538/5

The idea is that enabling https://nix-community.github.io/home-manager/options.xhtml#opt-programs.bash.enableCompletion should set environment.pathsToLink = [ "/share/bash-completion" ];.

I think that module system is missing an option to pass config options recursively up to all ancestors.

15:06:01
@mr-qubo:matrix.orgmr-qubo My idea is that nixos config could have a property extraNixosChildConfig and in home-manager bash module I could set _recurseAncestors = { extraNixosChildConfig = { environment.pathsToLink = [ ... ]; }; }. 15:07:22
@mr-qubo:matrix.orgmr-qubowdyt?15:07:26
@mr-qubo:matrix.orgmr-qubo * My idea is that nixos config could have a property extraNixosChildConfig that gets merged with the rest of the config and in home-manager bash module I could set _recurseAncestors = { extraNixosChildConfig = { environment.pathsToLink = [ ... ]; }; }. 15:07:44
@mr-qubo:matrix.orgmr-qubo * My idea is that nixos config could pick up extraNixosChildConfig from childs and merge it with the rest of the config and in home-manager bash module I could set _recurseAncestors = { extraNixosChildConfig = { environment.pathsToLink = [ ... ]; }; }. 15:08:21
@infinisil:matrix.orginfinisilNot sure about that recursive thing, that doesn't seem necessary, but yeah if there's something missing in the NixOS module for home-manager, that could be added15:34:09
@infinisil:matrix.orginfinisilSounds like an issue for the home-manager repo15:34:16
@mr-qubo:matrix.orgmr-quboYeah, we could add it just for home-manager. But is seems like the issue is quite generic. See also https://github.com/NixOS/nixpkgs/pull/152785.15:51:50
@infinisil:matrix.orginfinisilHmm yeah fair. I don't have the capacity to think a lot about this right now, it's a very intricate topic to wrap ones head around15:56:55
@mr-qubo:matrix.orgmr-quboYeah, I just wanted to bring the topic, maybe someone has some interesting thoughts.16:05:23
@philiptaron:matrix.orgPhilip Taron (UTC-8) joined the room.17:49:31
20 Feb 2024
@djacu:matrix.orgdjacu

I'm reading through the module system deep dive on nix.dev and am wondering if there is a behavioral difference between setting an options default behavior in the config attribute vs the default attribute in mkOption.

this

{
  pkgs,
  lib,
  config,
  ...
}: {
  options = {
    scripts.output = lib.mkOption {
      type = lib.types.package;
    };
  };
  config = {
    scripts.output = pkgs.writeShellApplication {
      name = "map";
      runtimeInputs = with pkgs; [curl feh];
      text = ''
        ${./map} ${lib.concatStringsSep " "
          config.requestParams} | feh -
      '';
    };
  };
}

vs this

{
  pkgs,
  lib,
  config,
  ...
}: {
  options = {
    scripts.output = lib.mkOption {
      type = lib.types.package;
      default = pkgs.writeShellApplication {
        name = "map";
        runtimeInputs = with pkgs; [curl feh];
        text = ''
          ${./map} ${lib.concatStringsSep " "
            config.requestParams} | feh -
        '';
      };
    };
  };
}
21:39:27
@infinisil:matrix.orginfinisil djacu: Setting a default with options.foo = lib.mkOption { default = <value>; ... } is equivalent to config.foo = lib.mkOptionDefault <value>; 23:23:21
@infinisil:matrix.orginfinisil Furthermore, default = <value> (and there's defaultText too) can get rendered in the manual, config.foo = ... can't 23:24:14
@djacu:matrix.orgdjacuRight right I forgot about the docs side. I was more focused on merge behavior. So either way they get default priority. Thanks for the explanation!23:48:23
21 Feb 2024
@infinisil:matrix.orginfinisil djacu (Well you need mkOptionDefault to get the same priority for config, which is generally not done) 11:25:22
25 Feb 2024
@olafkfreund:matrix.orgOlaf Krasicki-Freund joined the room.22:43:41
1 Mar 2024
@accelbread:matrix.orgaccelbread joined the room.04:27:37
7 Mar 2024
@djacu:matrix.orgdjacu

How does the module system handle definitions with no priority?

I've got two modules

{lib, ...}: {
  options = {
    name = lib.mkOption {
      type = lib.types.str;
    };
  };

  config = {
    name = lib.mkDefault "foo";
  };
}
{...}: {
  config = {
    name = "bar";
  };
}

If I evaluate them together, I get "bar" for the value for name. How does it handle this situation? Is is like using mkForce? Does it bypass the priority system completely?

I imagine the answer is somewhere in this function but I am having trouble working through the logic.
https://github.com/hsjobeki/nixpkgs/blob/985fc9b995c07037f6a6273bafa3526f06bb2343/lib/modules.nix#L818

On a side note, this appears to be the place where option declarations with a default attribute value use mkOptionDefault.

04:41:32

Show newer messages


Back to Room ListRoom Version: 10