From 678ba70af90cbf6b432dac527f55ea35e276488b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20J=C3=B6rg?= Date: Sun, 31 May 2026 21:15:28 +0200 Subject: [PATCH] Initial Packages --- by-name/arcosparse/default.nix | 26 ++ by-name/copernicusmarine/default.nix | 37 +++ by-name/openzl/default.nix | 102 +++++++ by-name/pygments-styles/default.nix | 25 ++ .../sphinx-last-updated-by-git/default.nix | 50 ++++ by-name/sphinx-shibuya-theme/default.nix | 27 ++ by-name/sphinx-sitemap/default.nix | 30 +++ by-name/sz3/default.nix | 46 ++++ default.nix | 28 ++ flake.nix | 40 +++ npins/default.nix | 249 ++++++++++++++++++ npins/sources.json | 11 + overlay.nix | 6 + shell.nix | 13 + 14 files changed, 690 insertions(+) create mode 100644 by-name/arcosparse/default.nix create mode 100644 by-name/copernicusmarine/default.nix create mode 100644 by-name/openzl/default.nix create mode 100644 by-name/pygments-styles/default.nix create mode 100644 by-name/sphinx-last-updated-by-git/default.nix create mode 100644 by-name/sphinx-shibuya-theme/default.nix create mode 100644 by-name/sphinx-sitemap/default.nix create mode 100644 by-name/sz3/default.nix create mode 100644 default.nix create mode 100644 flake.nix create mode 100644 npins/default.nix create mode 100644 npins/sources.json create mode 100644 overlay.nix create mode 100644 shell.nix diff --git a/by-name/arcosparse/default.nix b/by-name/arcosparse/default.nix new file mode 100644 index 0000000..1eb848c --- /dev/null +++ b/by-name/arcosparse/default.nix @@ -0,0 +1,26 @@ +{ + fetchPypi, + python3Packages, +}: +python3Packages.buildPythonPackage rec { + pname = "arcosparse"; + version = "0.4.2"; + format = "pyproject"; + + src = fetchPypi { + inherit version; + pname = "arcosparse"; + sha256 = "sha256-Z8NW+dsC3uXk101kr8tzsgjAoFb4KNdGkxyFkJ5UhFA="; + }; + + pythonRelaxDeps = true; + + nativeBuildInputs = [ python3Packages.poetry-core ]; + propagatedBuildInputs = with python3Packages; [ + pyarrow + pandas + pystac + tqdm + requests + ]; +} diff --git a/by-name/copernicusmarine/default.nix b/by-name/copernicusmarine/default.nix new file mode 100644 index 0000000..67bcc69 --- /dev/null +++ b/by-name/copernicusmarine/default.nix @@ -0,0 +1,37 @@ +{ + fetchPypi, + python3Packages, + arcosparse, +}: +python3Packages.buildPythonPackage rec { + pname = "copernicusmarine"; + version = "2.2.2"; + format = "pyproject"; + + src = fetchPypi { + inherit version; + pname = "copernicusmarine"; + sha256 = "sha256-5T3iH4Hh08wIao2MMveb/bVnVz0pK0PoN4CRk811P0g="; + }; + + pythonRelaxDeps = true; + + nativeBuildInputs = [ python3Packages.poetry-core ]; + propagatedBuildInputs = with python3Packages; [ + boto3 + click + dask + h5netcdf + arcosparse + lxml + numpy + pydantic + pystac + requests + semver + setuptools + tqdm + xarray + zarr + ]; +} diff --git a/by-name/openzl/default.nix b/by-name/openzl/default.nix new file mode 100644 index 0000000..bd734a1 --- /dev/null +++ b/by-name/openzl/default.nix @@ -0,0 +1,102 @@ +{ + autoPatchelfHook, + pkg-config, + cmake, + fetchFromGitHub, + patchelf, + python3, + stdenv, + xgboost, +}: +stdenv.mkDerivation { + pname = "openzl"; + version = "0.2.0"; + + src = fetchFromGitHub { + owner = "facebook"; + repo = "openzl"; + rev = "46e4826715ed31c9fe13922951f088f0af5b6a91"; + sha256 = "sha256-ZMFoEjgKQPVF+u3gNtKpNwuql1X3wemg4ug/Qy+Js1o="; + fetchSubmodules = true; + }; + + nativeBuildInputs = [ + autoPatchelfHook + cmake + patchelf + pkg-config + python3 + ]; + + buildInputs = [ xgboost ]; + + # Replace the ExternalProject_Add(xgboost_external ...) block in ml_selector + # with find_package calls and a stub INTERFACE target, so the nixpkgs xgboost + # is used instead of downloading from github (which is not allowed in the sandbox). + preConfigure = '' + python3 - <<'PYEOF' + import re, pathlib + + p = pathlib.Path("tools/ml_selector/CMakeLists.txt") + src = p.read_text() + + replacement = """\ + find_package(xgboost REQUIRED) + # Stub target: downstream CMakeLists add_dependencies on xgboost_external + add_library(xgboost_external INTERFACE) + target_link_libraries(xgboost_external INTERFACE xgboost::xgboost) + + add_library(xgboost ALIAS xgboost::xgboost) + """ + + # Replace everything from include(ExternalProject) up to (and including) + # add_dependencies(dmlc xgboost_external) + src = re.sub( + r'include\(ExternalProject\).*?add_dependencies\(dmlc xgboost_external\)\n', + replacement, + src, + flags=re.DOTALL, + ) + + # Fix ml_selector include path: remove reference to XGBOOST_INSTALL_DIR + src = src.replace( + " ''${XGBOOST_INSTALL_DIR}/include\n", + "", + ) + + # Replace xgboost/dmlc link targets with xgboost::xgboost (dmlc is bundled in xgboost) + src = src.replace( + " openzl\n openzl_cpp\n xgboost\n dmlc\n", + " openzl\n openzl_cpp\n xgboost::xgboost\n", + ) + + p.write_text(src) + PYEOF + ''; + + postInstall = '' + # Install the zli CLI and all its internal shared libraries that CMake + # does not install by default (libcommands.so, libargs.so, etc.). + install -Dm755 cli/zli $out/bin/zli + find "$NIX_BUILD_TOP" \( -name '*.so' -o -name '*.so.*' \) \ + -not -path "$out/*" \ + -exec install -Dm755 {} -t $out/lib \; + + # Fix rpaths: replace build-dir references with $out/lib + for f in $out/bin/* $out/lib/*.so $out/lib/*.so.*; do + [ -f "$f" ] || continue + patchelf --set-rpath "$out/lib" "$f" || true + done + ''; + + cmakeFlags = [ + "-DBUILD_SHARED_LIBS=ON" + "-DOPENZL_BUILD_TESTS=OFF" + "-DOPENZL_BUILD_BENCHMARKS=OFF" + "-DOPENZL_BUILD_PYTHON_EXT=OFF" + "-DOPENZL_BUILD_EXAMPLES=OFF" + "-DOPENZL_ALLOW_INTROSPECTION=ON" + ]; + + meta.mainProgram = "zli"; +} diff --git a/by-name/pygments-styles/default.nix b/by-name/pygments-styles/default.nix new file mode 100644 index 0000000..8a19ace --- /dev/null +++ b/by-name/pygments-styles/default.nix @@ -0,0 +1,25 @@ +{ + python3Packages, + fetchPypi, +}: +python3Packages.buildPythonPackage rec { + pname = "pygments-styles"; + version = "0.3.0"; + + format = "wheel"; + + src = fetchPypi { + inherit version; + format = "wheel"; + dist = "py3"; + python = "py3"; + pname = "pygments_styles"; + hash = "sha256-xsRemTnrdZA0W8kIQRO6xGxF8SsAnRNCK+AugOhKA0w="; + }; + + propagatedBuildInputs = [ + python3Packages.pygments + ]; + + pythonImportsCheck = [ "pygments_styles" ]; +} diff --git a/by-name/sphinx-last-updated-by-git/default.nix b/by-name/sphinx-last-updated-by-git/default.nix new file mode 100644 index 0000000..4b00647 --- /dev/null +++ b/by-name/sphinx-last-updated-by-git/default.nix @@ -0,0 +1,50 @@ +{ + gitMinimal, + python3Packages, + fetchFromGitHub, + lib, +}: +python3Packages.buildPythonPackage { + pname = "sphinx-last-updated-by-git"; + version = "0.3.8-unstable-2025-08-26"; + pyproject = true; + + src = fetchFromGitHub { + owner = "mgeier"; + repo = "sphinx-last-updated-by-git"; + rev = "07ac1a98af2a927e773a65c6524ce83067c977b8"; + hash = "sha256-2TGFR11Ejh/9zpVC/TEdmMNaBt38wE5yeJeYixZSVUE="; + fetchSubmodules = true; + leaveDotGit = true; + }; + + build-system = [ python3Packages.setuptools ]; + + dependencies = with python3Packages; [ + sphinx + gitpython + ]; + + postPatch = '' + # we cant just substitute by matching `'git'` due to collisons + substituteInPlace src/sphinx_last_updated_by_git.py \ + --replace-fail "'git', 'ls-tree'" " '${lib.getExe gitMinimal}', 'ls-tree'" \ + --replace-fail "'git', 'log'" "'${lib.getExe gitMinimal}', 'log'" \ + --replace-fail "'git', 'rev-parse'" "'${lib.getExe gitMinimal}', 'rev-parse'" \ + ''; + + propagatedBuildInputs = [ gitMinimal ]; + + nativeCheckInputs = with python3Packages; [ + pytestCheckHook + sphinx-pytest + pytest-cov-stub + ]; + + disabledTests = [ + "test_no_git" # we hardcoded the git path + + "test_repo_shallow" + "test_repo_shallow_without_warning" + ]; +} diff --git a/by-name/sphinx-shibuya-theme/default.nix b/by-name/sphinx-shibuya-theme/default.nix new file mode 100644 index 0000000..2c386d3 --- /dev/null +++ b/by-name/sphinx-shibuya-theme/default.nix @@ -0,0 +1,27 @@ +{ + python3Packages, + fetchPypi, + pygments-styles, +}: +python3Packages.buildPythonPackage rec { + pname = "sphinx-shibuya-theme"; + version = "2026.1.9"; + + format = "wheel"; + + src = fetchPypi { + inherit version; + format = "wheel"; + dist = "py3"; + python = "py3"; + pname = "shibuya"; + hash = "sha256-tYo8xuVhnHHQD88L5KMGDIcEDCpiobPxqTpqQcqOr0U="; + }; + + propagatedBuildInputs = [ + python3Packages.sphinx + pygments-styles + ]; + + pythonImportsCheck = [ "shibuya" ]; +} diff --git a/by-name/sphinx-sitemap/default.nix b/by-name/sphinx-sitemap/default.nix new file mode 100644 index 0000000..974f21d --- /dev/null +++ b/by-name/sphinx-sitemap/default.nix @@ -0,0 +1,30 @@ +{ + python3Packages, + fetchFromGitHub, + sphinx-last-updated-by-git, +}: +python3Packages.buildPythonPackage rec { + pname = "sphinx-sitemap"; + version = "2.9.0"; + pyproject = true; + + src = fetchFromGitHub { + owner = "jdillard"; + repo = "sphinx-sitemap"; + tag = "v${version}"; + hash = "sha256-TiR6F9wMWOGYexSKDzbSPPq0oiIDrZwSiO3a9DajL+0="; + }; + + build-system = [ python3Packages.setuptools ]; + + dependencies = [ + python3Packages.sphinx + sphinx-last-updated-by-git + ]; + + nativeCheckInputs = with python3Packages; [ + pytestCheckHook + sphinx-pytest + defusedxml + ]; +} diff --git a/by-name/sz3/default.nix b/by-name/sz3/default.nix new file mode 100644 index 0000000..83065aa --- /dev/null +++ b/by-name/sz3/default.nix @@ -0,0 +1,46 @@ +{ + lib, + stdenv, + cmake, + pkg-config, + fetchFromGitHub, + zstd, + gsl, + llvmPackages, +}: +stdenv.mkDerivation { + pname = "sz3"; + version = "3.3.x"; + + src = fetchFromGitHub { + owner = "szcompressor"; + repo = "SZ3"; + rev = "34b36f2af0d43aa4f5dea0e39500e91f6d35c9cf"; + sha256 = "0fckf5939m9d2w3095isnq3qfrz8fxpppn7y3c2hwzdh72vdzic7"; + }; + + nativeBuildInputs = [ + cmake + pkg-config + ]; + + buildInputs = + [ + zstd + gsl + ] + ++ lib.optionals stdenv.cc.isClang [ + llvmPackages.openmp + ]; + + cmakeFlags = [ + "-DBUILD_SHARED_LIBS=ON" + ]; + + meta = with lib; { + description = "A modular error-bounded lossy compression framework for scientific datasets"; + homepage = "https://github.com/szcompressor/SZ3"; + license = licenses.bsd3; + platforms = platforms.unix; + }; +} diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..4b00065 --- /dev/null +++ b/default.nix @@ -0,0 +1,28 @@ +{ + sources ? import ./npins, + pkgs ? import sources.nixpkgs { config.allowUnfree = true; }, + ... +}: + +let + inherit (pkgs.lib) callPackageWith; + + callPackage = callPackageWith (pkgs // self); + + listDirs = + dir: + let + entries = builtins.readDir dir; + in + builtins.filter (n: entries.${n} == "directory") (builtins.attrNames entries); + + mkPackages = + fun: dir: + builtins.map (name: { + inherit name; + value = fun (dir + "/${name}") { }; + }) (listDirs dir); + + self = builtins.listToAttrs (mkPackages callPackage ./by-name); +in +self diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..863767f --- /dev/null +++ b/flake.nix @@ -0,0 +1,40 @@ +{ + description = "Oceanbox internal Nix package overlay"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = + { self, nixpkgs, ... }: + let + eachSystem = nixpkgs.lib.genAttrs [ + "aarch64-darwin" + "aarch64-linux" + "x86_64-darwin" + "x86_64-linux" + ]; + + pkgsFor = + system: + import nixpkgs { + inherit system; + config.allowUnfree = true; + overlays = [ self.overlays.default ]; + }; + in + { + overlays = { + default = import ./overlay.nix; + }; + + packages = eachSystem ( + system: + import ./default.nix { + pkgs = pkgsFor system; + } + ); + + legacyPackages = eachSystem pkgsFor; + }; +} diff --git a/npins/default.nix b/npins/default.nix new file mode 100644 index 0000000..884fc8c --- /dev/null +++ b/npins/default.nix @@ -0,0 +1,249 @@ +/* + This file is provided under the MIT licence: + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +# Generated by npins. Do not modify; will be overwritten regularly +let + # Backwards-compatibly make something that previously didn't take any arguments take some + # The function must return an attrset, and will unfortunately be eagerly evaluated + # Same thing, but it catches eval errors on the default argument so that one may still call it with other arguments + mkFunctor = + fn: + let + e = builtins.tryEval (fn { }); + in + (if e.success then e.value else { error = fn { }; }) // { __functor = _self: fn; }; + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 + range = + first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 + stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 + stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); + concatStrings = builtins.concatStringsSep ""; + + # If the environment variable NPINS_OVERRIDE_${name} is set, then use + # the path directly as opposed to the fetched source. + # (Taken from Niv for compatibility) + mayOverride = + name: path: + let + envVarName = "NPINS_OVERRIDE_${saneName}"; + saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; + ersatz = builtins.getEnv envVarName; + in + if ersatz == "" then + path + else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + builtins.trace "Overriding path of \"${name}\" with \"${ersatz}\" due to set \"${envVarName}\"" ( + if builtins.substring 0 1 ersatz == "/" then + /. + ersatz + else + /. + builtins.getEnv "PWD" + "/${ersatz}" + ); + + mkSource = + name: spec: + { + pkgs ? null, + }: + assert spec ? type; + let + # Unify across builtin and pkgs fetchers. + # `fetchGit` requires a wrapper because of slight API differences. + fetchers = + if pkgs == null then + { + inherit (builtins) fetchTarball fetchurl; + # For some fucking reason, fetchGit has a different signature than the other builtin fetchers … + fetchGit = args: (builtins.fetchGit args).outPath; + } + else + { + fetchTarball = + { + url, + sha256, + }: + pkgs.fetchzip { + inherit url sha256; + extension = "tar"; + }; + inherit (pkgs) fetchurl; + fetchGit = + { + url, + submodules, + rev, + name, + narHash, + }: + pkgs.fetchgit { + inherit url rev name; + fetchSubmodules = submodules; + hash = narHash; + }; + }; + + # Dispatch to the correct code path based on the type + path = + if spec.type == "Git" then + mkGitSource fetchers spec + else if spec.type == "GitRelease" then + mkGitSource fetchers spec + else if spec.type == "PyPi" then + mkPyPiSource fetchers spec + else if spec.type == "Channel" then + mkChannelSource fetchers spec + else if spec.type == "Tarball" then + mkTarballSource fetchers spec + else if spec.type == "Container" then + mkContainerSource pkgs spec + else + builtins.throw "Unknown source type ${spec.type}"; + in + spec // { outPath = mayOverride name path; }; + + mkGitSource = + { + fetchTarball, + fetchGit, + ... + }: + { + repository, + revision, + url ? null, + submodules, + hash, + ... + }: + assert repository ? type; + # At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository + # In the latter case, there we will always be an url to the tarball + if url != null && !submodules then + fetchTarball { + inherit url; + sha256 = hash; + } + else + let + url = + if repository.type == "Git" then + repository.url + else if repository.type == "GitHub" then + "https://github.com/${repository.owner}/${repository.repo}.git" + else if repository.type == "GitLab" then + "${repository.server}/${repository.repo_path}.git" + else if repository.type == "Forgejo" then + "${repository.server}/${repository.owner}/${repository.repo}.git" + else + throw "Unrecognized repository type ${repository.type}"; + urlToName = + url: rev: + let + matched = builtins.match "^.*/([^/]*)(\\.git)?$" url; + + short = builtins.substring 0 7 rev; + + appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else ""; + in + "${if matched == null then "source" else builtins.head matched}${appendShort}"; + name = urlToName url revision; + in + fetchGit { + rev = revision; + narHash = hash; + + inherit name submodules url; + }; + + mkPyPiSource = + { fetchurl, ... }: + { + url, + hash, + ... + }: + fetchurl { + inherit url; + sha256 = hash; + }; + + mkChannelSource = + { fetchTarball, ... }: + { + url, + hash, + ... + }: + fetchTarball { + inherit url; + sha256 = hash; + }; + + mkTarballSource = + { fetchTarball, ... }: + { + url, + locked_url ? url, + hash, + ... + }: + fetchTarball { + url = locked_url; + sha256 = hash; + }; + + mkContainerSource = + pkgs: + { + image_name, + image_tag, + image_digest, + ... + }: + if pkgs == null then + builtins.throw "container sources require passing in a Nixpkgs value: https://github.com/andir/npins/blob/master/README.md#using-the-nixpkgs-fetchers" + else + pkgs.dockerTools.pullImage { + imageName = image_name; + imageDigest = image_digest; + finalImageTag = image_tag; + }; +in +mkFunctor ( + { + input ? ./sources.json, + }: + let + data = + if builtins.isPath input then + # while `readFile` will throw an error anyways if the path doesn't exist, + # we still need to check beforehand because *our* error can be caught but not the one from the builtin + # *piegames sighs* + if builtins.pathExists input then + builtins.fromJSON (builtins.readFile input) + else + throw "Input path ${toString input} does not exist" + else if builtins.isAttrs input then + input + else + throw "Unsupported input type ${builtins.typeOf input}, must be a path or an attrset"; + version = data.version; + in + if version == 7 then + builtins.mapAttrs (name: spec: mkFunctor (mkSource name spec)) data.pins + else + throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`" +) diff --git a/npins/sources.json b/npins/sources.json new file mode 100644 index 0000000..c4e5084 --- /dev/null +++ b/npins/sources.json @@ -0,0 +1,11 @@ +{ + "pins": { + "nixpkgs": { + "type": "Channel", + "name": "nixos-unstable", + "url": "https://releases.nixos.org/nixos/unstable/nixos-26.05pre1004030.64c08a7ca051/nixexprs.tar.xz", + "hash": "sha256-NpH8iEQ5JHv/BtUuzTEXUMDxPLetCDzIv4OxL8H7Kps=" + } + }, + "version": 7 +} diff --git a/overlay.nix b/overlay.nix new file mode 100644 index 0000000..44f0ab7 --- /dev/null +++ b/overlay.nix @@ -0,0 +1,6 @@ +self: super: +let + entries = builtins.readDir ./by-name; + packages = builtins.filter (n: entries.${n} == "directory") (builtins.attrNames entries); +in +super.lib.genAttrs packages (name: self.callPackage ./by-name/${name} { }) diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..3339b29 --- /dev/null +++ b/shell.nix @@ -0,0 +1,13 @@ +{ + sources ? import ./npins, + pkgs ? import sources.nixpkgs { }, +}: + +pkgs.mkShellNoCC { + packages = [ + pkgs.npins + pkgs.nix-init + pkgs.nixfmt-rfc-style + pkgs.nix-update + ]; +}