!wfudwzqQUiJYJnqfSY:nixos.org

NixOS Module System

186 Members
40 Servers

You have reached the beginning of time (for this room).


SenderMessageTime
27 May 2024
@infinidoge:inx.moeInfinidoge 🏳️‍⚧️ Probably the easiest way to accomplish something like this would be to have all of the profiles imported, but control what gets applied with options

Something like:
common:
options = {
  profile1 = lib.mkOption {
    type = lib.types.bool;
    default = false;
  };
  profile2 = lib.mkOption {
    type = lib.types.bool;
    default = false;
  };
  profile3 = lib.mkOption {
    type = lib.types.bool;
    default = false;
  };
};
config = {
  # Common config here
};

profile1:
config = lib.mkIf config.profile1 {
  # Profile 1 config here
};

profile2:
config = lib.mkIf config.profile2 {
  # Profile 2 config here
};
And so on
01:34:41
@nbp:mozilla.orgnbp Sam Lehman: Yes, evalModules should capture the whole tree of imports and deduplicated moduled key property.
However, if you are using flakes, the key attribute is not initialized if the module is not listed as a path, to be imported by the module system.
09:42:10
@nbp:mozilla.orgnbp * Sam Lehman: Yes, evalModules should capture the whole tree of imports and deduplicated moduled key property.
However, if you are using flakes, and define a nixosModules within the flake.nix file, then the key attribute is not initialized to any value which can safely be deduplicated.
09:43:28
@nbp:mozilla.orgnbp infinisil: I just watch your stream from a month ago. _options used to be the default, except that it got removed in favor of toJSON / toTOML functions 🤦 17:07:25
@nbp:mozilla.orgnbp * infinisil: I just watch your stream from a month ago. _options used to be the default in submodules, except that it got removed in favor of toJSON / toTOML functions 🤦 17:07:36
@infinisil:matrix.orginfinisil

@nbp:mozilla.org Aren't you thinking of _module?

17:09:00
@infinisil:matrix.orginfinisil

I'm the one who removed that in submodules ;)

17:10:35
@nbp:mozilla.orgnbp Yes _module was one way to expose the internal details. 17:12:15
@nbp:mozilla.orgnbpThere are multiple problems to finding the declarations of a submodule option.17:12:47
@nbp:mozilla.orgnbpOne of them is the apply function, which implies that the content would be post-processed.17:13:32
@nbp:mozilla.orgnbp

Another one, which I bet nobody noticed, is that you can add submodules at the definition site:

nix-repl> (nixosConfigurations.ouessant.extendModules { modules = [ ({...}: { fileSystems."/" = {lib, ...}: { options.color = lib.mkOption { type = lib.types.str; default = "red"; }; }; }) ]; }).config.fileSystems."/".color
"red"
17:19:11

Show newer messages


Back to Room ListRoom Version: 10