-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2024 09 12 til how to get shell completions in nix shell with direnv
- Loading branch information
1 parent
1197a2c
commit 187975d
Showing
5 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
Binary file added
BIN
+351 KB
...9-12-til-how-to-get-shell-completions-in-nix-shell-with-direnv/images/cover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
93 changes: 93 additions & 0 deletions
93
...s/2024-09-12-til-how-to-get-shell-completions-in-nix-shell-with-direnv/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <TAB>` | ||
|
||
```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 🤔. |
Binary file added
BIN
+344 KB
...osts/2024-09-15-til-how-to-cancel-stale-pipelines-in-gitlab-ci/images/cover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+92.9 KB
...5-til-how-to-cancel-stale-pipelines-in-gitlab-ci/images/gitlab-ci-cancelled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions
40
content/posts/2024-09-15-til-how-to-cancel-stale-pipelines-in-gitlab-ci/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |