Skip to content
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

Missing submodules in Nixos #64

Closed
leenaars opened this issue Feb 13, 2020 · 4 comments · Fixed by #69
Closed

Missing submodules in Nixos #64

leenaars opened this issue Feb 13, 2020 · 4 comments · Fixed by #69

Comments

@leenaars
Copy link
Contributor

It is no longer possible to build nixcloud-webservices with current nixos-unstable:

building Nix...
building the system configuration...
error: attribute 'submodule' missing, at /home/username/repo/nixcloud-webservices/modules/web/core/webserver.nix:66:39
(use '--show-trace' to show detailed location information)

@leenaars
Copy link
Contributor Author

There were some changes in modules related to nixcloud-webservices::

https://nixos.org/nixos/manual/release-notes.html#sec-release-19.09

@fgaz
Copy link
Collaborator

fgaz commented Apr 25, 2020

This prevents nixcloud-webservices to work on the newly released 20.03

@infinisil
Copy link

A couple days ago I had a discussion with @Melkor333 on IRC regarding this: https://logs.nix.samueldr.com/nixos/2020-07-12#1594566523-1594572059; where I also suggested a non-optimal solution

The change in nixpkgs that introduced this problem is my PR NixOS/nixpkgs#75031. I don't think this is a problem with the PR though, because the problematic code in nixcloud-webservices at

type = let
submodules = toplevel.options.users.users.type.getSubModules;
in lib.types.submodule (map (m: m.submodule) submodules);
(among others) relies on module system internals, which I removed in that PR: https://github.com/NixOS/nixpkgs/pull/75031/files#diff-490491facef0aa6a6dbe8ffc5bd97097L174-L184

After messing with it for a bit, here is how the same functionality can be achieved without relying on internals:

{
  options.webserver.userOptions = lib.mkOption {
    type = lib.types.submodule options.users.users.type.functor.wrapped.getSubModules;
    default = {};
  };

  config.users.users.webserver = lib.modules.mkAliasAndWrapDefsWithPriority lib.id options.webserver.userOptions;

Also, make sure to not use // for merging in the module system like in

users.${config.webserver.user} = {
inherit (config.webserver) group;
} // removeAttrs config.webserver.userOptions [ "name" "group" ];
, because it can lead to problems. Prefer mkMerge instead. And to prevent attributes from being changed, a mkForce is recommended. So in the end that part looks about like this:

{
  users.${config.webserver.user} = lib.mkMerge [
    (lib.mkForce { inherit (config.webserver) user group; })
    (lib.modules.mkAliasAndWrapDefsWithPriority lib.id options.webserver.userOptions)
  ];
}

To prevent name and group from being changed you could set group and name with a mkForce.

@Melkor333
Copy link
Contributor

Oh wow thank you for taking another look at it!! 😯 I hope I’ll have time next weekend to run the tests with this code and create a PR...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants