HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/nix.cpython-310.pyc
o

�N�g �@s�dZddlZddlZddlZddlZddlZe�e�Z	dd�Z
dd�Zdd�Zd	d
�Z
dd�Zd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zd dd�Zdd�Zdd�ZdS)!a�
Work with Nix packages
======================

.. versionadded:: 2017.7.0

Does not require the machine to be Nixos, just have Nix installed and available
to use for the user running this command. Their profile must be located in
their home, under ``$HOME/.nix-profile/``, and the nix store, unless specially
set up, should be in ``/nix``. To easily use this with multiple users or a root
user, set up the `nix-daemon`_.

This module exposes most of the common nix operations. Currently not meant to be run as a ``pkg`` module, but explicitly as ``nix.*``.

For more information on nix, see the `nix documentation`_.

.. _`nix documentation`: https://nixos.org/nix/manual/
.. _`nix-daemon`: https://nixos.org/nix/manual/#ssec-multi-user
�NcCsXtj�tj�d�td��d�}tjj�tj�|d��r*tjj�tj�|d��r*dSdS)z6
    This only works if we have access to nix-env
    �~{}�user�.nix-profile/bin/�nix-env�nix-collect-garbageT)Fz]The `nix` binaries required cannot be found or are not installed. (`nix-store` and `nix-env`))	�os�path�join�
expanduser�format�__opts__�salt�utils�which�Znixhome�r�D/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/nix.py�__virtual__s���rc	Cs&td|dtj�d�td��id�S)zJ
    Just a convenience function for ``__salt__['cmd.run_all'](cmd)``
    zcmd.run_all�HOMErr)�env)Z__salt__rrr
rr)�cmdrrr�_run2s�rcC�0tj�tj�d�td��d�}tj�|d�gS)��
    nix-env with quiet option. By default, nix is extremely verbose and prints the build log of every package to stderr. This tells nix to
    only show changes.
    rrrr�rrr	r
rrrrrr�_nix_env;s�rcCr)z4
    Make sure we get the right nix-store, too.
    rrrrrrrrr�_nix_collect_garbageFs�rcCst�}|�d�|S)rz--no-build-output)r�append)�prrr�	_quietnixPs
rcCstj�tt�|�|��S)zH
    intersperse x into ys, with an extra element at the beginning.
    )�	itertools�chain�
from_iterable�zip�repeat)�xZysrrr�_zip_flattenZsr&cs�fdd�|D�S)z�
    gets a list of all the packages that were affected by ``operation``, splits it up (there can be multiple packages on a line), and then
    flattens that list. We make it to a list for easier parsing.
    cs&g|]}|���r|��dd��qS)�N��
startswith�split��.0�s��	operationrr�
<listcomp>fs&z"_output_format.<locals>.<listcomp>r)�outr/rr.r�_output_formatasr2cC�
|�d�S)z7
    split the ``upgrade`` responses on ``' to '``
    z to �r*�r-rrr�_format_upgradei�
r6cCr3)z]
    nix likes to quote itself in a backtick and a single quote. This just strips those.
    z'`)�stripr5rrr�
_strip_quotespr7r9cGsFt�}|�d�|�|�t|�}dd�|d��D�}dd�|D�S)a�
    Runs an update operation on the specified packages, or all packages if none is specified.

    :type pkgs: list(str)
    :param pkgs:
        List of packages to update

    :return: The upgraded packages. Example element: ``['libxslt-1.1.0', 'libxslt-1.1.10']``
    :rtype: list(tuple(str, str))

    .. code-block:: bash

        salt '*' nix.update
        salt '*' nix.update pkgs=one,two
    z	--upgradecSs*g|]}|�d�rt|jdd�d��qS)Z	upgradingr')�maxsplit)r)r6r*r+rrrr0�s��zupgrade.<locals>.<listcomp>�stderrcSsg|]	}dd�|D��qS)cS�g|]}t|��qSr�r9)r,Zs_rrrr0��z&upgrade.<locals>.<listcomp>.<listcomp>rr+rrrr0�s�rr�extendr�
splitlines)�pkgsrr1Zupgradesrrr�upgradews


�rCcOs�|�dd�}|s
dSt�}|�d�|�dd�r!|�td|��n|�|�t|�}ttj�	dd�|d�
�D���}d	d�|D�S)
a�
    Installs a single or multiple packages via nix

    :type pkgs: list(str)
    :param pkgs:
        packages to update
    :param bool attributes:
        Pass the list of packages or single package as attribues, not package names.
        default: False

    :return: Installed packages. Example element: ``gcc-3.3.2``
    :rtype: list(str)

    .. code-block:: bash

        salt '*' nix.install package [package2 ...]
        salt '*' nix.install attributes=True attr.name [attr.name2 ...]
    �
attributesFz.Plese specify a package or packages to upgradez	--installz--attrcSs&g|]}|�d�r|��dd��qS)Z
installingr'Nr(r+rrrr0����zinstall.<locals>.<listcomp>r;cSr<rr=r+rrrr0�r>)�getrrr@r&r�listr r!r"rA)rB�kwargsrDrr1Zinstallsrrr�install�s"


���
rITcCs`t�}|�d�|r|�d�|s|�d�|r|�d�t|�}dd�tjj�|dd�D�S)	aP
    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
    z--queryz--installedz--availablez--attr-pathcSsg|]}|���qSrr4r+rrrr0�r>zlist_pkgs.<locals>.<listcomp>�stdout�
)rrrr
rr r*)Z	installedrDrr1rrr�	list_pkgs�s



rLcGsHt�}|�d�|�|�t|�}|d��df}dd�|d��D�S)a
    Erases a package from the current nix profile. Nix uninstalls work differently than other package managers, and the symlinks in the
    profile are removed, while the actual package remains. There is also a ``nix.purge`` function, to clear the package cache of unused
    packages.

    :type pkgs: list(str)
    :param pkgs:
        List, single package to uninstall

    :return: Packages that have been uninstalled
    :rtype: list(str)

    .. code-block:: bash

        salt '*' nix.uninstall pkg1 [pkg2 ...]
    z--uninstallr;�uninstallingcSs&g|]}|�d�rt|��d��qS)rMr')r)r9r*r+rrrr0rEzuninstall.<locals>.<listcomp>r?)rBrr1Zfmtoutrrr�	uninstall�s


�rNcCs$t�}|�d�t|�}|d��S)a�
    Completely removed all currently 'uninstalled' packages in the nix store.

    Tells the user how many store paths were removed and how much space was freed.

    :return: How much space was freed and how many derivations were removed
    :rtype: str

    .. warning::
       This is a destructive action on the nix store.

    .. code-block:: bash

        salt '*' nix.collect_garbage
    z--delete-oldrJ)rrrrA)rr1rrr�collect_garbages
rO)TT)�__doc__r �loggingrZsalt.utils.itertoolsr
Zsalt.utils.path�	getLogger�__name__�loggerrrrrrr&r2r6r9rCrIrLrNrOrrrr�<module>s*
	


0,!