From 0a0d3549621a70f39eddeae7c404f60382f99c4d Mon Sep 17 00:00:00 2001 From: technofab Date: Wed, 31 Dec 2025 17:39:01 +0100 Subject: [PATCH] chore: minor improvements like making inventory arg optional --- flake.nix | 4 +--- lib/module.nix | 17 +++++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/flake.nix b/flake.nix index dc9e417..50c4504 100644 --- a/flake.nix +++ b/flake.nix @@ -152,11 +152,9 @@ }; optionsDoc = doclib.mkOptionDocs { module = { + _module.args.pkgs = pkgs; imports = [ nblib.module - { - _module.args.pkgs = pkgs; - } ]; }; roots = [ diff --git a/lib/module.nix b/lib/module.nix index bcbe713..5624d58 100644 --- a/lib/module.nix +++ b/lib/module.nix @@ -19,7 +19,7 @@ unsetOr = typ: (types.either unsetType typ) // { - description = typ.description; + inherit (typ) description getSubOptions; }; filterUnset = value: @@ -36,7 +36,7 @@ mkOption args // { type = unsetOr args.type; - default = unset; + default = args.default or unset; defaultText = literalExpression "unset"; }; @@ -59,7 +59,7 @@ }; }; tasksType = types.submodule { - freeformType = types.attrsOf (types.attrsOf types.anything); + freeformType = types.attrsOf types.anything; options = { name = mkUnsetOption { type = types.str; @@ -118,7 +118,7 @@ }; }; playType = types.submodule { - freeformType = types.attrsOf (types.attrsOf types.anything); + freeformType = types.attrsOf types.anything; options = { name = mkOption { type = types.str; @@ -278,12 +278,17 @@ in { cli = pkgs.writeShellApplication { name = "nixible"; runtimeInputs = config.dependencies; - text = '' + text = let + inventoryStr = + if config.inventory != {} + then "-i ${config.inventoryFile}" + else ""; + in '' set -euo pipefail export ANSIBLE_COLLECTIONS_PATH=${config.installedCollections} git_repo=$(git rev-parse --show-toplevel 2>/dev/null || true) - ${config.ansiblePackage}/bin/ansible-playbook -i ${config.inventoryFile} ${config.playbookFile} -e "pwd=$(pwd)" -e "git_root=$git_repo" "$@" + ${config.ansiblePackage}/bin/ansible-playbook ${inventoryStr} ${config.playbookFile} -e "pwd=$(pwd)" -e "git_root=$git_repo" "$@" ''; }; };