This commit is contained in:
Oliver Davies 2023-04-06 14:07:08 +01:00
parent 63bf55b978
commit 8b18e05fbc
25 changed files with 1042 additions and 1 deletions

View file

@ -13,7 +13,10 @@
devShell = with pkgs; pkgs.mkShell {
buildInputs = [
just
python310Packages.rst2pdf
python39Packages.rst2pdf
pdfpc
libcanberra
libcanberra-gtk3
];
};
});

View file

@ -20,3 +20,6 @@ generate name: (clean name)
--font-path ../fonts \
--output {{ name }}-dark.pdf \
--stylesheets opdavies-dark,tango,monokai
thumbnail name slideNumber:
pdftoppm {{ name }}/{{ name }}.pdf -png -f {{ slideNumber }} -l {{ slideNumber }} > {{ name }}/{{ name }}-{{ slideNumber }}.png

View file

@ -0,0 +1,12 @@
FROM php:{{ php.version }} AS base
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
RUN which composer && composer -V
ARG DOCKER_UID=1000
ENV DOCKER_UID="${DOCKER_UID}"
WORKDIR {{ project_root }}
RUN adduser --disabled-password --uid "${DOCKER_UID}" app \
&& chown app:app -R {{ project_root }}

View file

@ -0,0 +1,13 @@
alias cp="cp -v"
alias mv="mv -v"
alias rm="rm -v"
alias g="git"
alias gs="git status"
alias dk="docker"
alias dkp="docker ps"
alias dkc="docker compose"
alias dkcu="docker compose up"
alias docker-composer="docker-compose"

View file

@ -0,0 +1,46 @@
name: docker-example-drupal
language: php
type: drupal-project
web:
type: nginx
database:
type: mariadb
version: 10
php:
version: 8.1-fpm-bullseye
phpcs:
standard: Drupal,DrupalPractice
phpstan:
level: max
drupal:
docroot: web
docker-compose:
services:
database: ~
php:
build:
target: build
dockerfile:
stages:
build:
extends: base
packages:
- git
- libpng-dev
- libzip-dev
- mariadb-client
- unzip
extensions:
install:
- gd
- pdo_mysql
- zip
commands:
- composer validate --strict
- composer install

View file

@ -0,0 +1,26 @@
{ config, pkgs, ... }:
{
imports = [ ./hardware-configuration.nix ];
nix.settings.experimental-features = [ "nix-command" "flakes" ];
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
boot.loader.efi.efiSysMountPoint = "/boot/efi";
boot.kernelPackages = pkgs.linuxPackages_latest;
networking.hostName = "nixedo";
networking.networkmanager.enable = true;
time.timeZone = "Europe/London";
i18n.defaultLocale = "en_GB.UTF-8";
users.users.opdavies = {
isNormalUser = true;
description = "Oliver Davies";
extraGroups = [ "docker" "networkmanager" "wheel" ];
packages = with pkgs; [ firefox ];
};

View file

@ -0,0 +1,15 @@
{% if "php" == language %}
php:
<<: *default-app
build:
context: .
target: build
args:
- "DOCKER_UID=${DOCKER_UID:-1000}"
volumes:
- .:{{ project_root }}
{% if "database" in dockerCompose.services|keys -%}
depends_on:
- database
{% endif -%}
profiles: [php]

View file

@ -0,0 +1,19 @@
{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
inputs.devshell.url = "github:numtide/devshell";
outputs = inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [ inputs.devshell.flakeModule ];
systems = [ "x86_64-linux" ];
perSystem = { config, self', inputs', pkgs, system, ... }: {
devshells.default = {
packages = with pkgs; [ php82 php82Packages.composer ];
};
};
flake = { };
};
}

View file

