# std/distros

Dark Mode

- Manual
- Standard library
- Index
- Compiler docs
- Fusion docs
- devel, stable

Search:
Source Edit

This module implements the basics for Linux distribution ("distro") detection and the OS's native package manager. Its primary purpose is to produce output for Nimble packages, like:

    To complete the installation, run:

    sudo apt-get install libblas-dev
    sudo apt-get install libvoodoo

The above output could be the result of a code snippet like:

    if detectOs(Ubuntu):
      foreignDep "lbiblas-dev"
      foreignDep "libvoodoo"

See packaging for hints on distributing Nim using OS packages.

# Imports

strutils, osproc, os

# Types

    Distribution {.pure.} = enum
      Windows,                  ## some version of Windows
      Posix,                    ## some POSIX system
      MacOSX,                   ## some version of OSX
      Linux,                    ## some version of Linux
      Ubuntu, Debian, Gentoo, Fedora, RedHat, OpenSUSE, Manjaro, Elementary, Zorin,
      CentOS, Deepin, ArchLinux, Artix, Antergos, PCLinuxOS, Mageia, LXLE, Solus,
      Lite, Slackware, Androidx86, Puppy, Peppermint, Tails, AntiX, Kali,
      SparkyLinux, Apricity, BlackLab, Bodhi, TrueOS, ArchBang, KaOS, WattOS,
      Korora, Simplicity, RemixOS, OpenMandriva, Netrunner, Alpine, BlackArch,
      Ultimate, Gecko, Parrot, KNOPPIX, GhostBSD, Sabayon, Salix, Q4OS, ClearOS,
      Container, ROSA, Zenwalk, Parabola, ChaletOS, BackBox, MXLinux, Vector, Maui,
      Qubes, RancherOS, Oracle, TinyCore, Robolinux, Trisquel, Voyager, Clonezilla,
      SteamOS, Absolute, NixOS, ## NixOS or a Nix build environment
      AUSTRUMI, Arya, Porteus, AVLinux, Elive, Bluestar, SliTaz, Solaris, Chakra,
      Wifislax, Scientific, ExTiX, Rockstor, GoboLinux, Void, BSD, FreeBSD, OpenBSD,
      DragonFlyBSD, Haiku

  the list of known distributions Source Edit

# Vars

    foreignDeps: seq[string] = @[]

  Registered foreign deps. Source Edit

# Consts

    LacksDevPackages = {Distribution.Gentoo, Distribution.Slackware,
                        Distribution.ArchLinux, Distribution.Artix,
                        Distribution.Antergos, Distribution.BlackArch,
                        Distribution.ArchBang}

  Source Edit

# Procs

    proc echoForeignDeps() {....raises: [], tags: [].}

  Writes the list of registered foreign deps to stdout. Source Edit

    proc foreignCmd(cmd: string; requiresSudo = false) {....raises: [], tags: [].}

  Registers a foreign command to the internal list of commands that can be queried later. Source Edit

    proc foreignDep(foreignPackageName: string) {....raises: [], tags: [].}

  Registers `foreignPackageName` to the internal list of foreign deps. It is your job to ensure that the package name is correct. Source Edit

    proc foreignDepInstallCmd(foreignPackageName: string): (string, bool) {.
        ...raises: [], tags: [].}

  Returns the distro's native command to install `foreignPackageName` and whether it requires root/admin rights. Source Edit

# Templates

    template detectOs(d: untyped): bool

  Distro/OS detection. For convenience, the required `Distribution.` qualifier is added to the enum value. Source Edit