From f0eba88cc5eef21f3b795d0e20a97344786313c0 Mon Sep 17 00:00:00 2001 From: TomaSajt <62384384+TomaSajt@users.noreply.github.com> Date: Sat, 30 Mar 2024 12:23:35 +0100 Subject: [PATCH] btdu: use buildDubPackage --- pkgs/tools/misc/btdu/default.nix | 129 +++++++++-------------------- pkgs/tools/misc/btdu/dub-lock.json | 20 +++++ pkgs/tools/misc/btdu/update.py | 82 ------------------ 3 files changed, 59 insertions(+), 172 deletions(-) create mode 100644 pkgs/tools/misc/btdu/dub-lock.json delete mode 100755 pkgs/tools/misc/btdu/update.py diff --git a/pkgs/tools/misc/btdu/default.nix b/pkgs/tools/misc/btdu/default.nix index 631c542a9f8ad..4debdae0df0b3 100644 --- a/pkgs/tools/misc/btdu/default.nix +++ b/pkgs/tools/misc/btdu/default.nix @@ -1,93 +1,42 @@ -{ lib -, stdenv -, fetchurl -, dub -, ncurses -, ldc -, zlib -, removeReferencesTo +{ + lib, + buildDubPackage, + fetchFromGitHub, + ncurses, + zlib, }: -let - _d_ae_ver = "0.0.3236"; - _d_btrfs_ver = "0.0.18"; - _d_ncurses_ver = "1.0.0"; - _d_emsi_containers_ver = "0.9.0"; -in -stdenv.mkDerivation rec { - pname = "btdu"; - version = "0.5.1"; - - srcs = [ - (fetchurl { - url = "https://github.com/CyberShadow/${pname}/archive/v${version}.tar.gz"; - sha256 = "566269f365811f6db53280fc5476a7fcf34791396ee4e090c150af4280b35ba5"; - }) - (fetchurl { - url = "https://github.com/CyberShadow/ae/archive/v${_d_ae_ver}.tar.gz"; - sha256 = "5ea3f0d9d2d13012ce6a1ee1b52d9fdff9dfb1d5cc7ee5d1b04cab1947ed4d36"; - }) - (fetchurl { - url = "https://github.com/CyberShadow/d-btrfs/archive/v${_d_btrfs_ver}.tar.gz"; - sha256 = "32af4891d93c7898b0596eefb8297b88d3ed5c14c84a5951943b7b54c7599dbd"; - }) - (fetchurl { - url = "https://github.com/D-Programming-Deimos/ncurses/archive/v${_d_ncurses_ver}.tar.gz"; - sha256 = "b5db677b75ebef7a1365ca4ef768f7344a2bc8d07ec223a2ada162f185d0d9c6"; - }) - (fetchurl { - url = "https://github.com/dlang-community/containers/archive/v${_d_emsi_containers_ver}.tar.gz"; - sha256 = "5e256b84bbdbd2bd625cba0472ea27a1fde6d673d37a85fe971a20d52874acaa"; - }) - ]; - - sourceRoot = "."; - - postUnpack = '' - mv ae-${_d_ae_ver} "ae" - ''; - - - nativeBuildInputs = [ dub ldc ]; - buildInputs = [ ncurses zlib ]; - - configurePhase = '' - runHook preConfigure - mkdir home - HOME="home" dub add-local ae ${_d_ae_ver} - HOME="home" dub add-local d-btrfs-${_d_btrfs_ver} ${_d_btrfs_ver} - HOME="home" dub add-local ncurses-${_d_ncurses_ver} ${_d_ncurses_ver} - HOME="home" dub add-local containers-${_d_emsi_containers_ver} ${_d_emsi_containers_ver} - runHook postConfigure - ''; - - buildPhase = '' - runHook preBuild - cd ${pname}-${version} - HOME="../home" dub --skip-registry=all build -b release - runHook postBuild - ''; - - installPhase = '' - runHook preInstall - mkdir -p $out/bin - cp btdu $out/bin/ - runHook postInstall - ''; - - postInstall = '' - ${removeReferencesTo}/bin/remove-references-to -t ${ldc} $out/bin/btdu - ''; - - passthru.updateScript = ./update.py; - - meta = with lib; { - description = "Sampling disk usage profiler for btrfs"; - homepage = "https://github.com/CyberShadow/btdu"; - changelog = "https://github.com/CyberShadow/btdu/releases/tag/v${version}"; - license = licenses.gpl2Only; - platforms = platforms.linux; - maintainers = with maintainers; [ atila ]; - mainProgram = "btdu"; - }; +buildDubPackage rec { + pname = "btdu"; + version = "0.5.1"; + + src = fetchFromGitHub { + owner = "CyberShadow"; + repo = "btdu"; + rev = "v${version}"; + hash = "sha256-3sSZq+5UJH02IO0Y1yL3BLHDb4lk8k6awb5ZysBQciE="; + }; + + dubLock = ./dub-lock.json; + + buildInputs = [ + ncurses + zlib + ]; + + installPhase = '' + runHook preInstall + install -Dm755 btdu -t $out/bin + runHook postInstall + ''; + + meta = with lib; { + description = "Sampling disk usage profiler for btrfs"; + homepage = "https://github.com/CyberShadow/btdu"; + changelog = "https://github.com/CyberShadow/btdu/releases/tag/${src.rev}"; + license = licenses.gpl2Only; + platforms = platforms.linux; + maintainers = with maintainers; [ atila ]; + mainProgram = "btdu"; + }; } diff --git a/pkgs/tools/misc/btdu/dub-lock.json b/pkgs/tools/misc/btdu/dub-lock.json new file mode 100644 index 0000000000000..9a7ab79a5e049 --- /dev/null +++ b/pkgs/tools/misc/btdu/dub-lock.json @@ -0,0 +1,20 @@ +{ + "dependencies": { + "ae": { + "version": "0.0.3236", + "sha256": "0by9yclvk795nw7ilwhv7wh17j2dd7xk54phs8s5jxrwpqx10x52" + }, + "btrfs": { + "version": "0.0.18", + "sha256": "0m8r4skfiryn2nk4wyb61lpvlga1330crr4y1h0q39g9xl3g6myf" + }, + "ncurses": { + "version": "1.0.0", + "sha256": "0ivl88vp2dy9rpv6x3f9jlyqa7aps2x1kkyx80w2d4vcs31pzmb2" + }, + "emsi_containers": { + "version": "0.9.0", + "sha256": "1viz1fjh6jhfvl0d25bb1q7aclm1hrs0d7hhcx1d9c0gg5k6lcpm" + } + } +} diff --git a/pkgs/tools/misc/btdu/update.py b/pkgs/tools/misc/btdu/update.py deleted file mode 100755 index aa3b149d733ea..0000000000000 --- a/pkgs/tools/misc/btdu/update.py +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/env nix-shell -#!nix-shell -i python -p python39Packages.requests - -import requests -import subprocess - -pkgbuild = requests.get('https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=btdu').text - -def grabDepVersions(depDict, pkgbuild=pkgbuild): - for line in pkgbuild.split('\n'): - if depDict["string"] in line: - start = len(depDict["string"]) + 1 - depDict["version"] = line[start:] - break - -def grabDepHashes(key,pkgbuild=pkgbuild): - start = pkgbuild.find(key) + len(key) - end = start+64 - hashes = [] - for i in range(5): - hashes.append(pkgbuild[start:end]) - start = pkgbuild.find("'",end+1) + 1 - end = start+64 - return hashes - -def findLine(key,derivation): - count = 0 - lines = [] - for line in derivation: - if key in line: - lines.append(count) - count += 1 - return lines - -def updateVersions(btdu,ae,btrfs,ncurses,containers,derivation): - key = "let" - line = findLine(key,derivation)[0] + 1 - derivation[line+0] = f' _d_ae_ver = "{ae["version"]}";\n' - derivation[line+1] = f' _d_btrfs_ver = "{btrfs["version"]}";\n' - derivation[line+2] = f' _d_ncurses_ver = "{ncurses["version"]}";\n' - derivation[line+3] = f' _d_emsi_containers_ver = "{containers["version"]}";\n' - - key = "version = " - line = findLine(key,derivation)[0] - derivation[line] = f' version = "{btdu["version"]}";\n' - - return derivation - -def updateHashes(btdu,ae,btrfs,ncurses,containers,derivation): - key = "sha256 = " - hashLines = findLine(key,derivation) - for i in range(len(hashes)): - derivation[hashLines[i]] = f' sha256 = "{hashes[i]}";\n' - - return derivation - -if __name__ == "__main__": - - btdu = {"string": "pkgver"} - ae = {"string": "_d_ae_ver"} - btrfs = {"string": "_d_btrfs_ver"} - ncurses = {"string": "_d_ncurses_ver"} - containers = {"string": "_d_emsi_containers_ver"} - - grabDepVersions(btdu) - grabDepVersions(ae) - grabDepVersions(btrfs) - grabDepVersions(ncurses) - grabDepVersions(containers) - - hashes = grabDepHashes("sha256sums=('") - - nixpkgs = subprocess.check_output(["git", "rev-parse", "--show-toplevel"]).decode("utf-8").strip('\n') - btduFolder = "/pkgs/tools/misc/btdu/" - with open(nixpkgs + btduFolder + "default.nix", 'r') as arq: - derivation = arq.readlines() - - derivation = updateVersions(btdu,ae,btrfs,ncurses,containers,derivation) - derivation = updateHashes(btdu,ae,btrfs,ncurses,containers,derivation) - - with open(nixpkgs + btduFolder + "default.nix", 'w') as arq: - arq.writelines(derivation)