-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set module class to "homeManager"
#5339
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This enables a module system feature documented here: https://nixos.org/manual/nixpkgs/stable/index.html#module-system-lib-evalModules-param-class For example, it allows a mistake to be caught, which is loading a NixOS module into home-manager. This only works when the offending module declares what it's for with a `_class` attribute. It is not expected that users declare the `_type`, because the payoff is small. It is only expected to be set by generic code, such as functions or libraries that help with the "publishing" of modules (e.g. flake-parts, flake-utils). The class feature has been available in the module system since NixOS/nixpkgs#197547, merged May 6, 2023. It has been part of all releases since 23.05-beta. The last NixOS release that did _not_ support it has been end-of-life for close to a year now. Example: (lib.homeManagerConfiguration { pkgs = nixpkgs.legacyPackages.x86_64-linux; modules = [{ _class = "nixos"; imports = [ ./foo.nix ]; }]; }).activation-script Corresponding error: error: The module <unknown-file> was imported into homeManager instead of nixos. (`<unknown-file>` can be improved by also setting `_file`, if known; a much older feature)
rycee
pushed a commit
that referenced
this pull request
Apr 27, 2024
This enables a module system feature documented here: https://nixos.org/manual/nixpkgs/stable/index.html#module-system-lib-evalModules-param-class For example, it allows a mistake to be caught, which is loading a NixOS module into home-manager. This only works when the offending module declares what it's for with a `_class` attribute. It is not expected that users declare the `_type`, because the payoff is small. It is only expected to be set by generic code, such as functions or libraries that help with the "publishing" of modules (e.g. flake-parts, flake-utils). The class feature has been available in the module system since NixOS/nixpkgs#197547, merged May 6, 2023. It has been part of all releases since 23.05-beta. The last NixOS release that did _not_ support it has been end-of-life for close to a year now. Example: (lib.homeManagerConfiguration { pkgs = nixpkgs.legacyPackages.x86_64-linux; modules = [{ _class = "nixos"; imports = [ ./foo.nix ]; }]; }).activation-script Corresponding error: error: The module <unknown-file> was imported into homeManager instead of nixos. (`<unknown-file>` can be improved by also setting `_file`, if known; a much older feature) PR #5339
Thanks! Looks great. Rebased to master in 26e72d8. |
Ok, great, thanks! |
Noodlez1232
pushed a commit
to Noodlez1232/home-manager
that referenced
this pull request
Nov 21, 2024
This enables a module system feature documented here: https://nixos.org/manual/nixpkgs/stable/index.html#module-system-lib-evalModules-param-class For example, it allows a mistake to be caught, which is loading a NixOS module into home-manager. This only works when the offending module declares what it's for with a `_class` attribute. It is not expected that users declare the `_type`, because the payoff is small. It is only expected to be set by generic code, such as functions or libraries that help with the "publishing" of modules (e.g. flake-parts, flake-utils). The class feature has been available in the module system since NixOS/nixpkgs#197547, merged May 6, 2023. It has been part of all releases since 23.05-beta. The last NixOS release that did _not_ support it has been end-of-life for close to a year now. Example: (lib.homeManagerConfiguration { pkgs = nixpkgs.legacyPackages.x86_64-linux; modules = [{ _class = "nixos"; imports = [ ./foo.nix ]; }]; }).activation-script Corresponding error: error: The module <unknown-file> was imported into homeManager instead of nixos. (`<unknown-file>` can be improved by also setting `_file`, if known; a much older feature) PR nix-community#5339
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Enable a basic type check for module imports, so that a simple error appears when e.g. a NixOS module is loaded into Home Manager.
While currently almost no modules are "typed" like this yet, this will increase to a non-zero fraction, so supporting this feature will be beneficial.
It is important for applications (including Home Manager) to initiate this improvement, by choosing a name for
class
, as we can not expect others to guess the name and hope for the best.Description
This enables a module system feature documented here: https://nixos.org/manual/nixpkgs/stable/index.html#module-system-lib-evalModules-param-class
For example, it allows a mistake to be caught, which is loading a NixOS module into home-manager. This only works when the offending module declares what it's for with a
_class
attribute.It is not expected that users declare the
_type
, because the payoff is small. It is only expected to be set by generic code, such as functions or libraries that help with the "publishing" of modules (e.g. flake-parts, flake-utils).The class feature has been available in the module system since NixOS/nixpkgs#197547, merged May 6, 2023. It has been part of all releases since 23.05-beta. The last NixOS release that did not support it has been end-of-life for close to a year now.
Example:
Corresponding error:
(
<unknown-file>
can be improved by also setting_file
, if known;a much older feature)
Checklist
Change is backwards compatible.
lib
23.05.Code formatted with
./format
.Code tested through
nix-shell --pure tests -A run.all
ornix develop --ignore-environment .#all
using Flakes.grep -v OK
. Would appreciate a summary of the test result at the end.Test cases updated/added. See example.
homeManagerConfiguration
ormodules/default.nix
) is tested.Commit messages are formatted like
See CONTRIBUTING for more information and recent commit messages for examples.
If this PR adds a new module
Maintainer CC