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
Merged

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.
@Infinisil
Copy link
Member

@Infinisil Infinisil commented Jan 26, 2019

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 Infinisil commented Jan 28, 2019

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

@danbst danbst force-pushed the small-eval-optimization branch from 37da1fc to 5747041 Jan 28, 2019
@danbst danbst requested a review from thoughtpolice as a code owner Jan 28, 2019
@danbst danbst force-pushed the small-eval-optimization branch from 5747041 to 30748a8 Jan 28, 2019
@danbst danbst removed the request for review from thoughtpolice Jan 28, 2019
@danbst
Copy link
Contributor Author

@danbst danbst commented Jan 28, 2019

@Infinisil should be good now

Copy link
Member

@Infinisil Infinisil left a comment

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 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

@rycee rycee Jan 29, 2019

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

@rycee rycee Jan 29, 2019

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

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 danbst commented Jan 30, 2019

@rycee @Infinisil is release doc good now?

@danbst danbst force-pushed the small-eval-optimization branch from 5f8106d to 27982b4 Jan 30, 2019
@danbst danbst merged commit 30c3123 into NixOS:master Jan 30, 2019
1 check was pending
@danbst danbst deleted the small-eval-optimization branch Jan 30, 2019
@Profpatsch
Copy link
Member

@Profpatsch Profpatsch commented Jan 31, 2019

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

@rycee
Copy link
Member

@rycee rycee commented Jan 31, 2019

Agreed that it looks good 👍

delroth added a commit to delroth/nixpkgs that referenced this issue 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 issue Feb 3, 2019
* pr-55088:
  nixos/tasks/encrypted-devices: fix regression from #54637
matthewbauer
Copy link
Member

matthewbauer commented on 27982b4 Mar 7, 2019

It looks like this broke nixops: NixOS/nixops#1086

We should probably look into writing some tests for nixops to catch these things sooner.

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

Successfully merging this pull request may close these issues.

None yet

6 participants