Convenient ways of modifying replacing a package with a modified version

I am jockeying between learning Nix fundamentals and just diving in.

I would like to modify a package that already exists in nixpkgs. The package maps one attribute set in the package definition directly to a yaml config for the package, and the goal is to insert some new yaml stuff.

I mean the relevant .nix file in nixos/modules looks like:

{ config, lib, pkgs, ... }:
options.services.myservice = {
  enable = lib.mkEnableOption "myservice";
  settings = { <... attribute set with a bunch of mkOption ...> };
}

where settings gets converted to the yaml config for the service.

The goal for me is just to hack, I’m not immediately thinking of a PR or anything. To be able to modify the package config, I could either add new mkOption in settings or hardcode some attributes directly into settings.

What I really am asking about here is what is the best way to integrate my changes into a running NixOS system. I know about two options for modifying packages: overlays or maintaining a fork of nixpkgs. I have been told in the Matrix chat that there is likely no way to add new mkOption using an overlay. I have found working with a fork to be pretty cumbersome mainly because the repository is so large. There is a delay of several seconds even cding into the repository. I am not a git guru but also played around with using a shallow clone. However, this presented other problems in rebasing the fork on origin whenever I want to resync.

So is it really true I cannot achieve my goal with an overlay? If so is there any method of locally modifying a package other than a fork? Or if I have to use a fork, are there best practices for working with the huge repository, especially when I just have some small changes? Or is it just going to be a big, slow repo?

To give a bit of a non-answer (to the broader question): unless you’re on really slow storage this is likely an indication that you have a prompt that uses one or more slow git commands every time it renders.

It won’t spare you from some git operations still being very slow, but if so you may want to try disabling it temporarily to see if the latencies are tolerable.

If so, you may have some success with gitstatusd, which is also integrated with zsh-powerlevel10k (both of these are in nixpkgs). If you have fairly minimalistic git-prompt needs, I also wrote something a little more idiomatic (though it’s currently bash only): GitHub - abathur/lilgit: a smol (quick) git status prompt plugin

Just to clear up some confusion:

I believe that what you are referring to is not a package at all, it is a module. A module may make use of packages, but it is not itself a package.

You typically import a module with

{
  imports = [ ./path/to/myservice.nix ];
}

If you want to completely replace an existing “native” module that NixOS imports implicitly, you can do it (roughly) as follows:

{
  disableModules = [ "services/category/myservice.nix" ];
  imports = [ ./path/to/myservice.nix ];
}

I’m not sure where disableModules is documented, but this may be helpful:

1 Like

I did indeed pick some stock git-aware prompt. Didn’t think of that, thanks for sharing solutions

1 Like

This did the trick for me. You’re correct I was confused about module vs. package. Thanks

1 Like