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

lib/types: allow custom submoduleWith descriptions #173621

Merged
merged 1 commit into from
Jun 10, 2022

Conversation

ncfavier
Copy link
Member

Currently the only way to set the description for a submodule type is to use freeformType. This is not ideal as it requires setting a freeform type, and evaluates the submodule config unnecessarily. Instead, add a description argument to submoduleWith.

The motivation for this is to be able to evaluate Home Manager's NixOS module options in nixos-search with minimal evaluation. To get the description for the attrsOf hmModule type, we currently need to evaluate the whole HM module stack in order to know whether there's a freeformType to get the description from, which requires access to the pkgs argument.

I also added a trivial lib.maybe function to simplify the if x != null then x else y pattern. The name is inspired by Haskell (well, fromMaybe is more accurate) but I'm open to better suggestions.


We really need to simplify the payload/binOp logic at some point... something like

{
  op = {
    modules = concatLists;
    specialArgs = mergeDisjointAttrs;
    description = mergeEqualValues;
    # ...
  };
}

would be nice, short of a meta-type system.

lib/trivial.nix Outdated Show resolved Hide resolved
@roberth
Copy link
Member

roberth commented May 19, 2022

We really need to simplify the payload/binOp logic at some point... something like

This exists to support type merging, which is a very useful feature.

Personally, I don't like to be wrong, so I prefer to ask questions. Somewhat conversely, I like to answer whereas I don't like to refute. ☮️

would be nice, short of a meta-type system.

We do have a type for types, or did you have something else in mind?

Currently the only way to set the description for a submodule type is to
use `freeformType`. This is not ideal as it requires setting a
freeform type, and evaluates the submodule config unnecessarily.

Instead, add a `description` argument to `submoduleWith`.
@ncfavier
Copy link
Member Author

This exists to support type merging, which is a very useful feature.

I know! I'm only saying its implementation could be simplified.

We do have a type for types, or did you have something else in mind?

I guess what I mean is that currently optionType is defined using mergeOptionDecls, but the dependency should really be the other way around, with things like description or shorthandOnlyDefinesConfig as suboptions of the option type. But this sounds like a mine field of infinite recursions.

@ncfavier
Copy link
Member Author

ncfavier commented Jun 9, 2022

boop

@roberth roberth merged commit ec82f36 into NixOS:master Jun 10, 2022
@roberth
Copy link
Member

roberth commented Jun 10, 2022

Thanks!

@ncfavier ncfavier deleted the submodule-description branch June 10, 2022 09:10
@roberth roberth added the 6.topic: module system About "NixOS" module system internals label Jun 10, 2022
ncfavier added a commit to ncfavier/home-manager that referenced this pull request Jun 10, 2022
ncfavier added a commit to ncfavier/home-manager that referenced this pull request Jun 12, 2022
ncfavier added a commit to ncfavier/home-manager that referenced this pull request Jun 18, 2022
rycee pushed a commit to ncfavier/home-manager that referenced this pull request Jun 26, 2022
jevy pushed a commit to jevy/home-manager that referenced this pull request Jul 1, 2022
rycee pushed a commit to nix-community/home-manager that referenced this pull request Jul 20, 2022
Removes the hack after NixOS/nixpkgs#173621
landed.

(cherry picked from commit 0434f8e)
jevy pushed a commit to jevy/home-manager that referenced this pull request Jul 23, 2022
Removes the hack after NixOS/nixpkgs#173621
landed.

(cherry picked from commit 0434f8e)
montchr added a commit to montchr/home-manager that referenced this pull request Jul 24, 2022
Squashed commit of the following:

commit 504df6d
Author: Chris Montgomery <chris@cdom.io>
Date:   Wed Mar 16 10:54:19 2022 -0400

    gpg-agent: add launchd service for darwin

commit 572f348
Author: midchildan <git@midchildan.org>
Date:   Sun Apr 24 16:19:56 2022 +0900

    darwin: add support for 'defaults -currentHost' options

    Closes nix-community#2615

