Skip to content

Performance: Replace ./ with self flake input to improve evaluation speed #181

@anntnzrb

Description

@anntnzrb

Summary

When using snowfall-lib with mkFlake, Nix shows performance warnings suggesting faster evaluation could be achieved by replacing ./ path references with the self flake input or builtins.path.

Warning Details

warning: Copying '«github:snowfallorg/lib/02d941739f98a09e81f3d2d9b3ab08918958beac?narHash=sha256-4i9nAJEZFv7vZMmrE0YG55I3Ggrtfo5/T07JEpEZ/RM%3D»/nix/store/dmwivyifr88a7mr2f851gcm6q2ig9hbc-source' to the store again
You can make Nix evaluate faster and copy fewer files by replacing \`./.\` with the \`self\` flake input, or \`builtins.path { path = ./.; name = \"source\"; }\`

Location: «github:snowfallorg/lib/02d941739f98a09e81f3d2d9b3ab08918958beac?narHash=sha256-4i9nAJEZFv7vZMmrE0YG55I3Ggrtfo5/T07JEpEZ/RM%3D»/nix/store/dmwivyifr88a7mr2f851gcm6q2ig9hbc-source/flake.nix:21:15

Root Cause

In flake.nix line 17, snowfall-lib uses:

core-inputs =
  inputs
  // {
    src = ./.;  # <-- This causes the warning
  };

The warning originates from this usage of ./ which causes Nix to copy the entire directory tree to the store on each evaluation.

Proposed Solution

Replace the src = ./.; with one of the recommended optimizations:

Option 1: Use builtins.path (immediate fix)

core-inputs =
  inputs
  // {
    src = builtins.path { path = ./.; name = "source"; };
  };

Option 2: Use self flake input (requires architecture changes)

# Would need to investigate how to properly pass self to mkLib
# This might require changes to the mkFlake interface

Impact

  • Performance: Faster Nix evaluation times
  • Storage: Reduced unnecessary copying to Nix store
  • User Experience: Eliminates warning messages for all users
  • Frequency: Appears on every nix build, home-manager switch, etc.

Environment

  • snowfall-lib version: Latest main (commit 02d9417)
  • Nix version: 2.18+ (warnings appear in modern Nix versions)
  • Reproducible: Yes, affects all users of snowfall-lib

Additional Context

This warning appears to be related to Nix's evaluation cache improvements and affects any flake using snowfall-lib. The functionality works correctly, but the optimization would improve performance for all users.

There may be similar issues in other parts of the codebase where ./ is used instead of more optimized alternatives.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions