From 1c918657050c858a3044723e8fe3aad5b934a056 Mon Sep 17 00:00:00 2001 From: Yorick Barbanneau Date: Tue, 3 Sep 2024 00:28:20 +0200 Subject: [PATCH] feat(build): use Nix flake, go-task and lefthook --- Makefile | 60 ---------------------------------------------- Taskfile.dist.yaml | 41 +++++++++++++++++++++++++++++++ flake.lock | 60 ++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 32 +++++++++++++++++++++++++ lefthook.yaml | 21 ++++++++++++++++ 5 files changed, 154 insertions(+), 60 deletions(-) delete mode 100644 Makefile create mode 100644 Taskfile.dist.yaml create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 lefthook.yaml diff --git a/Makefile b/Makefile deleted file mode 100644 index dea8aca..0000000 --- a/Makefile +++ /dev/null @@ -1,60 +0,0 @@ -# Ansible options -ansible_user ?= ephase -ansible_roles := deps -ansible_options ?= --diff -ansible_playbook ?= playbook.yml -ansible_req ?= requirements.yml -# venv options -venv_source ?= .venv -venv_cmd := . $(venv_source)/bin/activate - -#Python -python_bin ?= python -pip_req ?= requirements.txt - -.PHONY: inventory -inventory: - ansible-inventory --graph -i inventory.ini - -deps: $(ansible_req) $(venv_source)/dep - $(shell mkdir -p $(ansible_roles)) -ifeq ($(wildcard $(ansible_req)),) - $(error there is not requirements.yml file in $(ansible_data)!) -endif - $(venv_cmd) && ansible-galaxy install \ - --ignore-errors \ - --roles-path="$(ansible_roles)" \ - --role-file="$(ansible_req)" - -.PHONY: check-syntax -check-syntax: deps - $(venv_cmd) && ansible-playbook -i inventory.ini \ - --syntax-check $(ansible_playbook) - -.PHONY: dry-run -dry-run: deps - $(venv_cmd) && ansible-playbook -i inventory.ini \ - --check $(ansible_options) $(ansible_playbook) \ - -u $(ansible_user) - -.PHONY: run -run: deps - $(venv_cmd) && ansible-playbook -i inventory.ini \ - $(ansible_options) $(ansible_playbook) \ - -u $(ansible_user) - -.PHONY: clean -clean: clean-venv - [ -d $(ansible_roles) ] && rm -rf $(ansible_roles) - -# venv management -$(venv_source): - $(python_bin) -m venv $(venv_source) - -$(venv_source)/dep: $(venv_source) $(pip_req) - touch $(venv_source)/dep - $(venv_cmd) && pip install -r $(pip_req) - -.PHONY: clean-venv -clean-venv: - [ -d $(venv_source) ] && rm -rf $(venv_source) diff --git a/Taskfile.dist.yaml b/Taskfile.dist.yaml new file mode 100644 index 0000000..d85921e --- /dev/null +++ b/Taskfile.dist.yaml @@ -0,0 +1,41 @@ +--- +version: "3" +set: [errexit, pipefail, nounset] +shopt: [globstar] +env: + ANSIBLE_OPTIONS: --diff --become-method=doas -K + ANSIBLE_PLAYBOOK: playbook.yml + ANSIBLE_USER: ephase + +tasks: + inventory: + cmds: + - ansible-inventory --graph -i inventory.ini + + dryrun: + deps: + - install:deps + cmds: + - | + ansible-playbook -i inventory.ini \ + --check {{.ANSIBLE_OPTIONS}} {{.ANSIBLE_PLAYBOOK}} \ + -u {{ .ANSIBLE_USER }} + run: + deps: + - install:deps + cmds: + - | + ansible-playbook -i inventory.ini \ + {{.ANSIBLE_OPTIONS}} {{.ANSIBLE_PLAYBOOK}} \ + -u {{.ANSIBLE_USER}} + + install:deps: + internal: true + cmds: + - | + ansible-galaxy install \ + --ignore-errors \ + --roles-path="deps/" \ + --role-file="requirements.yml" + sources: + - requirements.yaml diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..69a8112 --- /dev/null +++ b/flake.lock @@ -0,0 +1,60 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1725103162, + "narHash": "sha256-Ym04C5+qovuQDYL/rKWSR+WESseQBbNAe5DsXNx5trY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "12228ff1752d7b7624a54e9c1af4b222b3c1073b", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..11b2e70 --- /dev/null +++ b/flake.nix @@ -0,0 +1,32 @@ +{ + description = "Devshel for Ansible"; + + + inputs = { + nixpkgs.url = "nixpkgs/nixos-unstable"; + flake-utils = { + url = "github:numtide/flake-utils"; + }; + }; + + outputs = { nixpkgs , flake-utils, ... }: flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + }; + in { + devShells = { + default = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ + lefthook + go-task + convco + typos + ansible + ]; + shellHook = '' + ''; + }; + }; + }); +} diff --git a/lefthook.yaml b/lefthook.yaml new file mode 100644 index 0000000..76a8dd0 --- /dev/null +++ b/lefthook.yaml @@ -0,0 +1,21 @@ +--- +skip_output: [meta, success] +no_tty: true + +commit-msg: + commands: + lint:convco: + run: cat {1} | convco check --from-stdin + lint:typos: + run: cat {1} | typos - +pre-commit: + parallel: false + commands: + lint:typos:staged_files: + run: typos {staged_files} +pre-push: + parallel: false + commands: + check:nix: + tags: check + run: nix flake check