cachix / install-nix-action

Installs Nix on GitHub Actions for the supported platforms: Linux and macOS.
Apache License 2.0
498 stars 78 forks source link

Drop the need for python by using nproc --all/hw.logicalcpu_max #186

Closed Kranzes closed 1 month ago

Kranzes commented 1 year ago

on my R7 8c/16t system nproc prints 16 and nproc --all prints 32, so i think this is the same behavior.

domenkozar commented 1 year ago

It used to be nproc, but I can't remember why we ditched it.

Kranzes commented 1 year ago

It used to be nproc, but I can't remember why we ditched it.

Oh well there we have it, it doesn't exist on MacOS, that's weird. There has to be a better way to just get the core count without needing an entire python interpreter.

Kranzes commented 1 year ago

After 10 seconds of googling, sysctl -n hw.logicalcpu_max on MacOS should return the same thing as nproc --all.

Docs: https://opensource.apple.com/source/xnu/xnu-792.2.4/libkern/libkern/sysctl.h.auto.html

(I tested this via darling on my Linux host.)

[kranzes@pongo ~]$ nproc
16
[kranzes@pongo ~]$ nproc --all
32
[kranzes@pongo ~]$ sudo nix run nixpkgs#darling shell
[sudo] password for kranzes:
Bootstrapping the container with launchd...
Authorization required, but no authorization protocol specified

Authorization required, but no authorization protocol specified

Authorization required, but no authorization protocol specified

Authorization required, but no authorization protocol specified

Authorization required, but no authorization protocol specified

Authorization required, but no authorization protocol specified

The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
Darling [/Volumes/SystemRoot/home/kranzes]# sysctl -n hw.logicalcpu
16
Darling [/Volumes/SystemRoot/home/kranzes]# sysctl -n hw.logicalcpu_max
32
max-privatevoid commented 1 year ago

nproc --all seems to give weird results on at least one of my systems, and on none of them does it return twice the core count.

Physical desktop:
Model name:                      AMD Ryzen 5 2600 Six-Core Processor
CPU(s):                          12
nproc: 12
nproc --all: 32

Ampere A1 VM:
Model name:                      Neoverse-N1
CPU(s):                          4
nproc: 4
nproc --all: 4

Physical server:
Model name:                      Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz
CPU(s):                          8
nproc: 8
nproc --all: 8

Micro cloud instance:
Model name:                      AMD EPYC 7551 32-Core Processor
CPU(s):                          2
nproc: 2
nproc --all: 2

Maybe it's better to use "$(($(nproc) * 2))"?

Kranzes commented 1 year ago

Also, it seems the nix installer by default just creates 32 users and the detsys one does 32 on Darwin and auto-uid-allocation on Linux...