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

module system: small eval optimization #54637

Merged
merged 3 commits into from
Jan 30, 2019

Conversation

danbst
Copy link
Contributor

@danbst danbst commented Jan 26, 2019

Motivation for this change

Small NixOS eval optimization (~2.5% runtime, ~5% memory)

  1. Replace foldl'+foldl'+ attrNames -> foldl' + mapAttrs
  2. Replace listToAttrs + mapAttrsToList -> mapAttrs
  3. Deprecate finally types.optionSet and remove some (most?) related code
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Assured whether relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@GrahamcOfBorg GrahamcOfBorg added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: changelog 8.has: documentation 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Jan 26, 2019
@infinisil
Copy link
Member

Oh nice! I didn't know the options attribute of mkOption could be fully replaced by just setting the type. This might enable me to finish my small experiment of having a proper NixOps module, bringing lots of cool stuff.

@infinisil
Copy link
Member

infinisil commented Jan 28, 2019

Can you put a more fitting description for the first 2 commits? Seems good to merge then

@danbst
Copy link
Contributor Author

danbst commented Jan 28, 2019

@infinisil should be good now

Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to take @nbp, @Profpatsch or @rycee to take a look at this as well.

One thing that could be changed is to throw an error when people pass an options argument to mkOption, this then corresponds to optionSet's behavior

@danbst
Copy link
Contributor Author

danbst commented Jan 28, 2019

options and optionSet were deprecated for 5 years at least (70a2c54#diff-2d2cc23a01923ed9f342b937c087d5b1R23). I've mentioned in release doc that we finally remove types.optionSet. Maybe I should also mention that options argument to mkOption is removed as well.

@@ -350,6 +350,12 @@
See the <literal>fish</literal> <link xlink:href="https://github.com/fish-shell/fish-shell/releases/tag/3.0.0">release notes</link> for more information.
</para>
</listitem>
<listitem>
<para>
<literal>types.optionSet</literal> is deprecated. Use <literal>types.submodule</literal>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs more strong wording since "deprecated" might imply that it is still actually working. I would suggest something like

<literal>types.optionSet</literal> has been removed after a long deprecation period. Use <literal>types.submodule</literal> instead.

I guess "removed" is not technically correct but I think it is morally correct 😉

@@ -92,23 +92,25 @@ let
exit($mainRes & 127 ? 255 : $mainRes << 8);
'';

opts =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest changing the formatting to

opts = { config, name, ... }: {
  options.runner = mkOption {
    internal = true;
    description = ''
      A script that runs the service outside of systemd,
      useful for testing or for using NixOS services outside
      of NixOS.
    '';
  };
  config.runner = makeScript name config;
};

Copy link
Member

@rycee rycee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't checked super carefully but I'm liking it a lot! Very nice to clean up this old options code.

@danbst
Copy link
Contributor Author

danbst commented Jan 30, 2019

@rycee @infinisil is release doc good now?

@GrahamcOfBorg GrahamcOfBorg added the 2.status: merge conflict This PR has merge conflicts with the target branch label Jan 30, 2019
@GrahamcOfBorg GrahamcOfBorg removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Jan 30, 2019
@danbst danbst merged commit 30c3123 into NixOS:master Jan 30, 2019
@danbst danbst deleted the small-eval-optimization branch January 30, 2019 22:42
@Profpatsch
Copy link
Member

Looks good. Am not particularly deep into the implementation of the module system. Nix needs an hlint. :P

@rycee
Copy link
Member

rycee commented Jan 31, 2019

Agreed that it looks good 👍

delroth added a commit to delroth/nixpkgs that referenced this pull request Feb 2, 2019
27982b4 introduced a bug when
refactoring the encrypted-devices module, causing some encrypted
filesystem options to not be recognized anymore.

See e.g. https://hydra.nixos.org/build/88145490
Ekleog added a commit that referenced this pull request Feb 3, 2019
* pr-55088:
  nixos/tasks/encrypted-devices: fix regression from #54637
@infinisil infinisil added the 6.topic: module system About "NixOS" module system internals label Mar 19, 2020
@infinisil infinisil mentioned this pull request Sep 4, 2020
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: module system About "NixOS" module system internals 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: changelog 8.has: documentation 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants