I just installed Nix Package Manager on my Mac M3 running the
sh <(curl -L https://nixos.org/nix/install)
But, then, when running just a nix run "nixpkgs#hello", the first time as it is installing the packages its takes 49 seconds, then subsequente times take around 9 seconds. This seems too much for a simple command. Funny enough if I run with --vv, besides printing the lines, it takes 6 seconds.
Is this time expected or am I missing something?
Running nix-shell with any package (eg: nix-shell -p curl), takes almost 1 minute, its a bit frustrating
The first time, nixpkgs needs to be updated, and both it and the hello program need to be resolved. The former will take about as much time as it will when executing a darwin-rebuild.
The 9 seconds on the second run is strange though. The second time I run the hello progam, immediately after the first, execution is practically instantaneous, taking 0.03s user time.
How much storage do you have in your M3 MBP? Apple has been known to skimp on the chips for lower capacities, so that might affect binary load times, although arguably nowhere near that much.
And/Or perhaps you have any software running that heavily uses your storage eg some AV program?
EDIT: here is a screenshot of the performance characteristics on my M1 MBP for both the first and second executions:
Hmm I’m noticing that the output of your time command is different from the default, and that you seem to be using fish.
Especially the latter seems to consume most of the time (if I’m reading the table correctly at least) so can you try it with the default time cmd and terminal/shell combo (iterm/zsh)? Just to eliminate both as a factor.
Well that definitely links it to something in your user environment.
Judging by your OP I can guess the answer, but just not to assume anything: are you using home-manager yet?
If not, perhaps it would be a useful exercise to try and take stock of other software you’ve manually installed on your MBP, and scrutinizing every program, no matter how innocent it seems.
I also was thinking it could be iCloud but on 2nd thought that seems unlikely, as then there shouldn’t be an improvement when using sudo.
Also, what happens when you run some other (non-nix-related) cli command, for example time ls - ahl? Does that also take more time?
Do you happen to be running this on a managed work device? Jamf Protect, Crowdstrike, and other endpoint security agents might significantly slow down Nix. If that’s the case I’d bother your IT department to see if some exemptions could be added for e.g. /nix/store to reduce the overhead.
Otherwise… this is definitely a strange one, especially since sudo seems to fix it.
I’ve been noticing poor flake performance on all Macbooks I’ve ever used Nix + Home Manager + nix-darwin on. That is with fresh installations on both architectures (Intel as well as M1 / M2 devices).