@ -0,0 +1,27 @@
programs.git = {
enable = true;
userName = "Oliver Davies";
userEmail = "oliver@oliverdavies.uk";
aliases = {
aa = "add --all";
assume = "update-index --assume-unchanged";
assumed = "!git ls-files -v | grep '^[hsmrck?]' | cut -c 3-";
b = "branch";
# ...
};
extraConfig = {
branch = {
autosetupmerge = true;
autosetuprebase = "always";
};
checkout.defaultRemote = "origin";
color.ui = true;
commit = {
template = "~/.gitmessage";
};
core = {
editor = "nvim";
excludesFile = "~/.gitignore-global";
pager = "delta";
};

View file

@ -0,0 +1,15 @@
[alias]
aa = "add --all"
assume = "update-index --assume-unchanged"
assumed = "!git ls-files -v | grep '^[hsmrck?]' | cut -c 3-"
b = "branch"
browse = "!gh repo view --web"
ca = "commit --amend --verbose"
car = "commit --amend --no-edit"
[branch]
autosetupmerge = true
autosetuprebase = "always"
[checkout]
defaultRemote = "origin"

View file

@ -0,0 +1,25 @@
{ config, lib, pkgs, modulesPath, ... }:
{
imports = [ (modulesPath + "/installer/scan/not-detected.nix") ];
boot.initrd.availableKernelModules =
[ "xhci_pci" "thunderbolt" "nvme" "usb_storage" "sd_mod" ];
boot.initrd.kernelModules = [ ];
boot.kernelModules = [ "kvm-intel" ];
boot.kernelParams = [ "i8042.reset" ];
boot.extraModulePackages = [ ];
fileSystems."/" = {
device = "/dev/disk/by-uuid/7c6d69ec-ba06-4ddb-b9c4-62b3994fda91";
fsType = "ext4";
};
fileSystems."/boot/efi" = {
device = "/dev/disk/by-uuid/B729-9A75";
fsType = "vfat";
};
swapDevices =
[{ device = "/dev/disk/by-uuid/5db0a0e6-93fb-4d0b-8fb0-fdb3cb76b89d"; }];

View file

@ -0,0 +1,11 @@
{ config, pkgs, ... }:
{
home.username = "opdavies";
home.homeDirectory = "/home/opdavies";
home.packages = with pkgs; [
php82
php82Packages.composer
];
};

View file

@ -0,0 +1,12 @@
{% if "php" is same as language %}
composer *args:
{{ "just _exec php composer {{ args }}" | raw }}
{% if "drupal-project" is same as type %}
drush *args:
{{ "just _exec php drush {{ args }}" | raw }}
install *args:
{{ "just _exec php drush site:install -y {{ args }}" | raw }}
{% endif %}
{% endif %}

View file

@ -0,0 +1,164 @@
embeddedFonts:
- - Inconsolata.ttf
- Inconsolata.ttf
- Inconsolata.ttf
- Inconsolata.ttf
- - Helvetica.ttf
- Helvetica-Bold.ttf
- Helvetica.ttf
- Helvetica-Bold.ttf
fontsAlias:
fontBold: Helvetica-Bold
fontFont: Helvetica
fontItalic: Helvetica
fontMono: Inconsolata
fontMonoBold: Inconsolata
fontMonoBoldItalic: Inconsolata
fontMonoItalic: Inconsolata
linkColor: '#60a5fa'
pageSetup:
firstTemplate: coverPage
height: 18cm
margin-bottom: 0cm
margin-gutter: 0cm
margin-left: 0cm
margin-right: 0cm
margin-top: 0cm
size: null
spacing-footer: 2mm
spacing-header: 2mm
width: 32cm
pageTemplates:
coverPage:
background: ../images/bg-dark.png
frames:
- - 12%
- 10%
- 76%
- 75%
showFooter: false
showHeader: false
imagePage:
alignment: TA_CENTER
background: ../images/bg-dark.png
frames:
- - 3%
- 3%
- 92%
- 92%
showFooter: true
showHeader: false
outputPage:
background: ../images/bg-dark.png
frames:
- - 8%
- 10%
- 82%
- 65%
showFooter: false
showHeader: false
standardPage:
background: ../images/bg-dark.png
frames:
- - 3%
- 3%
- 92%
- 92%
showFooter: true
showHeader: false
titlePage:
alignment: TA_CENTER
background: ../images/bg-dark.png
frames:
- - 8%
- 8%
- 85%
- 65%
showFooter: true
showHeader: false
styles:
bodytext:
alignment: TA_LEFT
bullet-list:
colWidths:
- '20'
- null
commands:
- - LEFTPADDING
- - 0
- 0
- - 1
- -1
- 5
- - RIGHTPADDING
- - 0
- 0
- - 1
- -1
- 0
textColor: '#ffffff'
bullet-list-item:
spaceAfter: 0
spaceBefore: 18
centred:
alignment: TA_CENTER
parent: normal
centredtitle:
alignment: TA_CENTER
fontName: fontBold
fontSize: 48
leading: 64
parent: heading
code:
backColor: '#111111'
borderWidth: 0
fontSize: 24
leading: 26
parent: literal
spaceBefore: 4
footer:
alignment: TA_RIGHT
fontName: fontMono
fontSize: 20
rightIndent: 16
spaceBefore: 0
textColor: '#24608a'
heading:
fontName: fontBold
fontSize: 20
spaceAfter: 16
textColor: '#60a5fa'
literal:
backColor: '#111111'
fontName: fontMono
normal:
fontSize: 24
textColor: '#ffffff'
title:
fontSize: 300%
parent: heading
titleslideinfo:
alignment: TA_CENTER
fontSize: 140%
parent: normal

View file

@ -0,0 +1,158 @@
embeddedFonts:
- - Inconsolata.ttf
- Inconsolata.ttf
- Inconsolata.ttf
- Inconsolata.ttf
- - Helvetica.ttf
- Helvetica-Bold.ttf
- Helvetica.ttf
- Helvetica-Bold.ttf
fontsAlias:
fontBold: Helvetica-Bold
fontFont: Helvetica
fontItalic: Helvetica
fontMono: Inconsolata
fontMonoBold: Inconsolata
fontMonoBoldItalic: Inconsolata
fontMonoItalic: Inconsolata
linkColor: '#24608a'
pageSetup:
firstTemplate: coverPage
height: 18cm
margin-bottom: 0cm
margin-gutter: 0cm
margin-left: 0cm
margin-right: 0cm
margin-top: 0cm
size: null
spacing-footer: 2mm
spacing-header: 2mm
width: 32cm
pageTemplates:
coverPage:
frames:
- - 12%
- 10%
- 76%
- 75%
showFooter: false
showHeader: false
imagePage:
alignment: TA_CENTER
frames:
- - 3%
- 3%
- 92%
- 92%
showFooter: true
showHeader: false
outputPage:
frames:
- - 8%
- 10%
- 82%
- 65%
showFooter: false
showHeader: false
standardPage:
frames:
- - 3%
- 3%
- 92%
- 92%
showFooter: true
showHeader: false
titlePage:
alignment: TA_CENTER
frames:
- - 8%
- 8%
- 85%
- 65%
showFooter: true
showHeader: false
styles:
bodytext:
alignment: TA_LEFT
bullet-list:
colWidths:
- '20'
- null
commands:
- - LEFTPADDING
- - 0
- 0
- - 1
- -1
- 5
- - RIGHTPADDING
- - 0
- 0
- - 1
- -1
- 0
textColor: '#aaaaaa'
bullet-list-item:
spaceAfter: 0
spaceBefore: 18
centred:
alignment: TA_CENTER
parent: normal
centredtitle:
alignment: TA_CENTER
fontName: fontBold
fontSize: 48
leading: 64
parent: heading
code:
backColor: white
borderWidth: 0
fontSize: 22
leading: 24
parent: literal
spaceBefore: 0
footer:
alignment: TA_RIGHT
fontName: fontMono
fontSize: 20
rightIndent: 16
spaceBefore: 0
textColor: '#24608a'
heading:
fontName: fontBold
fontSize: 20
spaceAfter: 16
textColor: '#24608a'
literal:
backColor: white
fontName: fontMono
normal:
fontSize: 24
textColor: '#383745'
title:
fontSize: 300%
parent: heading
titleslideinfo:
alignment: TA_CENTER
fontSize: 140%
parent: normal

View file

@ -0,0 +1,71 @@
.. raw:: pdf
PageBreak titlePage
.. class:: centredtitle
Generating configuration files
.. raw:: pdf
PageBreak standardPage
build-configs
=============
Most of my projects have the same configuration files:
|
* ``Dockerfile``
* ``docker-compose.yaml``
* ``justfile``
* ``phpstan.neon.dist``
* ``phpunit.xml.dist``
.. raw:: pdf
TextAnnotation "Same files with either the same or similar values. What if, instead of copying and pasting these between projects, I could generate them from a canonical set of templates?"
build-configs
=============
* Symfony/Silly CLI project
* Twig for templating
* Takes values from a `build.yaml` file
* Generates the appropriate files with the correct configuration
* Easier to set up a new project
* Less maintenance overhead
* Can quickly add a new feature and update every project
.. raw:: pdf
TextAnnotation "Opinionated template files"
build.yaml
==========
.. code-block:: yaml
:include: code/build.yaml
:linenos:
Dockerfile.twig
===============
.. code-block:: Dockerfile
:include: code/Dockerfile.twig
:linenos:
docker-compose.yaml.twig
========================
.. code-block:: twig
:include: code/docker-compose.yaml.twig
:linenos:
justfile.twig
=============
.. code-block:: twig
:include: code/justfile.twig
:linenos:

View file

@ -0,0 +1,22 @@
.. raw:: pdf
PageBreak standardPage
Nix Flakes
==========
* Per project
* Uses ``nixpkgs`` to create a development shell
* Can create build artifacts (phar?)
* Could replace Docker and Docker Compose
.. raw:: pdf
TextAnnotation "Creates a temporary shell with the requirements for that project."
flake.nix
=========
.. code-block:: nix
:include: code/flake.nix
:linenos:

View file

@ -0,0 +1,19 @@
.. raw:: pdf
PageBreak standardPage
Git
===
Customised to my preferences, managed by Home Manager:
.. code-block:: nix
:include: code/git.nix
:linenos:
.. raw:: pdf
PageBreak
.. code-block:: ini
:include: code/gitconfig.ini

View file

@ -0,0 +1,69 @@
.. raw:: pdf
PageBreak titlePage
.. class:: centredtitle
just
.. raw:: pdf
TextAnnotation "Who's used a Makefile? I have, but wasn't using a lot of the build features it has. I was using it as a task runner."
.. raw:: pdf
PageBreak standardPage
justfile
========
.. code-block:: make
default:
@just --list
_exec +args:
docker compose exec {{ args }}
# Run Composer
composer *args:
just _exec php composer {{ args }}
# Run Drush commands
drush *args:
just _exec php drush {{ args }}
# Install Drupal
install *args:
just drush site:install -y {{ args }}
# Run Artisan commands (Laravel)
artisan *args:
docker compose run \
--entrypoint php \
--rm \
--tty \
php artisan {{ args }}
.. raw:: pdf
PageBreak titlePage
.. class:: centredtitle
``just composer require
drupal/override_node_options``
.. raw:: pdf
PageBreak
.. class:: centredtitle
``just drush cache-rebuild``
|
.. class:: centredtitle
``just install localgov``

View file

@ -0,0 +1,14 @@
.. raw:: pdf
PageBreak standardPage
neovim
======
* Community-maintained fork of Vim
* Configured with Lua
* ``nvim-lspconfig`` for language server support
* Intelephense and Phpactor for PHP
* ``nvim-dap`` and ``nvim-dap-ui`` for step debugging
* ``nvim-cmp`` for completion, LuaSnip for snippets
* PHPCS, PHPStan diagnostics with ``null-ls.nvim``

View file

@ -0,0 +1,138 @@
.. raw:: pdf
PageBreak standardPage
Operating system
================
**Personal**:
- Linux
- NixOS
- KDE Plasma
|
**Work**:
- Windows 10
- WSL (Ubuntu)
- Nix package manager
.. raw:: pdf
TextAnnotation "Started with Ubuntu for work, used Pop!_OS for personal laptops and now on NixOS."
TextAnnotation "Used to use Apple/macOS and switched full-time to Linux a few years ago.used Homebrew for package management."
TextAnnotation "Automated things with Ansible."
TextAnnotation ""
TextAnnotation "Use Windows for Office, Teams, etc. Development is done within the WSL/Linux environment."
Nix and NixOS
=============
- Declarative
- Reproducable
- Nix Packages collection (``nixpkgs``) has over 80,000 packages
- Easy to add to and edit, and contribute to
.. raw:: pdf
TextAnnotation "Nix builds packages in isolation from each other. This ensures that they are reproducible and don't have undeclared dependencies, so if a package works on one machine, it will also work on another."
TextAnnotation "Nix makes it trivial to share development and build environments for your projects, regardless of what programming languages and tools youre using. "
TextAnnotation "80,000 packages including Vim and tmux plugins, PHP and node packages"
TextAnnotation "Configuration file-driven. You declare the end state rather than the steps to get there."
TextAnnotation "Replaced Ansible for me."
.. raw:: pdf
PageBreak titlePage
.. class:: centredtitle
``nix-env -iA php82``
.. raw:: pdf
PageBreak
.. class:: centredtitle
``nix-shell --packages php82``
.. raw:: pdf
PageBreak
.. class:: centredtitle
``nix-shell --packages php82
--command "php -v"``
.. raw:: pdf
PageBreak standardPage
configuration.nix
=================
.. code-block:: nix
:include: code/configuration.nix
:linenos:
hardware-configuration.nix
==========================
.. code-block:: nix
:include: code/hardware-configuration.nix
:linenos:
.. raw:: pdf
PageBreak titlePage
.. class:: centredtitle
``sudo nixos-rebuild build
--flake .#nixedo``
.. raw:: pdf
PageBreak standardPage
dotfiles
========
* System configuration files
* Usually hidden, filenames start with a dot (``.zshrc``, ``.gitconfig``, ``.config/``)
* Maintained on GitHub since July 2015
* https://opdavi.es/dotfiles
* Managed with Home Manager
.. raw:: pdf
TextAnnotation "Similar to hidden files within projects like .gitignore."
TextAnnotation "Manages user configuration instead of system configuration."
TextAnnotation ""
TextAnnotation "Used with NixOS and the Nix package manager in WSL."
home-manager/home.nix
=====================
.. code-block:: nix
:include: code/home-manager.nix
:linenos:
.. raw:: pdf
PageBreak titlePage
.. class:: centredtitle
``home-manager build
-f home-manager/home.nix
--flake .#wsl2``
.. raw:: pdf
PageBreak standardPage

View file

@ -0,0 +1,12 @@
.. raw:: pdf
PageBreak standardPage
Other mentions
==============
* ``fzf``
* ``grep`` and ``ripgrep``
* ``find`` and ``xargs``
* Pulumi and Terraform for infrastructure automation
* Ansible and Ansistrano

View file

@ -0,0 +1,80 @@
.. raw:: pdf
PageBreak titlePage
.. class:: centredtitle
Z Shell
.. raw:: pdf
PageBreak standardPage
Why zsh?
========
* Replacement for the ``bash`` shell
* Default on macOS
* Separate to "oh-my-zsh"
* OMZSH plugins and themes can be installed using ``zplug``
* Aliases
* Globbing and expanding
Aliases
=======
.. code-block:: bash
:linenos:
:include: code/aliases.sh
.. raw:: pdf
TextAnnotation "Can be used to override default behaviour or to add new commands and shortcuts."
Globbing and expanding
======================
Changing a file prefix:
``mv index.{html,twig}``
``mv index.html index.twig``
|
Creating two files with different prefixes:
``touch my-component.{config.yml,twig}``
|
Creating a range of files:
``touch {1..10}.php``
Auto-expanding
==============
.. code-block:: bash
:linenos:
expand-alias-space() {
[[ $LBUFFER =~ "\<(''${(j:|:)baliases})\$" ]]; insertBlank=$?
if [[ ! $LBUFFER =~ "\<(''${(j:|:)ialiases})\$" ]]; then
zle _expand_alias
fi
zle self-insert
if [[ "$insertBlank" = "0" ]]; then
zle backward-delete-char
fi
}
zle -N expand-alias-space
bindkey " " expand-alias-space
.. raw:: pdf
TextAnnotation "More like snippets than aliases."

View file

@ -0,0 +1,12 @@
.. raw:: pdf
PageBreak standardPage
tmux
====
* "Terminal multiplexer"
* Splits a terminal into different sessions and panes
* One session per project
* Editing in one pane, running commands in another
* Long-running commands in a separate window

View file

@ -0,0 +1,55 @@
.. footer:: @opdavies
Working without Workspace
#########################
|
.. class:: titleslideinfo
Oliver Davies (@opdavies)
.. raw:: pdf
PageBreak titlePage
.. class:: centredtitle
Working with Workspace
.. raw:: pdf
TextAnnotation "Workspace is an open-source project developed and maintained by Inviqa, which we used on our projects and I was starting to use on personal projects."
TextAnnotation "This talk is about how my development environment and tools work now, a couple of years after leaving Inviqa."
.. include:: sections/operating-system.rst
.. include:: sections/shell.rst
.. include:: sections/git.rst
.. include:: sections/just.rst
.. include:: sections/build-configs.rst
.. include:: sections/flakes.rst
.. include:: sections/neovim.rst
.. include:: sections/tmux.rst
.. include:: sections/others.rst
.. raw:: pdf
PageBreak standardPage
Thanks!
=======
References:
* https://opdavi.es/dotfiles
* https://nixos.org
* https://just.systems
* https://neovim.io
* https://github.com/tmux/tmux/wiki
* https://opdavi.es/docker-examples
|
Me:
* https://www.oliverdavies.uk