!yUrHuDcxUngfTlDbiy:matrix.org

flakelight

38 Members
https://github.com/nix-community/flakelight12 Servers

Load older messages


SenderMessageTime
22 Oct 2025
@niclas:overby.meNiclas Overby Ⓝ

I have noticed that devShells evaluates all nixosConfigurations, if you refer to checks from outputs:

# devShell.nix
pkgs: pkgs.mkShell {
  packages = [
    outputs.checks.${pkgs.system}.pre-commit-check.enabledPackages
  ];
}
# checks.nix
{
  checks.pre-commit-check = {
    inputs,
    system,
    ...
  }:
    inputs.git-hooks.lib.${system}.run {
      src = ./.;
      hooks = {
        alejandra.enable = true;
        statix.enable = true;
        ruff-format.enable = true;
      };
    };
}
10:54:30
@niclas:overby.meNiclas Overby Ⓝ *

I have noticed that devShells evaluates all nixosConfigurations, if you refer to checks from outputs:

# devShell.nix
pkgs: pkgs.mkShell {
  packages = [
    outputs.checks.${pkgs.system}.pre-commit-check.enabledPackages
  ];
}
# checks.nix
{
  checks.pre-commit-check = {
    inputs,
    system,
    ...
  }:
    inputs.git-hooks.lib.${system}.run {
      src = ./.;
      hooks = {
        alejandra.enable = true;
        statix.enable = true;
        ruff-format.enable = true;
      };
    };
}
10:54:38
@niclas:overby.meNiclas Overby Ⓝflamegraph.svg
Download flamegraph.svg
10:55:30
@niclas:overby.meNiclas Overby ⓃI have made a flamegraph to demonstrate it10:55:44
@niclas:overby.meNiclas Overby Ⓝ

The offending code is in builtinModules/nixosConfigurations.nix:

      checks = foldl recursiveUpdate { } (mapAttrsToList
        (n: v: {
          # Wrapping the drv is needed as computing its name is expensive
          # If not wrapped, it slows down `nix flake show` significantly
          ${v.config.nixpkgs.system}."nixos-${n}" = v.pkgs.runCommand
            "check-nixos-${n}"
            { } "echo ${v.config.system.build.toplevel} > $out";
        })
11:19:10
@niclas:overby.meNiclas Overby Ⓝ *

The offending code is in builtinModules/nixosConfigurations.nix:

      checks = foldl recursiveUpdate { } (mapAttrsToList
        (n: v: {
          # Wrapping the drv is needed as computing its name is expensive
          # If not wrapped, it slows down `nix flake show` significantly
          ${v.config.nixpkgs.system}."nixos-${n}" = v.pkgs.runCommand
            "check-nixos-${n}"
            { } "echo ${v.config.system.build.toplevel} > $out";
        })
        configs);
11:19:36
@accelbread:matrix.orgaccelbreadhmm, i'll take a look16:13:07
@accelbread:matrix.orgaccelbreadmight need to use genAttrs16:14:12
@accelbread:matrix.orgaccelbreadDo you have a flake that reproduces this?17:01:39
@accelbread:matrix.orgaccelbreadI couldn't reproduce the issue with my nixos config at the moment. I pushed 5afd705 which cleans up the logic and slightly reduces the use of the nixos config in evaluating attrs; that may help, but unsure18:13:46
@accelbread:matrix.orgaccelbreadv.config.nixpkgs.system should be the only thing needed from each config, and evaluating just that should be fast18:14:58
@accelbread:matrix.orgaccelbread * <nixos value>.config.nixpkgs.system should be the only thing needed from each config, and evaluating just that should be fast 18:16:20
@accelbread:matrix.orgaccelbread * <nixos value>.config.nixpkgs.system should be the only thing needed from each config, and evaluating just that should be fast; rest should be lazy under evaluating the runCommand script 18:17:02
@accelbread:matrix.orgaccelbreadthough overall, for something like pre-commit, would be better to write a flakelightModule that adds options for the precommit config, generates the preconfig packages, and sets the devShell/checks using those18:27:25
@accelbread:matrix.orgaccelbreadwould make it more reusable and encapsulated18:28:05
@accelbread:matrix.orgaccelbreadupstream repo has flake-parts module; maybe they'd accept a flakelight module18:31:42
23 Oct 2025
@niclas:overby.meNiclas Overby ⓃThe graph looks different, but it still takes substantial longer time to init the devshell, because it loads all the nixosConfigurations. There are quite a lot of nixosConfigrations in the project, which might contribute to why it is slow in my project compared to yours.09:34:44
@niclas:overby.meNiclas Overby ⓃRedacted or Malformed Event09:34:48
@niclas:overby.meNiclas Overby ⓃI'm still not sure why the check is needed in the first place? It seems to be a performance footgun with projects with many nixosConfigurations.09:36:36
@niclas:overby.meNiclas Overby Ⓝflamegraph.svg
Download flamegraph.svg
09:37:48
25 Oct 2025
@niclas:overby.meNiclas Overby Ⓝ Would you still like this? 13:54:52
@accelbread:matrix.orgaccelbreadthat would help yes16:46:19
@accelbread:matrix.orgaccelbread
In reply to @niclas:overby.me
I'm still not sure why the check is needed in the first place?
It seems to be a performance footgun with projects with many nixosConfigurations.
if you have a nixos configuration, you wouldn't want nix flake check to pass if it didn't build right? same as why other packages are added to checks. though to evaluate what checks are available under checks.${systems} it needs to know the systems of the nixosConfigurations
16:49:47
@accelbread:matrix.orgaccelbreadi could add a config to not do that but trying to figure if i can make the calculation cheaper16:50:50
@accelbread:matrix.orgaccelbreadhow are you generating the graphs btw?17:40:16
@accelbread:matrix.orgaccelbreadseems passing system to nixosSystem is deprecated, so pushed some updates to use the buildSystem/targetSystem replacements instead19:31:57
@accelbread:matrix.orgaccelbreadalso perf things might depend on which nix is in use; I'm using Lix 2.93.3 at the moment19:33:04
@accelbread:matrix.orgaccelbread

I havent tested this, but heres what i'd do for integrating git-hooks.nix:

{ src, lib, config, ... }: {
  options.git-hooks = {
    type = lib.types.attrs;
    default = { };
  };

  config = {
    withOverlays = [
      (final: prev: {
        pre-commit-check = final.inputs.git-hooks.lib.${final.system}.run
          ({ inherit src; } // config.git-hooks);
      })
    ];

    checks = pkgs: { inherit (pkgs) pre-commit-hook; };

    devShell = { pre-commit-check, ... }: {
      inherit (pre-commit-check) shellHook;
      packages = pre-commit-check.enabledPackages;
    };
  };
}
20:16:31
@accelbread:matrix.orgaccelbread

can put that as nix/flakelightModules/git-hooks.nix or w/e and import the module in your flakelight config. (or if you have many repos, put this in your common config one)

Then in a flake you can use it as such:

{
  inputs = {
    flakelight.url = "github:nix-community/flakelight";
    git-hooks.url = "github:cachix/git-hooks.nix";
  };
  outputs = { flakelight, ... }@inputs: flakelight ./. {
    inherit (inputs);
    # Pull it from file, outputs.flaklightModules.git-hooks,
    # inputs.shared-flake.flakelightModules.git-hooks, or w/e
    imports = [ ./git-hooks.nix ];

    git-hooks.hooks = {
      alejandra.enable = true;
      statix.enable = true;
      ruff-format.enable = true;
    }
  };
}
20:22:34
@accelbread:matrix.orgaccelbread

You'd even be able to autoload it as nix/git-hooks.nix:

{
  hooks = {
    alejandra.enable = true;
    statix.enable = true;
    ruff-format.enable = true;
  };
}
20:23:55

Show newer messages


Back to Room ListRoom Version: 10