diff --git a/content/posts/2024-09-12-til-how-to-get-shell-completions-in-nix-shell-with-direnv/images/cover.png b/content/posts/2024-09-12-til-how-to-get-shell-completions-in-nix-shell-with-direnv/images/cover.png new file mode 100644 index 0000000..9439874 Binary files /dev/null and b/content/posts/2024-09-12-til-how-to-get-shell-completions-in-nix-shell-with-direnv/images/cover.png differ diff --git a/content/posts/2024-09-12-til-how-to-get-shell-completions-in-nix-shell-with-direnv/index.md b/content/posts/2024-09-12-til-how-to-get-shell-completions-in-nix-shell-with-direnv/index.md new file mode 100644 index 0000000..f1c3fd0 --- /dev/null +++ b/content/posts/2024-09-12-til-how-to-get-shell-completions-in-nix-shell-with-direnv/index.md @@ -0,0 +1,93 @@ +--- +title: "TIL: How to Get Shell Completions in Nix Shell With Direnv" +date: 2024-09-12 +canonicalURL: https://haseebmajid.dev/posts/2024-09-12-til-how-to-get-shell-completions-in-nix-shell-with-direnv +tags: + - nix + - direnv +series: + - TIL +cover: + image: images/cover.png +--- + +**TIL: How to Get Shell Completions in Nix Shell With Direnv** + +When shell completions don't work with direnv, you may need to use `nix develop` to load the shell manually. + +## Background + +I am using `nix-direnv`, with nix devshell to autoload into my development environments. I changed the directory +and the devshell is automagically loaded without me doing anything, which is great. Provides me with a bunch of tools +specific for that project. With all the benefits of Nix, mainly reproducibility. + +```bash +❯ z banterbus/ +direnv: loading ~/projects/banterbus/.envrc +direnv: using flake +direnv: nix-direnv: Using cached dev shell +direnv: export +AR +AS +CC +CONFIG_SHELL +CXX +GOTOOLDIR +HOST_PATH +IN_NIX_SHELL +LD +NIX_BINTOOLS +NIX_BINTOOLS_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu +NIX_BUILD_CORES +NIX_CC +NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu +NIX_CFLAGS_COMPILE +NIX_ENFORCE_NO_NATIVE +NIX_HARDENING_ENABLE +NIX_LDFLAGS +NIX_STORE +NM +OBJCOPY +OBJDUMP +PLAYWRIGHT_BROWSERS_PATH +PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD +RANLIB +READELF +SIZE +SOURCE_DATE_EPOCH +STRINGS +STRIP +__structuredAttrs +buildInputs +buildPhase +builder +cmakeFlags +configureFlags +depsBuildBuild +depsBuildBuildPropagated +depsBuildTarget +depsBuildTargetPropagated +depsHostHost +depsHostHostPropagated +depsTargetTarget +depsTargetTargetPropagated +doCheck +doInstallCheck +dontAddDisableDepTrack +hardeningDisable +mesonFlags +name +nativeBuildInputs +out +outputs +patches +phases +preferLocalBuild +propagatedBuildInputs +propagatedNativeBuildInputs +shell +shellHook +stdenv +strictDeps +system ~PATH ~XDG_DATA_DIRS +``` + + +Where my mkShell function looks something like: + +```nix +{ + pkgs.mkShell { + hardeningDisable = ["all"]; + shellHook = '' + export PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 + export PLAYWRIGHT_BROWSERS_PATH="${pkgs.playwright-driver.browsers}" + ${pre-commit-check.shellHook} + ''; + buildInputs = pre-commit-check.enabledPackages; + packages = with pkgs; [ + # TODO: workout how to use go env + # goEnv + gomod2nix + go_1_22 + playwright-test + + goose + air + golangci-lint + gotools + gotestsum + gocover-cobertura + go-task + go-mockery + goreleaser + golines + + tailwindcss + templ + sqlc + ]; + } +} + +``` + +You can see I have certain tools I want other developers to have access to like `go-task`, which they will automatically +get when they load into the devshell. + +## Issue + +This is all great; however, I have noticed that shell completions stopped working. Where I can normally do `task ` + +```bash +❯ task tests:e2e +build:dev (Build the app for development, generates all the files needed for the binary.) generate:sqlc (Generates the code to interact with SQL DB.) +coverage (Run the integration tests and gets the code coverage) lint (Runs the linter.) +dev (Start the app in dev mode with live-reloading.) release (Release the CLI tool.) +docker:build (Builds a Docker image using Nix.) tests (Runs all the tests.) +docker:load (Loads the Docker image from tar (in results).) tests:e2e (Runs e2e tests with playwright.) +docker:publish (Publishes the Docker image) tests:integration (Runs all the integration tests.) +format (Runs the formatter.) tests:unit (Runs all the unit tests.) +``` + +However, in the devshell this does not work until I load into the shell manually `nix develop`. Which does defeat +the purpose of using `nix-direnv` as you need to manually run a command now. + +I don't know what causes this and will do a deeper dive at some point 🤔. diff --git a/content/posts/2024-09-15-til-how-to-cancel-stale-pipelines-in-gitlab-ci/images/cover.png b/content/posts/2024-09-15-til-how-to-cancel-stale-pipelines-in-gitlab-ci/images/cover.png new file mode 100644 index 0000000..805437b Binary files /dev/null and b/content/posts/2024-09-15-til-how-to-cancel-stale-pipelines-in-gitlab-ci/images/cover.png differ diff --git a/content/posts/2024-09-15-til-how-to-cancel-stale-pipelines-in-gitlab-ci/images/gitlab-ci-cancelled.png b/content/posts/2024-09-15-til-how-to-cancel-stale-pipelines-in-gitlab-ci/images/gitlab-ci-cancelled.png new file mode 100644 index 0000000..e453557 Binary files /dev/null and b/content/posts/2024-09-15-til-how-to-cancel-stale-pipelines-in-gitlab-ci/images/gitlab-ci-cancelled.png differ diff --git a/content/posts/2024-09-15-til-how-to-cancel-stale-pipelines-in-gitlab-ci/index.md b/content/posts/2024-09-15-til-how-to-cancel-stale-pipelines-in-gitlab-ci/index.md new file mode 100644 index 0000000..dc81066 --- /dev/null +++ b/content/posts/2024-09-15-til-how-to-cancel-stale-pipelines-in-gitlab-ci/index.md @@ -0,0 +1,40 @@ +--- +title: "TIL: How to Cancel Stale Pipelines in GitLab CI" +date: 2024-09-15 +canonicalURL: https://haseebmajid.dev/posts/2024-09-15-til-how-to-cancel-stale-pipelines-in-gitlab-ci +tags: + - gitlab-ci + - gitlab +series: + - TIL +cover: + image: images/cover.png +--- + +**TIL: How to Cancel Stale Pipelines in GitLab CI** + +Today I learnt that we can cancel old pipelines in MRs. For example, you push a new commit, and you don't care about the +old pipeline running any more. You want to cancel them to save CI minutes etc. + +Here is an example, you can see the 2nd pipeline is cancelled: + +![gitlab-ci-cancelled.png](./images/gitlab-ci-cancelled.png) + + +We need to add this to our `.gitlab-ci.yml` file. Where the `default.interruptible` marks every job as it can be +cancelled [^1]. + +```yaml +workflow: + auto_cancel: + on_new_commit: interruptible + +default: + interruptible: true +``` + +Then on new commits, we cancel all interruptible jobs. Just make sure to be careful where jobs actually deploy stuff. +You don't want to partially deploy things. But for jobs like running tests, linting etc this should be all good. + +[^1]: https://docs.gitlab.com/ee/ci/yaml/index.html#interruptible## Appendix +- [Example gitlab pipeline](https://gitlab.com/hmajid2301/banterbus/-/blob/1ef5ae17e81b75576d7df02a60c9e95e11fc6d96/.gitlab-ci.yml)