From 1c918657050c858a3044723e8fe3aad5b934a056 Mon Sep 17 00:00:00 2001 From: Yorick Barbanneau Date: Tue, 3 Sep 2024 00:28:20 +0200 Subject: [PATCH 1/2] 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 From 5ba41fcefe3c81ce17c22a28b604f55cd88d1d0d Mon Sep 17 00:00:00 2001 From: Yorick Barbanneau Date: Tue, 3 Sep 2024 00:30:06 +0200 Subject: [PATCH 2/2] chore(playbook): remove unused configurations and files --- playbook.yml | 60 +--------------------------------------------------- 1 file changed, 1 insertion(+), 59 deletions(-) diff --git a/playbook.yml b/playbook.yml index 5d721b4..ad8d925 100644 --- a/playbook.yml +++ b/playbook.yml @@ -36,33 +36,6 @@ mode: '0640' directory_mode: '0750' - - name: Install packages - ansible.builtin.package: - pkg: - - zsh - - pass - - vifm - - cmus - - unzip - state: present - become: true - - - name: Clone my zsh repository - ansible.builtin.git: - repo: ssh://git@git.epha.se:24422/ephase/zsh_config.git - dest: '{{ ansible_user_dir }}/.config/zsh' - - - name: Symlink .zshenv to ~ - ansible.builtin.file: - src: '{{ ansible_user_dir }}/.config/zsh/.zshenv' - dest: '{{ ansible_user_dir }}/.zshenv' - state: link - - - name: Clone my neovim repository - ansible.builtin.git: - repo: ssh://git@git.epha.se:24422/ephase/nvim_config.git - dest: '{{ ansible_user_dir }}/.config/nvim' - - name: Launch Sway related roles hosts: all roles: @@ -74,28 +47,9 @@ - ansible-swayidle - ansible-waybar -- name: Configure desktop +- name: Install some stuff hosts: all tasks: - - name: Install packages on Arch - ansible.builtin.package: - pkg: - - arc-solid-gtk-theme - - glib2 - - pinentry - - gcr - - libnotify - - opensc - - qt5-wayland - - ttf-dejavu - - ttf-fira-code - - ttf-joypixels - - ttf-liberation - - ttf-linux-libertine - - xorg-xwayland - when: ansible_distribution == "Archlinux" - become: true - - name: Install packages on Debian ansible.builtin.package: pkg: @@ -114,7 +68,6 @@ - pcscd - pcsc-tools - pulseaudio-utils - - qtwayland5 - scdaemon - texlive - webext-browserpass @@ -127,27 +80,16 @@ pkg: - papirus-icon-theme - brightnessctl - - chafa - - firefox - foot - foot-terminfo - fuzzel - - fzf - - highlight - - hugo - imv - - khal - - khard - - npm - mpv - ntfs-3g - pipewire - pipewire-pulse - - qutebrowser - - rsync - sshfs - udisks2 - - vdirsyncer - wireplumber - xdg-desktop-portal-wlr - xdg-user-dirs