[PATCH 4/8] nixos: invoke nix build through ansible.builtin.command
Daniel Gomez <[email protected]> Thu, 23 Apr 2026 00:48:42 +0200
| Newsgroups | dev.linux.lists.kdevops |
|---|---|
| Message-ID | <20260423-kdevops-series-b-nixos-qemu-v1-4-209154ae54f8@samsung.com> |
From: Daniel Gomez <[email protected]> Drop the scripts/nixos_build_image.sh bash helper and call nix directly from an ansible.builtin.command task with argv list form. argv skips the shell, so the # flakeref fragment no longer needs hiding behind a wrapper. The helper's only reason to exist was working around that parsing ambiguity in ansible.builtin.shell. Generated-by: Claude AI Signed-off-by: Daniel Gomez <[email protected]> (cherry picked from commit 18f495c65f520b39f1aa447633a3443b68d8e26c) --- playbooks/nixos.yml | 11 +++++++++-- scripts/nixos_build_image.sh | 38 -------------------------------------- 2 files changed, 9 insertions(+), 40 deletions(-) diff --git a/playbooks/nixos.yml b/playbooks/nixos.yml index 7db0ab63..7dea931c 100644 --- a/playbooks/nixos.yml +++ b/playbooks/nixos.yml @@ -155,9 +155,16 @@ tasks: - name: Build per-node NixOS disk image via the flake ansible.builtin.command: - cmd: "{{ playbook_dir }}/../scripts/nixos_build_image.sh {{ nixos_config_dir }}/{{ item }}" + argv: + - nix + - build + - "path:{{ nixos_config_dir }}/{{ item }}#image" + - --out-link + - "{{ nixos_config_dir }}/{{ item }}/result" + creates: "{{ nixos_config_dir }}/{{ item }}/result" environment: - NIXOS_MIRROR_URL: "{{ nixos_mirror_url | default('') if (nixos_use_local_mirror | default(false) | bool) else '' }}" + PATH: "/nix/var/nix/profiles/default/bin:{{ ansible_env.PATH | default('/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin') }}" + NIX_CONFIG: "{{ ('substituters = ' ~ nixos_mirror_url ~ ' https://cache.nixos.org') if (nixos_use_local_mirror | default(false) | bool and (nixos_mirror_url | default('') | length > 0)) else omit }}" loop: "{{ groups['all'] | reject('equalto', 'localhost') | list }}" loop_control: label: "{{ item }}" diff --git a/scripts/nixos_build_image.sh b/scripts/nixos_build_image.sh deleted file mode 100755 index a4a715fc..00000000 --- a/scripts/nixos_build_image.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash -# SPDX-License-Identifier: copyleft-next-0.3.1 -# -# Build a per-node NixOS disk image from a generated kdevops flake. -# Invoked from playbooks/nixos.yml's build-vms play with a single -# argument: the per-node flake directory. -# -# Resolves the flake with a path: URL so nix does not filter the -# flake directory through git. The per-node directory lives under -# scripts/nixos-qemu/configurations/ which the nixos-qemu subtree's -# own .gitignore excludes; a plain "." or "./" flake-ref would be -# treated as git+file: and come back empty. -# -# Optional: if NIXOS_MIRROR_URL is set in the environment, the nix -# build invocation routes through that substituter in addition to -# cache.nixos.org. -set -euo pipefail - -if [ $# -ne 1 ]; then - echo "Usage: $0 <per-node-flake-directory>" >&2 - exit 1 -fi - -NODE_DIR="$1" - -if [ -f /nix/var/nix/profiles/default/etc/profile.d/nix.sh ]; then - . /nix/var/nix/profiles/default/etc/profile.d/nix.sh -fi -export PATH="/nix/var/nix/profiles/default/bin:${PATH:-/usr/local/bin:/usr/bin:/bin}" - -if [ -n "${NIXOS_MIRROR_URL:-}" ]; then - export NIX_CONFIG="substituters = ${NIXOS_MIRROR_URL} https://cache.nixos.org" -fi - -cd "$NODE_DIR" -rm -f result -nix build "path:$PWD#image" -o result -readlink -f result/nixos.qcow2 -- 2.53.0