Skip to content

Automatically build sources #348

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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