!wfudwzqQUiJYJnqfSY:nixos.org

NixOS Module System

81 Members
20 Servers

Load older messages


SenderMessageTime
10 Aug 2024
@mattsturg:matrix.orgMatt Sturgeon

I've opened a draft PR that does it as an evalModules arg, so it actually works without inf-recursion. I detailed this limitation in the PR description. Any feedback would be greatly appreciated!

https://github.com/NixOS/nixpkgs/pull/333799

23:30:29
13 Aug 2024
@khaneliman:matrix.orgAustin Horstman joined the room.22:45:20
14 Aug 2024
@roberthensing:matrix.orgRobert Hensing (roberth) Matt Sturgeon: would you (or anyone I guess?) be interested in completing types.record from https://github.com/NixOS/nixpkgs/pull/257511? I don't have much time for this kind of thing due to other responsibilities recently 14:41:16
@mattsturg:matrix.orgMatt Sturgeon

I also don't know how much time I can dedicate to it. I had looked at it before when exploring solutions to https://matrix.to/#/!wfudwzqQUiJYJnqfSY:nixos.org/$mVuETvj4dPJNF6ZUdVEVvWmp07L5G3X-6y0bk-NmCP4?via=nixos.org&via=matrix.org&via=nixos.dev, however I came to the conclusion it is an interesting (and useful looking) type, but not a viable solution to the problem we have in nixvim.

I'll attempt to clarify a little in my response to your (very helpful) feedback in #333799.

14:45:44
@roberthensing:matrix.orgRobert Hensing (roberth)ohh saw the OP but glossed over the matrix thread - well good to have the context in github as well I guess14:50:44
@mattsturg:matrix.orgMatt SturgeonDon't blame you, it ended up being a long thread (as usual!)14:51:11
@mattsturg:matrix.orgMatt Sturgeon

Thanks again Robert Hensing (roberth) for your feedback and for reminding me of your existing proposals!

I've posted my initial thoughts on github. And further;

Reading through your simple/minimal module eval proposal, I think that's a great solution provided defining config from outside the simple-module type looks the same as defining config for a submodule type; i.e. many of the features you mention arent supported (mkIf for instance) still work, but are handled in the "host" module system before evaluating the resulting configured modules.

Enforcing one module/option per attr level (i.e. no nested options) sounds like a reasonable simplification too.

My main concern is that "perfection" here may be acting as the enemy of "good"; i.e. your proposal is great, but will be much more effort to actually get merged into nixpkgs.

From a different perspective, there's also some simplicity in not reinventing the wheel here, just to support one small feature (config without undefined opts). While we could see this as an opportunity to design a better/faster system, we could also just use the small change for now and consider in the future how it can be improved/replaced. 🤔

15:19:50
@mattsturg:matrix.orgMatt Sturgeon

Hm, I'm not sure why I was under the impression that the record type was restricted to being flat (and can't contain sub-options or sub-records, I guess). I assume the wildcard type could also be set to something like attrsOf anything to allow recursive merging?

If we can define nested optionalFields and recursively merged wildcards I think it fits nixvim's needs.

15:29:31
@mattsturg:matrix.orgMatt Sturgeon *

Hm, I'm not sure why I was under the impression that the record type was restricted to being flat (and couldn't contain sub-options, sub-records, sub-fields?). I assume the wildcard type could also be set to something like attrsOf anything to allow recursive merging?

If we can define nested optionalFields and recursively merged wildcards I think it fits nixvim's needs.

15:30:22
@roberthensing:matrix.orgRobert Hensing (roberth)Yeah records can have any type in their fields, including other records. It's simpler, lazier and more efficient that way.16:28:23
@nbp:mozilla.orgnbpI have no time this week, I might give it a look next week if needed.16:39:28
@mattsturg:matrix.orgMatt Sturgeon I'll play around with adding optionalFields to types.record, won't have anything "finished" today though. I believe after that it's just adding docs and getting reviews? 16:42:06
@mattsturg:matrix.orgMatt Sturgeon I have a draft PR up based on Robert Hensing (roberth)'s prior work, seems to be working but haven't polished it up or thoroughly tested it yet. 17:58:12
15 Aug 2024
@mr-qubo:matrix.orgmr-qubo

