Stream: flake-parts

Topic: Overriding `lib` in flake-parts


view this post on Zulip Srid (May 16 2024 at 23:22):

I got this working so far:

  outputs = inputs:
    let
      lib = inputs.nixpkgs.lib.extend (self: super: {
        # Polyfill https://github.com/NixOS/nixpkgs/blob/ea77cefecb0ab07e61d6bde3e24c7ae6820b96d5/lib/attrsets.nix#L360
        concatMapAttrs = with self; f: v:
          foldl' mergeAttrs { }
            (attrValues
              (mapAttrs f v)
            );
      });
      specialArgs = { inherit lib; };
    in
    inputs.flake-parts.lib.mkFlake { inherit inputs specialArgs; } {

However, this leads to error: attribute 'fileset' missing.

For some reason, fileset attribute gets lost.

view this post on Zulip Srid (May 16 2024 at 23:31):

After the addition of the following to the lib overlay (with a 2nd nixpkgs, nixpkgs-latest, added),

fileset = inputs.nixpkgs-latest.lib.fileset;

it works.

view this post on Zulip Srid (May 16 2024 at 23:33):

More concisely,

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
    nixpkgs-latest.url = "github:nixos/nixpkgs/nixpkgs-unstable";
    ...
  };
  outputs = inputs:
    let
      specialArgs.lib = inputs.nixpkgs.lib.extend (self: _: {
        # Polyfill what's missing in our `inputs.nixpkgs`.
        inherit (inputs.nixpkgs-latest.lib)
          concatMapAttrs
          fileset;
      });
    in
    inputs.flake-parts.lib.mkFlake { inherit inputs specialArgs; } {
      ...

view this post on Zulip Srid (May 16 2024 at 23:37):

Wait, that didn't quite work for treefmt-nix, when using its devShell.

view this post on Zulip Srid (May 16 2024 at 23:39):

We also need,

        _module.args.pkgs = import inputs.nixpkgs {
          inherit system;
          overlays = [
            (self: super: {
              lib = lib;
            })
          ];
        };

view this post on Zulip Srid (May 16 2024 at 23:42):

Alright, here's the final thing:

        _module.args.pkgs = import inputs.nixpkgs {
          inherit system;
          overlays = [
            (self: super: {
              lib = super.lib.extend (self: super: {
                inherit (inputs.nixpkgs-latest.lib) concatMapAttrs;
              });
            })
          ];
        };

view this post on Zulip Srid (Jul 03 2024 at 15:25):

https://github.com/hercules-ci/flake-parts/discussions/234


Last updated: Nov 21 2024 at 09:35 UTC