community.general icon indicating copy to clipboard operation
community.general copied to clipboard

Add a module for Nix package manager (nix-env, nix-channel)

Open Jackenmen opened this issue 1 year ago • 1 comments

Summary

This collection has modules for many OS package managers but there isn't one for Nix.

Nix is a standalone package manager that can be installed on Linux and macOS (and it also ships with NixOS though I don't feel like users of NixOS which is already using declarative system configuration would want to use Ansible?). The fact that nix packages can be installed on pretty much any Linux distro (+ macOS) makes it a compelling option for package maintainers as packaging for Nix means that they don't have to ship packages for all distros. Nix installs packages in package-specific directories (/nix/store/...) rather than "global" locations (/usr/bin) which keeps them isolated from each other. There's no sandboxing like with flatpak or snap however which some can see as a disadvantage but it does help with making packages just work without changes specific to the install method like in flatpak and snap case.

The reason why I think such a module would be a reasonable addition to this repository is the support for many other package management tools in this repository as well as the broadness of the available packages in the Nix Packages collection - over 70k packages: https://repology.org/repositories/statistics/total

The package versions are generally also newer than what you get with official repositories on distros such as Fedora or Ubuntu (assuming the package is even available there).

Issue Type

Feature Idea

Component Name

nix_channel, nix_env

Additional Information

- name: playbook name
  hosts: localhost
  tasks:
    - name: install python37
      # after confirming package isn't already installed, this runs something like:
      # nix-env -iA nixpkgs.python37
      community.general.nix_env:
        name: nixpkgs.python37
        state: present
    - name: install/upgrade spicetify-cli
      # this runs something like:
      # nix-env -uA nixpkgs.spicetify-cli
      community.general.nix_env:
        name: nixpkgs.spicetify-cli
        state: latest

    - name: add nixpkgs-unstable channel
      # this runs something like:
      # nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs-unstable
      # nix-channel --update nixpkgs-unstable
      community.general.nix_channel:
        # name can be omitted - by default `nix-channel` derives it from URL
        name: nixpkgs-unstable
        url: https://nixos.org/channels/nixpkgs-unstable
        state: present
        update: true  # defaults to `false`
    # if `update: true` wasn't specified in previous command,
    # update can also be done as shown below:
    - name: update channels
      # this runs something like:
      # nix-channel --update nixpkgs-unstable
      community.general.nix_channel:
        # name is optional, all channels are updated by default
        name:
          - nixpkgs-unstable
        update: true
    - name: install Chrome Beta from nixpkgs-unstable
      # after confirming package isn't already installed, this runs something like:
      # nix-env -iA nixpkgs-unstable.google-chrome-beta
      community.general.nix_env:
        name: nixpkgs-unstable.google-chrome-beta
        state: present
    - name: uninstall Chrome Beta
      # this runs something like:
      # nix-env -e google-chrome-beta
      community.general.nix_env:
        name: google-chrome-beta
        state: absent

    - name: remove nixpkgs-unstable channel
      # this runs something like:
      # nix-channel --remove nixpkgs-unstable
      community.general.nix_channel:
        name: nixpkgs-unstable
        state: absent

# etc...

Code of Conduct

  • [X] I agree to follow the Ansible Code of Conduct

Jackenmen avatar Aug 04 '22 20:08 Jackenmen

Files identified in the description: None

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot avatar Aug 04 '22 20:08 ansibullbot