Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,36 @@
, deploy
, ...
} @ inputs:

let
rakePkgs = dir:
let
sieve = name: val:
(name != "default" && name != "bud" && name != "_sources");

flattenFiltered = digga.lib.flattenTree
(nixos.lib.filterAttrs sieve (digga.lib.rakeLeaves dir));
getBasename = name: nixos.lib.last (nixos.lib.splitString "." name);
in
nixos.lib.mapAttrs' (n: v: nixos.lib.nameValuePair (getBasename n) v)
flattenFiltered;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you do think an importPackages would be suitable addition to digga? Could be, but we'd have to make and discuss the use case over there.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I do, I use the rakePkgs function exclusively to build the localPackages overlay. Which builds all packages in the ./pkgs directory so I never have to touch ./pkgs/default.nix when I add a new package. I do not know how to move it into digga and function properly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could make pkgs complely default.nix-less and add add nvfetcher stuff separately.

We could also consider to teach rakeLeaves to not consider basenames starting with an underscore.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can have a quick look at the digga impl. With a little help, it shouldn't be too hard.
https://github.com/divnix/digga/blob/main/src/importers.nix

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried actually, rakePkgs is easy but I could not figure out how to make the localPackages overlay fit in there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd model it after

digga/src/importers.nix

Lines 120 to 127 in fb3497d

importOverlays = dir:
{
# Meant to output a module that sets the overlays option
# overlays order matters. mkAfter ensures those in-house
# overlays are loaded later (after external ones), so the latter
# can be modified via internal overlays
overlays = lib.mkAfter (builtins.attrValues (flattenTree (rakeLeaves dir)));
};

returning a module that can be importsed:

{
  overlays = {};
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can use rakeLeaves as is. the only (orthogonal) addition could be to skip on _ prefixes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, you could also reuse flattenTree and derive the appropriate package name from that string, and finally callPackage on its values.


localPackages = final: prev:
builtins.mapAttrs
(name: value:
let
sources = (import ./pkgs/_sources/generated.nix) {
inherit (prev) fetchurl fetchgit;
};
package = import (value);
args = builtins.intersectAttrs (builtins.functionArgs package) {
source = sources.${name};
};
in
final.callPackage package args)
(rakePkgs (./pkgs));

in
digga.lib.mkFlake
{
inherit self inputs;
Expand All @@ -78,6 +108,7 @@
agenix.overlay
nvfetcher.overlay
deploy.overlay
localPackages
./pkgs/default.nix
];
};
Expand Down
32 changes: 28 additions & 4 deletions pkgs/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
final: prev: {
# keep sources this first
sources = prev.callPackage (import ./_sources/generated.nix) { };
# then, call packages with `final.callPackage`
self: super:
let
sources = (import ./_sources/generated.nix) { inherit (self) fetchurl fetchgit; };

mkVimPlugin = plugin:
self.vimUtils.buildVimPluginFrom2Nix {
inherit (plugin) pname version src;
};

newPkgsSet = pkgSet:
let
prefix = "${pkgSet}-";

pkgSetBuilder = {
"vimPlugins" = mkVimPlugin;
}.${pkgSet};


pkgsInSources = self.lib.mapAttrs' (name: value: self.lib.nameValuePair (self.lib.removePrefix prefix name) (value)) (self.lib.filterAttrs (n: v: self.lib.hasPrefix prefix n) sources);
in
self.lib.mapAttrs (n: v: pkgSetBuilder v) pkgsInSources;

in
{
inherit sources;

vimPlugins = super.vimPlugins // (newPkgsSet "vimPlugins");

}