1
0
Fork 0
Simple CLI to send a HTTP POST with log information. Primarily created to learn Nix building and packaging.
Find a file
Bauke Drijkoningen 29893c33ae
All checks were successful
Test / cargo check (push) Successful in 1m6s
Add a test Forgejo Actions workflow.
2025-05-29 23:57:58 +02:00
.forgejo/workflows Add a test Forgejo Actions workflow. 2025-05-29 23:57:58 +02:00
src Add ureq to make the POST request. 2025-04-14 23:47:06 +02:00
.envrc Initial template commit. 2025-04-14 20:47:45 +02:00
.gitignore Add a Nix derivation to build the CLI. 2025-04-15 19:49:49 +02:00
Cargo.lock Add ureq to make the POST request. 2025-04-14 23:47:06 +02:00
Cargo.toml Add ureq to make the POST request. 2025-04-14 23:47:06 +02:00
default.nix Add a Nix derivation to build the CLI. 2025-04-15 19:49:49 +02:00
derivation.nix Clean up template. 2025-04-15 20:16:25 +02:00
flake.lock Initial template commit. 2025-04-14 20:47:45 +02:00
flake.nix Initial template commit. 2025-04-14 20:47:45 +02:00
README.md Add documentation. 2025-05-29 23:18:50 +02:00
rustfmt.toml Add CLI foundation using Clap. 2025-04-14 21:10:31 +02:00
rustup-toolchain.toml Initial template commit. 2025-04-14 20:47:45 +02:00
shell.nix Initial template commit. 2025-04-14 20:47:45 +02:00

b3k-log

Simple CLI to send a HTTP POST with log information. Primarily created to learn Nix building and packaging.

Nix files

📄 shell.nix

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.

📄 flake.nix

The flake file, currently only used to set up the oxalica/rust-overlay and for direnv to automatically load in the development shell.

📄 default.nix

A default Nix file that just calls the derivation.nix file.

📄 derivation.nix

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.