|
All checks were successful
Test / cargo check (push) Successful in 1m6s
|
||
|---|---|---|
| .forgejo/workflows | ||
| src | ||
| .envrc | ||
| .gitignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| default.nix | ||
| derivation.nix | ||
| flake.lock | ||
| flake.nix | ||
| README.md | ||
| rustfmt.toml | ||
| rustup-toolchain.toml | ||
| shell.nix | ||
b3k-log
Simple CLI to send a HTTP POST with log information. Primarily created to learn Nix building and packaging.
Nix files
The development shell file that contains the development tools and dependencies, in our case we use the oxalica/rust-overlay to grab the Rust tools via our Rustup toolchain file.
The flake file, currently only used to set up the oxalica/rust-overlay and for direnv to automatically load in the development shell.
A default Nix file that just calls the derivation.nix file.
The file to actually build the b3k-log package using rustPlatform.buildRustPackage.
External Usage
One possible way to then use the derivation.nix in your own configuration is like this.
First we use fetchFromGitea to grab the source code, then we use callPackage on the derivation to actually build the package.
# b3k-log.nix
{ lib, pkgs, ... }:
let
src = pkgs.fetchFromGitea {
domain = "forgejo.drijkoningen.dev";
owner = "bauke";
repo = "b3k-log";
rev = "8f6892d158ae8636bbb006e6020411802e0f1ba6";
sha256 = "sha256-dz83L3KX1bAfuOzUBVJ3XRmvuBJC/sm03nkbsLcfIFs=";
};
in
pkgs.callPackage "${src}/derivation.nix" { }
With the package built, we can now use it in our NixOS configuration. For example, using a Systemd service and timer to log a message when the system boots:
# b3k-log-on-boot.nix
{ pkgs, ... }:
{
systemd.timers."b3k-log-on-boot" = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnBootSec = "5m";
Unit = "b3k-log-on-boot.service";
};
};
systemd.services."b3k-log-on-boot" = {
path = with pkgs; [
(callPackage ./b3k-log.nix { })
];
script = ''
set -eu
b3k-log \
--source "Helix" \
--message "Boot" \
--url "https://n8n.stardust.drijkoningen.dev/webhook/4b5d1f7c-ff0f-4ca6-ac46-a04826c2e155"
'';
serviceConfig = {
Type = "oneshot";
User = "bauke";
};
};
}
I'm not exactly a fan of the use of callPackage here again, ideally I'd make my own custom pkgs set and put all the custom packages in there, and then use it like you would pkgs. But I have yet to figure out how to do that exactly.