commit 1d3380a
Author: Noah Fontes <noah@noahfontes.com>
Date:   Fri Jul 22 12:29:04 2022 -0700

    flake: fix self referential lib output

    In nix-community#2859, the
    library became self-referential, so we need to use the stdlib-extended
    helper instead of importing directly.

commit d86c189
Author: Ryan Horiguchi <ryan.horiguchi@gmail.com>
Date:   Fri Jul 22 15:32:45 2022 +0200

    firefox: support showing bookmarks on toolbar

commit 218cb3a
Author: rcerc <88944439+rcerc@users.noreply.github.com>
Date:   Thu Jul 21 16:54:59 2022 -0400

    firefox: fix empty check of bookmarks list

commit f91fb47
Author: rcerc <88944439+rcerc@users.noreply.github.com>
Date:   Thu Jul 21 16:52:47 2022 -0400

    firefox: use `coercedTo` to convert bookmarks to a list

commit f47611f
Author: Robert Helgesson <robert@rycee.net>
Date:   Sat Jul 23 15:16:19 2022 +0200

    github: fix line wrapping

commit 9cf40a4
Author: Naïm Favier <n@monade.li>
Date:   Wed Jul 20 23:11:00 2022 +0200

    github: ensure using the right branch of Home Manager

commit 70d5929
Author: Naïm Favier <n@monade.li>
Date:   Fri Jun 10 11:13:27 2022 +0200

    integration-common: set hmModule's description directly

    Removes the hack after NixOS/nixpkgs#173621
    landed.

    (cherry picked from commit 0434f8e)
spacekookie pushed a commit to spacekookie/home-manager that referenced this pull request Feb 10, 2023
spacekookie pushed a commit to spacekookie/home-manager that referenced this pull request Feb 10, 2023
Removes the hack after NixOS/nixpkgs#173621
landed.

(cherry picked from commit 0434f8e)
montchr added a commit to montchr/home-manager that referenced this pull request Sep 6, 2023
Squashed commit of the following:

commit 504df6d
Author: Chris Montgomery <chris@cdom.io>
Date:   Wed Mar 16 10:54:19 2022 -0400

    gpg-agent: add launchd service for darwin

commit 572f348
Author: midchildan <git@midchildan.org>
Date:   Sun Apr 24 16:19:56 2022 +0900

    darwin: add support for 'defaults -currentHost' options

    Closes nix-community#2615

commit 1d3380a
Author: Noah Fontes <noah@noahfontes.com>
Date:   Fri Jul 22 12:29:04 2022 -0700

    flake: fix self referential lib output

    In nix-community#2859, the
    library became self-referential, so we need to use the stdlib-extended
    helper instead of importing directly.

commit d86c189
Author: Ryan Horiguchi <ryan.horiguchi@gmail.com>
Date:   Fri Jul 22 15:32:45 2022 +0200

    firefox: support showing bookmarks on toolbar

commit 218cb3a
Author: rcerc <88944439+rcerc@users.noreply.github.com>
Date:   Thu Jul 21 16:54:59 2022 -0400

    firefox: fix empty check of bookmarks list

commit f91fb47
Author: rcerc <88944439+rcerc@users.noreply.github.com>
Date:   Thu Jul 21 16:52:47 2022 -0400

    firefox: use `coercedTo` to convert bookmarks to a list

commit f47611f
Author: Robert Helgesson <robert@rycee.net>
Date:   Sat Jul 23 15:16:19 2022 +0200

    github: fix line wrapping

commit 9cf40a4
Author: Naïm Favier <n@monade.li>
Date:   Wed Jul 20 23:11:00 2022 +0200

    github: ensure using the right branch of Home Manager

commit 70d5929
Author: Naïm Favier <n@monade.li>
Date:   Fri Jun 10 11:13:27 2022 +0200

    integration-common: set hmModule's description directly

    Removes the hack after NixOS/nixpkgs#173621
    landed.

    (cherry picked from commit 0434f8e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants