Hi Community,
I would like share that I have added OTB to Nix packages, so now it is currently available as a package via Nix unstable channel.This is build from source based on version 9.1.0 with all modules activated by default, however the 3rd party dependencies version might be slightly different from the official binary as the dependencies version are based on Nix package version. Example GDAL 3.10.0 etc.
Guide on how to started with Nix and NixOS:
Below is a simple flake.nix
example which should activate an environment with OTB and Python 3 enabled, assuming one has already installed Nix with Flakes enabled.
{
description = "A flake for Orfeo Toolbox";
inputs = {
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = {
self,
nixpkgs-unstable,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = import nixpkgs-unstable {inherit system;};
python = pkgs.python3;
pyPkgs = python.pkgs;
in rec {
devShells.default = pkgs.mkShell rec {
packages = with pkgs; [
bashInteractive
pyPkgs.python
pyPkgs.venvShellHook
otb
];
venvDir = "./.venv";
postShellHook = ''
export PYTHONPATH="$PYTHONPATH:${pkgs.otb}/lib/otb/python"
'';
};
}
);
}
Advanced Configuration:
otb-nix
: Apart from that above Nix package for OTB, incase one needs to do some advanced configuration with Nix such as building OTB from source with remote modules, combining with different packages (pyOTB, rasterio etc), building docker images, etc. then one can refer to this otb-nix
project which already has all the mentioned examples and might be a good reference and can be adapted.
I would really appreciate any feedback and happy to answer any questions related to settings regarding Nix.
Hi!
Thank you for your contribution it is greatly appreciated that other Linux distro than Ubuntu/Debian/Fedora gets it packaged!
Let us know when it gets to the stable channel, we could add Nix as supported distro package installation
Best regards
1 Like
Hi @thibaut.romain !
Thanks for the suggestion. I will check how to backport the package to current stable channel (nixos-24.11). Although the name of the channel is unstable
actually this channel basically contains the latest tested version for packages
Channel branches - NixOS Wiki.
- Stable/unstable:
- Stable channels (
nixos-24.11
) only provide conservative updates for fixing bugs and security vulnerabilities, but do not receive major updates after the initial release. New stable channels are released every six months.
- Unstable channels (
nixos-unstable
, nixpkgs-unstable
) follow the master
branch of Nixpkgs, delivering the latest tested updates on a rolling basis.
I would also like to add OTB
can be used without having NixOS
distro. Nix
can also be used as a package manager with any Platform (Linux or MacOS, WSL2). But OTB Nix package is currently available only for any Linux distro (x86_64 and aarch64), not for MacOS c.f
Getting it started with Nix requires only two steps:
- Install Nix:
curl --proto ‘=https’ --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s – install
- Start a Nix shell with OTB
- nix-shell -I nixpkgs=channel:nixos-unstable -p otb
- Now we can use all the otbcli applications in this activated shell
- otbcli_BandMathX -help
- exit
Once we exit the shell there should be no OTB
Regarding the flake.nix
example I added above . Assuming Nix
is installed as mentioned here
One can start OTB with flake.nix
file as follows:
- Create a directory (any name)
- Then create a
flake.nix
file (use any editor of choice) and copy the content from above and save it.
- Now inside the directory we can run Nix command. This will activate an environment shell with
python 3
and otb
.
- Now we should have an shell environment with
otb
and python 3
- Try to import OTB with python
- python -c “import otbApplication as otb; app = otb.Registry.CreateApplication(‘Smoothing’);”
- exit()
Once we exit no more OTB or python. Next time we can again enter the directory and just start the environment with nix develop