Lists installed packages. Due to how nix works, it defaults to just doing a ``nix-env -q``.

    :param bool installed:
        list only installed packages. This can be a very long list (12,000+ elements), so caution is advised.
        Default: True

    :param bool attributes:
        show the attributes of the packages when listing all packages.
        Default: True

    :return: Packages installed or available, along with their attributes.
    :rtype: list(list(str))

    .. code-block:: bash

        salt '*' nix.list_pkgs
        salt '*' nix.list_pkgs installed=False

def list_pkgs(installed=True,
              attributes=True):
    '''
    Lists installed packages. Due to how nix works, it defaults to just doing a ``nix-env -q``.

    :param bool installed:
        list only installed packages. This can be a very long list (12,000+ elements), so caution is advised.
        Default: True

    :param bool attributes:
        show the attributes of the packages when listing all packages.
        Default: True

    :return: Packages installed or available, along with their attributes.
    :rtype: list(list(str))

    .. code-block:: bash

        salt '*' nix.list_pkgs
        salt '*' nix.list_pkgs installed=False
    '''

    # We don't use -Q here, as it obfuscates the attribute names on full package listings.
    cmd = _nix_env()
    cmd.append('--query')

    if installed:
        # explicitly add this option for consistency, it's normally the default
        cmd.append('--installed')
    if not installed:
        cmd.append('--available')
        # We only show attributes if we're not doing an `installed` run.
        # The output of `nix-env -qaP` and `nix-env -qP` are vastly different:
        #    `nix-env -qaP` returns a list such as 'attr.path  name-version'
        #    `nix-env -qP` returns a list of 'installOrder  name-version'
        # Install order is useful to unambiguously select packages on a single
        # machine, but on more than one it can be a bad thing to specify.
        if attributes:
            cmd.append('--attr-path')

    out = _run(cmd)

    return [s.split() for s in salt.utils.itertools.split(out['stdout'], '\n')]