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

toSystemModule style functions #2240

Open
MattSturgeon opened this issue Sep 14, 2024 · 0 comments
Open

toSystemModule style functions #2240

MattSturgeon opened this issue Sep 14, 2024 · 0 comments
Labels
enhancement New feature or request tech debt Related to technical debt and/or refactoring

Comments

@MattSturgeon
Copy link
Member

Currently we expose a few "system module" wrappers for nixvim, specifically for nixos, home-manager, and nix-darwin.

We plan to promote the use of an evaluated nixvim config to access a "standalone build" of nixvim (#2210). I believe we can do something similar with the wrapper modules to.

Ideally, I would like to expose wrapper modules as "deferred module" type options in the nixvim configuration. You would then access them as <nixvim>.config.modules.homeManager for example. However, I'm not sure this is possible, because the wrapper module would need access to <nixvim>.extendModules on the fully evaluated nixvim configuration.

As an alternative, we could provide functions alongside evalNixvim, such as toHomeModule, toNixOSModule, toDarwinModule, and a more generic toSystemModule. These functions would take a nixvim configuration as input and return a system module as output.

The existing modules could make use of these functions, supplying an empty nixvim configuration as input.

Along with a nixvim configuration, we could also have additional arguments:

toSystemModule =
  {
    # name to use in `programs.<name>`,
    # or a list to specify the whole option path
    name ? "nixvim",
    # modules to import at the system level
    # e.g. `toNixOSModule` would add modules to this list
    systemModules ? [ ],
    # modules to import at the nixvim level
    # e.g. We might use this to add an `enable` option
    nixvimModules ? [ ],
    # nixvim configuration to extend
    nixvimConfig ? evalNixvim { },
    # extra specialArgs to add/override nixvim configuration's
    extraSpecialArgs ? { },
  }:
  let
    prefix = if builtins.isList name then name else [
      "programs"
      name
    ];
    finalConfig = nixvimConfig.extendModules {
      inherit prefix;
      modules = nixvimModules;
      specialArgs = extraSpecialArgs;
    };
  in
  # Return a module
  { lib, config, ... }:
  {
    _file = ./.;
    imports = systemModules;
    options = lib.setAttrByPath prefix (lib.mkOption {
      inherit (finalConfig) type;
      default = { };
      description = "Nixvim config";
    });
  }

Related issues:

@MattSturgeon MattSturgeon added enhancement New feature or request tech debt Related to technical debt and/or refactoring labels Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request tech debt Related to technical debt and/or refactoring
Projects
None yet
Development

No branches or pull requests

1 participant