I'm using modules in my nixos config. For every user in my config I write something like this:

home-manager.users.alice = {
  imports = [ ./hm-common ];
  ...
};

Is it possible to somehow extend home-manager.users. submodule so that it always includes my import, so I don't have to write it for every user?

21:51:03
@mattsturg:matrix.orgMatt Sturgeon If you just want to include hm-common for all users, have you considered home-manager's sharedModules option? 22:15:46
@nbp:mozilla.orgnbp

mr-qubo: yes, by extending the option declaration.

{lib, ...}: {
  home-manage.users = lib.mkOptions {
    type = lib.types.attrsOf (lib.types.submodules [ ./hm-common ]);
  };
}
22:26:32
@nbp:mozilla.orgnbp *

mr-qubo: yes, by extending the option declaration.

{lib, ...}: {
  options.home-manage.users = lib.mkOptions {
    type = lib.types.attrsOf (lib.types.submodules [ ./hm-common ]);
  };
}
22:29:01
16 Aug 2024
@sebtm:lodere.esSebTMHey, I'm trying to access pkgs.system in a nixosModule for "imports" to determinate if I want to load a certain module based on x86 or aarch64 - but it goes to infinite recursion encountered while when using it in e.g. options it works? (tested with builtins.trace) 07:44:07
@mattsturg:matrix.orgMatt Sturgeon

pkgs is not fixed when evaluating imports, in fact nothing that depends on options or config is, including config._module.args.pkgs.

One approach would be to always load the module, but only enable its options on certain systems.

12:24:53
@mattsturg:matrix.orgMatt Sturgeon

Another approach would be to check system outside of the module eval. E.g. if you're using lib.evalModules you could do:

lib.evalModules {
  modules = [
    ./common.nix
  ]
  ++ lib.optionals (system == "some-system") [
    ./system-specific.nix
  ];
}

(Same applies to wrappers, such as lib.nixosSystem)

14:26:54
17 Aug 2024
@mattsturg:matrix.orgMatt Sturgeon *

Another approach would be to check system outside of the module eval. E.g. if you're using lib.evalModules you could do:

lib.evalModules {
  modules = [
    ./common.nix
  ]
  ++ lib.optionals (system == "some-system") [
    ./system-specific.nix
  ];
}

(Same applies to wrappers, such as lib.nixosSystem)

SebTM

22:17:28
@mattsturg:matrix.orgMatt Sturgeon *

SebTM
pkgs is not fixed when evaluating imports, in fact nothing that depends on options or config is, including config._module.args.pkgs.

One approach would be to always load the module, but only enable its options on certain systems.

22:17:41
@mattsturg:matrix.orgMatt Sturgeon *

Another approach would be to check system outside of the module eval. E.g. if you're using lib.evalModules you could do:

lib.evalModules {
  modules = [
    ./common.nix
  ]
  ++ lib.optionals (system == "some-system") [
    ./system-specific.nix
  ];
}

(Same applies to wrappers, such as lib.nixosSystem)

22:18:02
@mattsturg:matrix.orgMatt Sturgeon

Anyone know why overriding an option-type's merge function seems to have no effect?

E.g. I have a submodule with a deprecated sub-option. Since the submodule's final value is often fully evaluated (e.g. printed to lua using lib.generators.toLua) I'd like to filter the deprecated option out of the final-merged value to prevent "used but not defined" errors.

I figured I could do something like:

fooType =
  let
    sub = types.submodule ({ config, options, ... }: {
      options.deprecatedOption = mkOption { };
    };
  in
    sub // {
      merge = loc: defs: builtins.removeAttrs (sub.merge loc defs) [
        "deprecatedOption"
      ];
    };

However this doesn't seem to have any effect, deprecatedOption is still present in fooType's final value.

For this specific example, I could use an option's apply function, but I'd like to understand the underlying issue. Implementing it in the type would also be better, as I may use it in several options.

I had a the same issue a few weeks ago when extending types.coercedTo to support deprecation warnings. I wanted to just override the merge attr, however I ended up having to copy the entire coercedTo implementation to get it working...

Seeing as mkOptionType just returns an attrset, I'm confused why overriding the merge attr seemingly doesn't affect how the type is merged in the module system.

22:31:16
@mattsturg:matrix.orgMatt Sturgeon *

Anyone know why overriding an option-type's merge function seems to have no effect?

E.g. I have a submodule with a deprecated sub-option. Since the submodule's final value is often fully evaluated (e.g. printed to lua using lib.generators.toLua) I'd like to filter the deprecated option out of the final-merged value to prevent "used but not defined" errors.

I figured I could do something like:

fooType =
  let
    sub = types.submodule ({ config, options, ... }: {
      options.deprecatedOption = mkOption { };
    });
  in
    sub // {
      merge = loc: defs: builtins.removeAttrs (sub.merge loc defs) [
        "deprecatedOption"
      ];
    };

However this doesn't seem to have any effect, deprecatedOption is still present in fooType's final value.

For this specific example, I could use an option's apply function, but I'd like to understand the underlying issue. Implementing it in the type would also be better, as I may use it in several options.

I had a the same issue a few weeks ago when extending types.coercedTo to support deprecation warnings. I wanted to just override the merge attr, however I ended up having to copy the entire coercedTo implementation to get it working...

Seeing as mkOptionType just returns an attrset, I'm confused why overriding the merge attr seemingly doesn't affect how the type is merged in the module system.

22:32:23
@mattsturg:matrix.orgMatt Sturgeon *

Anyone know why overriding an option-type's merge function seems to have no effect?

E.g. I have a submodule with a deprecated sub-option. Since the submodule's final value is often fully evaluated (e.g. printed to lua using lib.generators.toLua) I'd like to filter the deprecated option out of the final-merged value to prevent "used but not defined" errors.

I figured I could do something like:

fooType =
  let
    sub = types.submodule ({ config, options, ... }: {
      options.deprecatedOption = mkOption { };
    });
  in
    sub // {
      merge = loc: defs: builtins.removeAttrs (sub.merge loc defs) [
        "deprecatedOption"
      ];
    };

However this doesn't seem to have any effect, deprecatedOption is still present in fooType's final value. Calling trace in the overridden merge function doesn't print anything either.

For this specific example, I could use an option's apply function, but I'd like to understand the underlying issue. Implementing it in the type would also be better, as I may use it in several options.

I had a the same issue a few weeks ago when extending types.coercedTo to support deprecation warnings. I wanted to just override the merge attr, however I ended up having to copy the entire coercedTo implementation to get it working...

Seeing as mkOptionType just returns an attrset, I'm confused why overriding the merge attr seemingly doesn't affect how the type is merged in the module system.

22:33:54
18 Aug 2024
@sebtm:lodere.esSebTM
In reply to @mattsturg:matrix.org

Another approach would be to check system outside of the module eval. E.g. if you're using lib.evalModules you could do:

lib.evalModules {
  modules = [
    ./common.nix
  ]
  ++ lib.optionals (system == "some-system") [
    ./system-specific.nix
  ];
}

(Same applies to wrappers, such as lib.nixosSystem)

Awesome thanks for explaining ✌🏻👌🏻🙏
07:38:58
@r3vx:matrix.orgr3vx joined the room.14:18:31
22 Aug 2024
@asmundesen:matrix.orgArtur Manuel joined the room.13:04:02
@asmundesen:matrix.orgArtur Manuel changed their profile picture.14:52:58

Show newer messages


Back to Room ListRoom Version: 10