Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions pkgs/by-name/op/optiland/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
lib,
stdenvNoCC,
python3Packages,
qt6,
}:

stdenvNoCC.mkDerivation (finalAttrs: {
pname = "optiland-python-env";
# Inheriting src too, to hint nix-update
inherit (python3Packages.optiland) version src;
strictDeps = true;
__structuredAttrs = true;

nativeBuildInputs = [
qt6.wrapQtAppsHook
];
buildInputs = [
qt6.qtbase
];

dontUnpack = true;
dontConfigure = true;

passthru = {
pythonPaths = python3Packages.requiredPythonModules (
[
python3Packages.optiland
python3Packages.python
]
++ python3Packages.optiland.passthru.optional-dependencies.gui
++ python3Packages.optiland.passthru.optional-dependencies.torch
);
pythonPath =
lib.makeSearchPathOutput "out" python3Packages.python.sitePackages
finalAttrs.finalPackage.passthru.pythonPaths;
makeWrapperArgs = [
# leaving here room for potential additional arguments
];
};

# Modelded after `python.buildEnv`'s postBuild, but we don't link paths at
# all, only create $out/bin/optiland (and potentially more) executable(s).
buildPhase = ''
mkdir -p $out/bin
cd ${python3Packages.optiland}/bin
for prg in *; do
Comment thread
doronbehar marked this conversation as resolved.
if [ -f "$prg" ] && [ -x "$prg" ]; then
makeWrapper "${python3Packages.optiland}/bin/$prg" "$out/bin/$prg" \
--set NIX_PYTHONPREFIX "$out" \
--set NIX_PYTHONEXECUTABLE "${placeholder "out"}/bin/${python3Packages.python.executable}" \
--set NIX_PYTHONPATH ${finalAttrs.finalPackage.passthru.pythonPath} \
--set PYTHONNOUSERSITE "true" \
${lib.concatStringsSep " " finalAttrs.finalPackage.passthru.makeWrapperArgs}
fi
done
'';

dontInstall = true;

meta = python3Packages.optiland.meta // {
description = python3Packages.optiland.meta.description + "; The GUI";
mainProgram = "optiland";
};
})
118 changes: 118 additions & 0 deletions pkgs/development/python-modules/optiland/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{
lib,
buildPythonPackage,
fetchFromGitHub,
fetchpatch,

# build-system
hatchling,

# dependencies
matplotlib,
numba,
numpy,
pandas,
pyyaml,
requests,
scipy,
seaborn,
tabulate,
typing-extensions,
vtk,

# tests
pytestCheckHook,

# optional-dependencies
pyside6,
qtconsole,
torch,
}:

buildPythonPackage (finalAttrs: {
pname = "optiland";
version = "0.6.0";
pyproject = true;
__structuredAttrs = true;

src = fetchFromGitHub {
owner = "HarrisonKramer";
repo = "optiland";
tag = "v${finalAttrs.version}";
hash = "sha256-s+EFsfj+3VIgpqhBv8f6IblyxfxXHWnO/i1lO3bEke4=";
};

patches = [
# wayland is not supported, see:
# https://github.com/optiland/optiland/issues/556
(fetchpatch {
url = "https://github.com/optiland/optiland/commit/9644df6e06bd24c5a3a7cf36c8df9dd83050bccc.patch";
hash = "sha256-a74Z7rp3ji3+9lM8Q/RttMIzwlRBki1N2Y0YtBiVaEA=";
})
# A fixup for the above, see:
#
# - https://github.com/optiland/optiland/pull/564#discussion_r3106831922
# - https://github.com/optiland/optiland/pull/568
(fetchpatch {
url = "https://github.com/optiland/optiland/commit/652922bce5e1854f1d067e292422d95dee129a46.patch";
hash = "sha256-9O+DNbqBDDSAaRkwCy3o76lwy5MJ7WHQqzfcN1fcmnE=";
})
];

build-system = [
hatchling
];

dependencies = [
matplotlib
numba
numpy
pandas
pyyaml
requests
scipy
seaborn
tabulate
typing-extensions
vtk
];

passthru = {
optional-dependencies = {
gui = [
pyside6
qtconsole
];
torch = [
torch
];
};
};

nativeCheckInputs = [
pytestCheckHook
]
# No need for optional-dependencies.gui, as the relevant tests requiring the
# gui dependencies are disabled below.
++ finalAttrs.finalPackage.passthru.optional-dependencies.torch;

disabledTestPaths = [
# From some reason, importing pyside6 during tests causes a core dump of the
# python interpreter, so we disable all GUI tests.
"tests/gui/"
];

pythonImportsCheck = [
"optiland"
];

meta = {
description = "Comprehensive optical design, optimization, and analysis in Python, including GPU-accelerated and differentiable ray tracing via PyTorch";
homepage = "https://github.com/HarrisonKramer/optiland";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ doronbehar ];
# Intentionally not setting optiland meta.mainProgram, as it is not
# functional without additional qt6 and python libraries available. See
# pkgs/by-name/op/optiland/package.nix for a derivation with a working GUI.
};
})
2 changes: 2 additions & 0 deletions pkgs/top-level/python-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11851,6 +11851,8 @@ self: super: with self; {

optax = callPackage ../development/python-modules/optax { };

optiland = callPackage ../development/python-modules/optiland { };

optimistix = callPackage ../development/python-modules/optimistix { };

optimum = callPackage ../development/python-modules/optimum { };
Expand Down
Loading