How to export a flake and make it configurable

Here is my nixvim standalone configuration with flake.https://github.com/hellopoisonx/nixvim
I have exported it so it can be imported in other flake like

inputs.nixvim-conf.url = "github:hellopoisonx/nixvim"

but it seems that I can’t config it through defined options.What should I do?

If you’re asking how to selectively enable/disable options that you’ve provided in your nix-vim derivation, I’d suggest having a look at both:

  • lib.mkOption
  • lib.mkEnableOption

there are several articles worth reading, searching those terms will find them.

you will end up with some boiler plate

(example)

{ pkgs, lib, ... }:
with lib;
let
    cfg = config.nixvim.thing;
in
{
    options.nixvim.thing.enable = mkEnableOption "enable thing";
    config = mkIf cfg.enable {
...

…that can be enabled/disabled from configuration.nix or home.nix, dependent on your target installation.

In fact, I want to figure out how to config it in flake.nix just like other package. Should I use overlay instead?

You might consider asking the author of github:hercules-ci/flake-parts, it seems to be in control of your flake.

Configure what? NixOS or HM? and via what options? It doesn’t seem like you created any options, I suggest reading the first reply and the NixOS Manual.

Disclaimer: I haven’t used nixvim, so what I’m saying below is general NixOS knowledge, but should probably be applicable to your use-case as well.

You can’t configure a flake, that’s one of the downsides flakes currently have. If you want to have something configurable, the usual way to do it is to create a NixOS module, export it from your flake and then import that module into another NixOS module you want to make configurable. In your case, you could probably export your nixvimModule from this flake and then in the another flake you want to use your neovim config in, add it as an input and then and put that module in imports of your neovim config in that flake and run nixvim.makeNixvimWithModule on that — then, if you need to configure something, you should be able to set options on that module. Does this make sense for you at a high level?

1 Like