NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.62k stars 13.77k forks source link

module system: No shorthand imports syntax in submodules #70638

Open roberth opened 4 years ago

roberth commented 4 years ago

Describe the bug

When importing into a submodule, imports are not recognized unless the submodule is specified as a function. Also the error message is not helpful.

Normally the syntaxes for modules are interchangable. In particular:

{
    imports = [ ./someFile.nix ];
}

is equivalent to

{...}: {
    imports = [ ./someFile.nix ];
}

This does not work for submodules.

{
    x.y = {...}: { imports = [ ./someFile.nix ]; };
}

should be equivalent to, but doesn't work when specified as

{
    x.y.imports = [ ./someFile.nix ];
}

To Reproduce

This uses Arion as an example and to provide some context as to why one might want this:

$ git clone https://github.com/hercules-ci/arion; cd arion
$ git checkout for-nixpkgs-lib-imports-issue
$ cd examples/minimal
$ NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs/archive/master.tar.gz ../../run-arion-via-nix cat --show-trace
[...]
The option `services.webserver.imports' defined in `/nix/store/sf3j91p62aznv9iy102sa0838qgjg61n-arion-0.1.0.0-data/share/ghc-8.6.4/x86_64-linux-ghc-8.6.4/arion-compose-0.1.0.0/nix/modules/composition/docker-compose.nix' does not exist.

Expected behavior

The simplification just works.

Metadata Please run nix run nixpkgs.nix-info -c nix-info -m and paste the result.

NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs/archive/master.tar.gz nix run nixpkgs.nix-info -c nix-info -m
warning: unknown setting 'sandbox-fallback'
 - system: `"x86_64-linux"`
 - host os: `Linux 5.2.13, NixOS, 19.09beta206.e6b068cd952 (Loris)`
 - multi-user?: `yes`
 - sandbox: `yes`
warning: unknown setting 'sandbox-fallback'
 - version: `nix-env (Nix) 2.2.2`
warning: unknown setting 'sandbox-fallback'
 - channels(user): `""`
warning: unknown setting 'sandbox-fallback'
 - channels(root): `"nixos-19.09beta206.e6b068cd952, nixos-19.03-19.03.173506.2dfae8e22fd, stable-18.09.2574.a7e559a5504"`
warning: unknown setting 'sandbox-fallback'
 - nixpkgs: `/nix/store/l9k8ycmrdn86a1lzgnx5c4ckld7k2l56-master.tar.gz`

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute:
# a list of nixos modules affected by the problem
module:
infinisil commented 4 years ago

With https://github.com/NixOS/nixpkgs/pull/75031 you can turn off this odd behavior for specific submodules by replacing types.submodule with types.fullSubmodule {}, see https://github.com/NixOS/nixpkgs/pull/75031#issuecomment-561993449

stale[bot] commented 4 years ago

Thank you for your contributions.

This has been automatically marked as stale because it has had no activity for 180 days.

If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.

Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse.
  3. Ask on the #nixos channel on irc.freenode.net.