From f7afb1dc30fbf9ad7026a9f137eebbadc4e94ba4 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Sun, 12 Apr 2026 11:58:16 +0100 Subject: [PATCH] sdformat: init at 0.2.0 --- pkgs/by-name/sd/sdformat/package.nix | 49 +++++++++++++++++++ .../sdformat/remove-hardcoded-lsblk-path.diff | 39 +++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 pkgs/by-name/sd/sdformat/package.nix create mode 100644 pkgs/by-name/sd/sdformat/remove-hardcoded-lsblk-path.diff diff --git a/pkgs/by-name/sd/sdformat/package.nix b/pkgs/by-name/sd/sdformat/package.nix new file mode 100644 index 000000000000..1c84dcf5950a --- /dev/null +++ b/pkgs/by-name/sd/sdformat/package.nix @@ -0,0 +1,49 @@ +{ + lib, + stdenv, + fetchFromGitHub, + util-linuxMinimal, + installShellFiles, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "sdformat"; + version = "0.2.0"; + + __structuredAttrs = true; + + src = fetchFromGitHub { + owner = "profi200"; + repo = "sdFormatLinux"; + rev = "v${finalAttrs.version}"; + hash = "sha256-AoAhP1dr+hQSnOpZC0oHt0j3fUVNVhD+3jWm6iMfskk="; + }; + + nativeBuildInputs = [ installShellFiles ]; + + patches = [ ./remove-hardcoded-lsblk-path.diff ]; + + strictDeps = true; + + makeFlags = [ + "TARGET=${finalAttrs.pname}" + "LSBLK_PATH=${lib.getExe' util-linuxMinimal "lsblk"}" + ]; + + installPhase = '' + runHook preInstall + + installBin ${finalAttrs.pname} + + runHook postInstall + ''; + + meta = { + description = "Format your SD card the way the SD Association intended"; + homepage = "https://github.com/profi200/sdFormatLinux"; + license = lib.licenses.mit; + mainProgram = finalAttrs.pname; + maintainers = with lib.maintainers; [ thiagokokada ]; + platforms = lib.platforms.linux; + }; +}) diff --git a/pkgs/by-name/sd/sdformat/remove-hardcoded-lsblk-path.diff b/pkgs/by-name/sd/sdformat/remove-hardcoded-lsblk-path.diff new file mode 100644 index 000000000000..22d786ae9fb7 --- /dev/null +++ b/pkgs/by-name/sd/sdformat/remove-hardcoded-lsblk-path.diff @@ -0,0 +1,39 @@ +diff --git i/Makefile w/Makefile +index c45b32b..258189c 100644 +--- i/Makefile ++++ w/Makefile +@@ -5,7 +5,8 @@ TARGET := $(notdir $(CURDIR)) + BUILD := build + INCLUDES := include + SOURCES := source +-DEFINES := -D_FORTIFY_SOURCE=2 ++LSBLK_PATH ?= /usr/bin/lsblk ++DEFINES := -D_FORTIFY_SOURCE=2 -DLSBLK_PATH=\"$(LSBLK_PATH)\" + + + # Compiler settings +diff --git i/source/blockdev.cpp w/source/blockdev.cpp +index a179604..b4de5ef 100644 +--- i/source/blockdev.cpp ++++ w/source/blockdev.cpp +@@ -7,6 +7,7 @@ + #include + #include // open()... + #include // BLKGETSIZE64... ++#include // PATH_MAX + #include // ioctl()... + #include // S_IRUSR, S_IWUSR... + #include // write(), close()... +@@ -21,8 +22,10 @@ + static int checkDevice(const char *const path) + { + int res = EINVAL; // By default assume the given path is not a suitable device. +- char cmd[64] = "/usr/bin/lsblk -dnr -oTYPE,HOTPLUG,PHY-SEC "; +- strncpy(&cmd[43], path, sizeof(cmd) - 43); ++ const char cmdPrefix[] = LSBLK_PATH " -dnr -oTYPE,HOTPLUG,PHY-SEC "; ++ char cmd[sizeof(cmdPrefix) + PATH_MAX]; ++ memcpy(cmd, cmdPrefix, sizeof(cmdPrefix) - 1); ++ strncpy(&cmd[sizeof(cmdPrefix) - 1], path, sizeof(cmd) - sizeof(cmdPrefix)); + cmd[sizeof(cmd) - 1] = '\0'; + FILE *const p = ::popen(cmd, "r"); + if(p == nullptr)