Repository: NixOS/nixpkgs
Pull request #385666: liblzf: init at 3.6
Author: login: tetov
Labels: name: 10.rebuild-linux: 1-10
description: This PR causes between 1 and 10 packages to rebuild on Linux.
name: 10.rebuild-darwin: 1-10
description: This PR causes between 1 and 10 packages to rebuild on Darwin.
name: 10.rebuild-darwin: 1
description: This PR causes 1 package to rebuild on Darwin.
name: 10.rebuild-linux: 1
description: This PR causes 1 package to rebuild on Linux.
name: 12.approvals: 1
description: This PR was reviewed and approved by one person.
name: 8.has: maintainer-list (update)
description: This PR changes `maintainers/maintainer-list.nix`
Created: 2025-02-27T23:09:36Z | Merged: 2025-04-29T14:49:48Z

[liblzf](http://software.schmorp.de/pkg/liblzf.html) is a very small and quick compression library implementing the [Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch) algorithm.

It's used in the [PCD format](https://pointclouds.org/documentation/tutorials/pcd_file_format.html), part of [Point Cloud Library](https://pointclouds.org/) (But PCL has a C++ implementation in their sourcetree). I'm looking into this since I want to python bindings that link to `liblzf.so`.

## Things done

<!-- Please check what applies. Note that these are not hard requirements but merely serve as information for reviewers. -->

- Built on platform(s)
  - [x] x86_64-linux
  - [ ] aarch64-linux
  - [ ] x86_64-darwin
  - [ ] aarch64-darwin
- For non-Linux: Is sandboxing enabled in `nix.conf`? (See [Nix manual](https://nixos.org/manual/nix/stable/command-ref/conf-file.html))
  - [ ] `sandbox = relaxed`
  - [ ] `sandbox = true`
- [x] Tested, as applicable:
  - [NixOS test(s)](https://nixos.org/manual/nixos/unstable/index.html#sec-nixos-tests) (look inside [nixos/tests](https://github.com/NixOS/nixpkgs/blob/master/nixos/tests))
  - and/or [package tests](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md#package-tests)
  - or, for functions and "core" functionality, tests in [lib/tests](https://github.com/NixOS/nixpkgs/blob/master/lib/tests) or [pkgs/test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/test)
  - made sure NixOS tests are [linked](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md#linking-nixos-module-tests-to-a-package) to the relevant packages
- [x] Tested compilation of all packages that depend on this change using `nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"`. Note: all changes have to be committed, also see [nixpkgs-review usage](https://github.com/Mic92/nixpkgs-review#usage)
- [x] Tested basic functionality of all binary files (usually in `./result/bin/`)
- [25.05 Release Notes](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2505.section.md) (or backporting [24.11](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2411.section.md) and [25.05](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2505.section.md) Release notes)
  - [ ] (Package updates) Added a release notes entry if the change is major or breaking
  - [ ] (Module updates) Added a release notes entry if the change is significant
  - [ ] (Module addition) Added a release notes entry if adding a new NixOS module
- [x] Fits [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md).

<!--
To help with the large amounts of pull requests, we would appreciate your
reviews of other pull requests, especially simple package updates. Just leave a
comment describing what you have tested in the relevant package/service.
Reviewing helps to reduce the average time-to-merge for everyone.
Thanks a lot if you do!

List of open PRs: https://github.com/NixOS/nixpkgs/pulls
Reviewing guidelines: https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md#reviewing-contributions
-->

---

Add a :+1: [reaction] to [pull requests you find important].

[reaction]: https://github.blog/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/
[pull requests you find important]: https://github.com/NixOS/nixpkgs/pulls?q=is%3Aopen+sort%3Areactions-%2B1-desc



Diff:
diff --git a/maintainers/maintainer-list.nix b/maintainers/maintainer-list.nix
index b14f78609e476..6dea01fa8860b 100644
--- a/maintainers/maintainer-list.nix
+++ b/maintainers/maintainer-list.nix
@@ -21519,6 +21519,13 @@
     githubId = 886074;
     name = "Matthieu Coudron";
   };
+  tetov = {
+    email = "anton@tetov.se";
+    github = "tetov";
+    githubId = 14882117;
+    keys = [ { fingerprint = "2B4D 0035 AFF0 F7DA CE5B  29D7 337D DB57 4A88 34DB"; } ];
+    name = "Anton Tetov";
+  };
   teutat3s = {
     email = "teutates@mailbox.org";
     matrix = "@teutat3s:pub.solar";
diff --git a/pkgs/by-name/li/liblzf/lib_test.c b/pkgs/by-name/li/liblzf/lib_test.c
new file mode 100644
index 0000000000000..04655d35a1e46
--- /dev/null
+++ b/pkgs/by-name/li/liblzf/lib_test.c
@@ -0,0 +1,33 @@
+#include "lzf.h"
+#include <stdio.h>
+#include <string.h>
+
+int main(void) {
+  const char *test = "liblzf test for nixpkgs, nixpkgs for test liblzf";
+  const size_t ilen = strlen(test) + 1;
+
+  printf("Test string length: %zu\n", ilen);
+
+  char compressed[100];
+  char decompressed[100];
+
+  unsigned int clen =
+      lzf_compress(test, ilen, compressed, sizeof(compressed));
+  if (!clen)
+    return 1;
+
+  printf("Compressed length: %d\n", clen);
+
+  unsigned int dlen =
+      lzf_decompress(compressed, clen, decompressed, sizeof(decompressed));
+  if (!dlen)
+    return 2;
+
+  if (strcmp(test, decompressed) != 0) {
+    printf("Strings don't match!\n");
+    return 3;
+  }
+
+  printf("Strings match, tests passed!\n");
+  return 0;
+}
diff --git a/pkgs/by-name/li/liblzf/package.nix b/pkgs/by-name/li/liblzf/package.nix
new file mode 100644
index 0000000000000..693488d64db44
--- /dev/null
+++ b/pkgs/by-name/li/liblzf/package.nix
@@ -0,0 +1,137 @@
+{
+  lib,
+  stdenv,
+  fetchDebianPatch,
+  fetchpatch,
+  fetchurl,
+  pkg-config,
+  testers,
+  validatePkgConfig,
+  autoconf,
+  automake,
+  libtool,
+}:
+stdenv.mkDerivation (finalAttrs: {
+  pname = "liblzf";
+  version = "3.6";
+
+  src = fetchurl {
+    url = "http://dist.schmorp.de/liblzf/liblzf-${finalAttrs.version}.tar.gz";
+    hash = "sha256-nF3gH3ucyuQMP2GdJqer7JmGwGw20mDBec7dBLiftGo=";
+  };
+
+  patches = [
+    (fetchDebianPatch {
+      inherit (finalAttrs) pname version;
+      debianRevision = "4";
+      patch = "0001-Make-sure-that-the-library-is-linked-with-C-symbols.patch";
+      hash = "sha256-Rgfp/TysRcEJaogOo/Xno+G4HZzj9Loa69DL43Bp1Ok=";
+    })
+    (
+      let
+        name = "liblzf-3.6-autoconf-20140314.patch";
+      in
+      fetchpatch {
+        inherit name;
+        url = "https://src.fedoraproject.org/rpms/liblzf/raw/53da654eead51a24ac81a28e1b1c531eb1afab28/f/${name}";
+        hash = "sha256-rkhI8w0HV3fGiDfHiXBzrnxqGDE/Yo5ntePrsscMiyg=";
+      }
+    )
+  ];
+
+  nativeBuildInputs = [
+    autoconf
+    automake
+    libtool
+    pkg-config
+    validatePkgConfig
+  ];
+
+  preConfigure = ''
+    sh ./bootstrap.sh
+  '';
+
+  postInstall = ''
+    pushd $out/bin
+    ln -s lzf unlzf
+    popd
+  '';
+
+  outputs = [
+    "out"
+    "dev"
+  ];
+
+  passthru.tests = {
+    pkgConfigTest = testers.hasPkgConfigModules {
+      package = finalAttrs.finalPackage;
+      version = "${finalAttrs.version}.0";
+      versionCheck = true;
+    };
+
+    exeTest = testers.runCommand {
+      name = "${finalAttrs.pname}-exe-test";
+      buildInputs = [ finalAttrs.finalPackage ];
+      script = ''
+        lzf -h 2> /dev/null
+
+        echo "LZFLZFLZFLZFLZFLZFLZFLZF" > test.txt
+
+        # unlzf writes to filename minus ".lzf"
+        cp test.txt test.txt.orig
+
+        lzf test.txt
+        unlzf test.txt.lzf
+
+        # Compare results
+        if ! cmp -s test.txt test.txt.orig; then
+          echo "Executable test failed: files don't match"
+          exit 1
+        fi
+
+        echo "Decompressed output matches test string (lzf & unlzf)"
+
+        touch $out
+      '';
+    };
+
+    shlibTest = testers.runCommand {
+      name = "${finalAttrs.pname}-shlib-test";
+      inherit stdenv; # with CC
+      nativeBuildInputs = [ pkg-config ];
+      buildInputs = [
+        finalAttrs.finalPackage.dev
+        finalAttrs.finalPackage
+      ];
+      # tests both the library and pkg-config file
+      script = ''
+        $CC -g ${./lib_test.c} -o lib_test \
+          $(pkg-config --cflags --libs liblzf)
+
+        ./lib_test >/dev/null
+
+        echo "Built and tested file linked against liblzf using pkg-config"
+        touch $out
+      '';
+    };
+  };
+
+  meta = {
+    changelog =
+      "http://cvs.schmorp.de/liblzf/Changes?pathrev=rel-"
+      + builtins.replaceStrings [ "." ] [ "_" ] finalAttrs.version;
+    description = "Small data compression library";
+    downloadPage = "http://dist.schmorp.de/liblzf/";
+    homepage = "http://software.schmorp.de/pkg/liblzf.html";
+    license = with lib.licenses; [
+      bsd2
+      gpl2Plus
+    ];
+    mainProgram = "lzf";
+    maintainers = with lib.maintainers; [
+      tetov
+    ];
+    platforms = lib.platforms.unix;
+    pkgConfigModules = [ "liblzf" ];
+  };
+})


Reviews:
state: APPROVED
author_association: NONE
submitted_at: 2025-02-27T23:30:32Z
user: login: tetov
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-28T15:01:47Z
state: APPROVED
author_association: NONE
submitted_at: 2025-03-02T09:05:44Z
state: APPROVED
author_association: NONE
submitted_at: 2025-03-02T12:02:05Z
user: login: SuperSandro2000
body: Can we upstream the test files and changes?
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-14T10:31:42Z
user: login: tetov
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-15T08:52:29Z
user: login: SuperSandro2000
state: APPROVED
author_association: MEMBER
submitted_at: 2025-04-29T14:49:33Z

Review comments:
diff_hunk: @@ -0,0 +1,66 @@
+{
+  lib,
+  fetchurl,
+  stdenv,
+}:
+stdenv.mkDerivation (finalAttrs: {
+  pname = "liblzf";
+  version = "3.6";
+
+  # used for changelog and test file
+  cvsTag = "rel-${builtins.replaceStrings [ "." ] [ "_" ] finalAttrs.version}";
+
+  src = fetchurl {
+    url = "http://dist.schmorp.de/liblzf/liblzf-${finalAttrs.version}.tar.gz";
+    hash = "sha256-nF3gH3ucyuQMP2GdJqer7JmGwGw20mDBec7dBLiftGo=";
+  };
+
+  doCheck = true;
+
+  preCheck = ''
path: pkgs/by-name/li/liblzf/package.nix
user: login: tetov
body: Good point. I've fixed that but I realized I need to patch some files to get a shared library out of the build process. I'll push a new commit soon-ish.
created_at: 2025-02-28T15:01:47Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,139 @@
+{
+  lib,
+  stdenv,
+  autoreconfHook,
+  fetchDebianPatch,
+  fetchurl,
+  pkg-config,
+  testers,
+  validatePkgConfig,
+  writeText,
+}:
+stdenv.mkDerivation (finalAttrs: {
+  pname = "liblzf";
+  version = "3.6";
+  shlib_version = "1:0:0"; # for libtool
+
+  # used for changelog
+  cvsTag = "rel-${builtins.replaceStrings [ "." ] [ "_" ] finalAttrs.version}";
path: pkgs/by-name/li/liblzf/package.nix
user: login: SuperSandro2000
body: Can we move this to a let in?
created_at: 2025-04-14T10:30:21Z
author_association: MEMBER
diff_hunk: @@ -0,0 +1,139 @@
+{
+  lib,
+  stdenv,
+  autoreconfHook,
+  fetchDebianPatch,
+  fetchurl,
+  pkg-config,
+  testers,
+  validatePkgConfig,
+  writeText,
+}:
+stdenv.mkDerivation (finalAttrs: {
+  pname = "liblzf";
+  version = "3.6";
+  shlib_version = "1:0:0"; # for libtool
+
+  # used for changelog
+  cvsTag = "rel-${builtins.replaceStrings [ "." ] [ "_" ] finalAttrs.version}";
path: pkgs/by-name/li/liblzf/package.nix
user: login: tetov
body: Resolved in 05221c935ab2ade0d6c328caed2032bc6d8e09d0 :)
created_at: 2025-04-15T08:52:29Z
author_association: CONTRIBUTOR

PR comments:
user: login: tetov
created_at: 2025-03-01T20:47:29Z
body: Autotools or CMake?

Debian, Ubuntu and conda-forge use CMake with a [CMakeList.txt](https://sources.debian.org/src/liblzf/3.6-4/debian/extras/CMakeLists.txt/) that is from Debian originally I think.

In Fedora there's a [big patch for the autotool files](https://src.fedoraproject.org/rpms/liblzf/blob/53da654eead51a24ac81a28e1b1c531eb1afab28/f/liblzf-3.6-autoconf-20140314.patch).

I decided to use Autotools but patch configure.ac and add a Makefile.am and pkg-config file since I that makes the changes rather small in comparison to upstream.

I'm open to converting to CMake if there's good reasons though :).
author_association: CONTRIBUTOR
user: login: tetov
created_at: 2025-03-02T08:26:45Z
body: One of the ofBorg runs have stopped just after fixup phase it seems like..

Should I retrigger CI with an empty commit?
author_association: CONTRIBUTOR
user: login: tetov
created_at: 2025-03-02T12:12:45Z
body: Thanks @nayeko!
author_association: CONTRIBUTOR
user: login: tetov
created_at: 2025-03-02T12:26:27Z
body: ## `nixpkgs-review` result

Generated using [`nixpkgs-review`](https://github.com/Mic92/nixpkgs-review).

Command: `nixpkgs-review pr 385666`

---
### `x86_64-linux`
<details>
  <summary>:white_check_mark: 2 packages built:</summary>
  <ul>
    <li>liblzf</li>
    <li>liblzf.dev</li>
  </ul>
</details>
author_association: CONTRIBUTOR
user: login: nixos-discourse
created_at: 2025-04-14T08:46:46Z
body: This pull request has been mentioned on **NixOS Discourse**. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/5383

author_association: NONE
user: login: tetov
created_at: 2025-04-14T10:52:46Z
body: > Can we upstream the test files and changes?

I had planned to, but got discouraged after this comment:

https://src.fedoraproject.org/rpms/liblzf/blob/rawhide/f/liblzf.spec#_11

I could of course try anyway.
author_association: CONTRIBUTOR
user: login: SuperSandro2000
created_at: 2025-04-14T14:43:13Z
body: But we could fetchpatch and filter the patches from fedora, could we? https://src.fedoraproject.org/rpms/liblzf/blob/rawhide/f/liblzf-3.6-autoconf-20140314.patch
author_association: MEMBER
user: login: tetov
created_at: 2025-04-15T08:20:31Z
body: > But we could fetchpatch and filter the patches from fedora, could we? https://src.fedoraproject.org/rpms/liblzf/blob/rawhide/f/liblzf-3.6-autoconf-20140314.patch

Please see: https://github.com/NixOS/nixpkgs/pull/385666#issuecomment-2692410582

It's either more patching but made by other distro, or a bit less and maintained here. I would like to get some input on how to proceed. :)
author_association: CONTRIBUTOR
user: login: tetov
created_at: 2025-04-28T16:33:24Z
body: I followed your suggestion @SuperSandro2000 and it did turn out cleaner. My commit log didn't though..

## `nixpkgs-review` result

Generated using [`nixpkgs-review`](https://github.com/Mic92/nixpkgs-review).

Command: `nixpkgs-review pr 385666`

---
### `x86_64-linux`
<details>
  <summary>:white_check_mark: 2 packages built:</summary>
  <ul>
    <li>liblzf</li>
    <li>liblzf.dev</li>
  </ul>
</details>

author_association: CONTRIBUTOR