From c8431fb979bac45125123962b2f20f4229226752 Mon Sep 17 00:00:00 2001 From: DeveloperDurp Date: Fri, 30 Jun 2023 08:29:42 -0400 Subject: [PATCH] update --- local.yml | 2 +- roles/nix/defaults/main.yml | 5 ++ roles/nix/tasks/main.yml | 107 ++++++++++++++++++++++++++++++++++++ roles/nix/vars/main.yml | 3 + 4 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 roles/nix/defaults/main.yml create mode 100644 roles/nix/tasks/main.yml create mode 100644 roles/nix/vars/main.yml diff --git a/local.yml b/local.yml index 7eb7024..c6774b2 100644 --- a/local.yml +++ b/local.yml @@ -4,7 +4,7 @@ become: true roles: - - danielrolls.nix + - nix - packages # - customize # - ansibleuser diff --git a/roles/nix/defaults/main.yml b/roles/nix/defaults/main.yml new file mode 100644 index 0000000..93c4d5e --- /dev/null +++ b/roles/nix/defaults/main.yml @@ -0,0 +1,5 @@ +--- +nix_version: 2.16.1 +installer_checksum: sha512:4edf245baf9641843b6bb750a1889e0266bace6df03cf90845c9c6279db4a3c2d1d100de446550658be84ac9b6b15017b05cd792cb6ee5da7ab74b79b215fd47 +flakes: false +nix_commands: [] diff --git a/roles/nix/tasks/main.yml b/roles/nix/tasks/main.yml new file mode 100644 index 0000000..8ba519d --- /dev/null +++ b/roles/nix/tasks/main.yml @@ -0,0 +1,107 @@ + +- name: Get nix version + shell: | + . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh + nix --version + ignore_errors: true + changed_when: false + register: nix_version_output +- name: Set nix version name + set_fact: + nix_version_on_system: "{{ (nix_version_output.stdout_lines[0] | cut -d' ' -f3" + when: nix_version_output.rc == 0 +- name: Download and run installer + block: + - name: Download installer + get_url: + url: "{{ installer_path }}" + dest: /tmp + checksum: "{{ installer_checksum }}" + - name: extract installer + unarchive: + src: /tmp/{{ nix_build }}.tar.xz + remote_src: true + dest: /tmp/ + - name: Uninistall the previous nix + block: + - name: disable nix socket + service: + name: nix-daemon.socket + state: stopped + enabled: false + become: true + ignore_errors: true + - name: disable nix service + service: + name: nix-daemon.service + state: stopped + enabled: false + become: true + ignore_errors: true + - name: Remove Installed nix files + file: + state: absent + path: /nix + become: true + - name: Remove Installed nix config files + file: + state: absent + path: /etc/nix + become: true + - name: stat bash.bashrc.backup-before-nix + stat: + path: /etc/bash.bashrc.backup-before-nix + register: bash_bashrc_backup_stat + - name: Restore bash.bashrc + shell: mv /etc/bash.bashrc.backup-before-nix /etc/bash.bashrc + become: true + when: bash_bashrc_backup_stat.stat.exists + - name: stat bashrc.backup-before-nix + stat: + path: /etc/bashrc.backup-before-nix + register: bashrc_backup_stat + - name: Restore bashrc + shell: mv /etc/bashrc.backup-before-nix /etc/bashrc + become: true + when: bashrc_backup_stat.stat.exists + - name: stat zshrc.backup-before-nix + stat: + path: /etc/zshrc.backup-before-nix + register: zshrc_backup_stat + - name: Restore zshrc + shell: mv /etc/zshrc.backup-before-nix /etc/zshrc + become: true + when: zshrc_backup_stat.stat.exists + - name: stat nix.sh + stat: + path: /etc/profile.d/nix.sh.backup-before-nix + register: nixsh_backup_stat + - name: Restore nix.sh + shell: mv /etc/profile.d/nix.sh.backup-before-nix /etc/profile.d/nix.sh + become: true + when: nixsh_backup_stat.stat.exists + when: nix_version_on_system is defined and nix_version_on_system != nix_version + - name: Run the installer + become: true + ansible.builtin.shell: + cmd: ./install --daemon