feat: implement nixpkgs count check in nix as package manager

This commit is contained in:
nekohepott 2026-06-17 04:16:25 +03:00
parent 5769f7a8f2
commit bec867e6b0
No known key found for this signature in database

23
main.go
View File

@ -148,16 +148,39 @@ func getHostname() string {
return fullHostname
}
func checkNix() bool {
_, err := exec.Command("sh", "-c", "command -v nix-env >/dev/null 2>&1").Output()
if err != nil {
return false
}
return true
}
func addNix() string {
out, _ := exec.Command("sh", "-c", "nix-env -q | wc -l").Output()
nixPkgs := strings.TrimSpace(string(out)) + " (nix)"
return nixPkgs
}
func getPkgs() string {
var pkgs string
haveNix := checkNix()
if strings.HasPrefix(dist, "Arch") {
out, _ := exec.Command("sh", "-c", "pacman -Qq | wc -l").Output()
if haveNix {
pkgs = strings.TrimSpace(string(out)) + " (pacman), " + addNix()
} else {
pkgs = strings.TrimSpace(string(out)) + " (pacman)"
}
return pkgs
}
if strings.HasPrefix(dist, "Debian") {
out, _ := exec.Command("sh", "-c", "dpkg -l | grep ^ii | wc -l").Output()
if haveNix {
pkgs = strings.TrimSpace(string(out)) + " (apt), " + addNix()
} else {
pkgs = strings.TrimSpace(string(out)) + " (apt)"
}
return pkgs
}
if strings.HasPrefix(dist, "NixOS") {