Skip to content

Instantly share code, notes, and snippets.

@Guiorgy
Created December 25, 2025 17:20
Show Gist options
  • Select an option

  • Save Guiorgy/8860785fb7b9fee32c5ee2402575824d to your computer and use it in GitHub Desktop.

Select an option

Save Guiorgy/8860785fb7b9fee32c5ee2402575824d to your computer and use it in GitHub Desktop.
Build NUT using Docker

Build

You can change the version being built by modifying the build.sh file and changing the VERSION variable at the top.

NOTE: Only 2.8.0 and 2.8.4 versions tested.

  • Before building

    mkdir bin
    chmod +x build.sh
  • One time

    docker compose run --rm builder
  • Reusing the container

    # First time
    docker compose run --name nut_builder builder
    
    # Subsequent times
    docker start --attach --interactive nut_builder builder

Run

Make sure you are in the directory where the bin directory is.

Modify the run-driver.sh file using the correct values from /etc/nut/ups.conf.

chmod +x run.sh run-driver.sh
./run-driver.sh
#!/bin/bash
# ============================================================================= #
# Copyright © 2025 Guiorgy #
# #
# This program is free software: you can redistribute it and/or modify it under #
# the terms of the GNU General Public License as published by the Free Software #
# Foundation, either version 3 of the License, or (at your option) any later #
# version. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
# FOR A PARTICULAR PURPOSE. #
# #
# You can see the full GNU General Public License at #
# <https://www.gnu.org/licenses/> for more details. #
# ============================================================================= #
VERSION="2.8.4"
# Prepare source
if [[ ! -f nut-"$VERSION".tar.gz ]]; then
echo 'Downloading source code'
wget https://github.com/networkupstools/nut/releases/download/v"$VERSION"/nut-"$VERSION".tar.gz
fi
if [[ ! -d nut-"$VERSION" ]]; then
echo 'Extracting source code'
tar -xvzf nut-"$VERSION".tar.gz
fi
cd nut-"$VERSION"
# When using git clone
#./autogen.sh
#./ci_build.sh
echo 'Configuring'
# Source: https://sources.debian.org/src/nut/2.8.4%2Breally-2/debian/rules
DEB_CONFIGURE_EXTRA_FLAGS=(
--prefix=/usr
--sysconfdir=/etc/nut
--includedir=/usr/include
--mandir=/usr/share/man
--libdir=/usr/lib/x86_64-linux-gnu
--libexecdir=/usr/libexec
--with-ssl --with-nss
# --with-cgi
--with-dev
--enable-static
--with-statepath=/run/nut
--with-altpidpath=/run/nut
--with-drvpath=/usr/libexec/nut
--with-cgipath=/usr/lib/cgi-bin/nut
--with-htmlpath=/usr/share/nut/www
--with-pidpath=/run/nut
--datadir=/usr/share/nut
--with-pkgconfig-dir=/usr/lib/x86_64-linux-gnu/pkgconfig
--with-user=nut --with-group=nut
--with-udev-dir=/usr/lib/udev
--with-systemdsystemunitdir=/usr/lib/systemd/system
--with-systemdshutdowndir=/usr/lib/systemd/system-shutdown
--with-systemdtmpfilesdir=/usr/lib/tmpfiles.d
--with-python=python3 --with-python3=/usr/bin/python3
)
./configure --enable-inplace-runtime --with-usb --without-linux_i2c "${DEB_CONFIGURE_EXTRA_FLAGS[@]}"
CPUS="$(nproc)"
echo "Building using $CPUS jobs"
make -j "$CPUS" all
echo "Testing using $CPUS jobs"
make -j "$CPUS" check
echo 'Copying bindaries to bin'
find . \( -type f -executable -o -type l \) -executable -exec cp --parents -t /build/bin {} +
echo 'Done!'
# Wait for the termination signal
#tail -f /dev/null & wait $!
# ============================================================================= #
# Copyright © 2025 Guiorgy #
# #
# This program is free software: you can redistribute it and/or modify it under #
# the terms of the GNU General Public License as published by the Free Software #
# Foundation, either version 3 of the License, or (at your option) any later #
# version. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
# FOR A PARTICULAR PURPOSE. #
# #
# You can see the full GNU General Public License at #
# <https://www.gnu.org/licenses/> for more details. #
# ============================================================================= #
services:
builder:
container_name: NUT_Builder
image: nut-builder:latest
user: "${UID:-1000}"
build:
context: .
dockerfile: Dockerfile.builder
args:
UID: "${UID:-1000}"
working_dir: /build
volumes:
- ./bin:/build/bin:rw
- ./build.sh:/build/build.sh:r
entrypoint: ./build.sh
FROM gcc:latest
# ============================================================================= #
# Copyright © 2025 Guiorgy #
# #
# This program is free software: you can redistribute it and/or modify it under #
# the terms of the GNU General Public License as published by the Free Software #
# Foundation, either version 3 of the License, or (at your option) any later #
# version. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
# FOR A PARTICULAR PURPOSE. #
# #
# You can see the full GNU General Public License at #
# <https://www.gnu.org/licenses/> for more details. #
# ============================================================================= #
RUN DEBIAN_FRONTEND=noninteractive \
apt-get -qq update \
&& apt-get -qq upgrade \
&& apt-get -qq install \
python3 \
libusb-1.0-0-dev \
ccache time \
git perl curl rsync \
libltdl-dev libtool binutils \
valgrind \
cppcheck \
pkg-config \
gcc g++ clang \
systemd-dev \
libsystemd-dev \
libcppunit-dev \
libssl-dev libnss3-dev \
augeas-tools libaugeas-dev augeas-lenses \
libusb-dev libusb-1.0-0-dev \
libi2c-dev \
libmodbus-dev \
libsnmp-dev \
libpowerman0-dev \
libfreeipmi-dev libipmimonitoring-dev \
libavahi-common-dev libavahi-core-dev libavahi-client-dev \
libgpiod-dev \
lua5.1 lua5.1-dev \
bash dash ksh busybox \
git-core libi2c-dev i2c-tools lm-sensors \
&& rm -rf /var/lib/apt/lists/*
ARG UID=1000
RUN useradd --non-unique --uid ${UID} --user-group --no-create-home --home /build --shell /sbin/nologin --comment Builder builder \
&& mkdir /build \
&& chown builder:builder /build
USER builder:builder
WORKDIR /build
#!/bin/sh
# ============================================================================= #
# Copyright © 2025 Guiorgy #
# #
# This program is free software: you can redistribute it and/or modify it under #
# the terms of the GNU General Public License as published by the Free Software #
# Foundation, either version 3 of the License, or (at your option) any later #
# version. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
# FOR A PARTICULAR PURPOSE. #
# #
# You can see the full GNU General Public License at #
# <https://www.gnu.org/licenses/> for more details. #
# ============================================================================= #
# Put the values from /etc/nut/ups.conf
sudo ./run ./bin/drivers/usbhid-ups \
-F \
-s testusbups \
-x port="auto" \
-x vendorid="" \
-x productid="" \
-x product="" \
-x serial="" \
-x vendor="" \
-x bus="" \
"$@"
#!/bin/sh
# ============================================================================= #
# Copyright © 2025 Guiorgy #
# #
# This program is free software: you can redistribute it and/or modify it under #
# the terms of the GNU General Public License as published by the Free Software #
# Foundation, either version 3 of the License, or (at your option) any later #
# version. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
# FOR A PARTICULAR PURPOSE. #
# #
# You can see the full GNU General Public License at #
# <https://www.gnu.org/licenses/> for more details. #
# ============================================================================= #
NUT_BASE="$(realpath ./bin)"
LD_LIBRARY_PATH=$NUT_BASE/clients/.libs:$NUT_BASE/tools/nutconf/.libs:$NUT_BASE/tools/nut-scanner/.libs:$NUT_BASE/tests/.libs:$NUT_BASE/drivers/.libs "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment