ci: build in nix shell

This commit is contained in:
Anton Iakimov 2024-06-25 15:53:01 +02:00
parent e2d7265d5b
commit e98f076f45
No known key found for this signature in database
10 changed files with 558 additions and 17 deletions

View File

@ -569,16 +569,22 @@ endif
nim_status_client: force-rebuild-status-go $(NIM_STATUS_CLIENT)
_APPIMAGE_TOOL := appimagetool-x86_64.AppImage
APPIMAGE_TOOL := tmp/linux/tools/$(_APPIMAGE_TOOL)
ifdef IN_NIX_SHELL
APPIMAGE_TOOL := appimagetool
else
APPIMAGE_TOOL := tmp/linux/tools/appimagetool
endif
_APPIMAGE_TOOL := appimagetool-x86_64.AppImage
$(APPIMAGE_TOOL):
ifndef IN_NIX_SHELL
echo -e "\033[92mFetching:\033[39m appimagetool"
rm -rf tmp/linux
mkdir -p tmp/linux/tools
wget -nv https://github.com/AppImage/AppImageKit/releases/download/continuous/$(_APPIMAGE_TOOL)
mv $(_APPIMAGE_TOOL) tmp/linux/tools/
mv $(_APPIMAGE_TOOL) tmp/linux/tools/appimagetool
chmod +x $(APPIMAGE_TOOL)
endif
STATUS_CLIENT_APPIMAGE ?= pkg/Status.AppImage
STATUS_CLIENT_TARBALL ?= pkg/Status.tar.gz
@ -623,16 +629,22 @@ $(STATUS_CLIENT_APPIMAGE): nim_status_client $(APPIMAGE_TOOL) nim-status.desktop
cp bin/StatusQ/* tmp/linux/dist/usr/bin/StatusQ
# Libraries
ifndef IN_NIX_SHELL
cp -r /usr/lib/x86_64-linux-gnu/nss tmp/linux/dist/usr/lib/
cp -P /usr/lib/x86_64-linux-gnu/libgst* tmp/linux/dist/usr/lib/
cp -r /usr/lib/x86_64-linux-gnu/gstreamer-1.0 tmp/linux/dist/usr/lib/
cp -r /usr/lib/x86_64-linux-gnu/gstreamer1.0 tmp/linux/dist/usr/lib/
endif
cp vendor/status-go/build/bin/libstatus.so tmp/linux/dist/usr/lib/
cp vendor/status-go/build/bin/libstatus.so.0 tmp/linux/dist/usr/lib/
cp $(STATUSKEYCARDGO) tmp/linux/dist/usr/lib/
echo -e $(BUILD_MSG) "AppImage"
linuxdeployqt tmp/linux/dist/nim-status.desktop -no-copy-copyright-files -qmldir=ui -qmlimport=$(QT5_QMLDIR) -bundle-non-qt-libs
ifdef IN_NIX_SHELL
patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 tmp/linux/dist/usr/bin/nim_status_client
endif
# Qt plugins
cp $(FCITX5_QT) tmp/linux/dist/usr/plugins/platforminputcontexts/
@ -642,6 +654,10 @@ $(STATUS_CLIENT_APPIMAGE): nim_status_client $(APPIMAGE_TOOL) nim-status.desktop
mkdir -p pkg
$(APPIMAGE_TOOL) tmp/linux/dist $(STATUS_CLIENT_APPIMAGE)
ifdef IN_NIX_SHELL
patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 $(STATUS_CLIENT_APPIMAGE)
endif
# if LINUX_GPG_PRIVATE_KEY_FILE is not set then we don't generate a signature
ifdef LINUX_GPG_PRIVATE_KEY_FILE
scripts/sign-linux-file.sh $(STATUS_CLIENT_APPIMAGE)

119
ci/Jenkinsfile.linux_nix Normal file
View File

@ -0,0 +1,119 @@
#!/usr/bin/env groovy
library 'status-jenkins-lib@linux-use-nix'
/* Options section can't access functions in objects. */
def isPRBuild = utils.isPRBuild()
pipeline {
agent { label 'linux && x86_64 && nix-2.14' }
parameters {
booleanParam(
name: 'RELEASE',
description: 'Decides whether release credentials are used.',
defaultValue: params.RELEASE ?: false
)
booleanParam(
name: 'INCLUDE_DEBUG_SYMBOLS',
description: 'Decides whether binaries are built with debug symbols.',
defaultValue: params.INCLUDE_DEBUG_SYMBOLS ?: false
)
choice(
name: 'VERBOSE',
description: 'Level of verbosity based on nimbus-build-system setup.',
choices: ['0', '1', '2']
)
string(
name: 'NIMFLAGS',
description: 'Extra Nim flags. Examples: --verbosity:2 --passL:"-v" --passC:"-v"',
defaultValue: '--colors:off'
)
booleanParam(
name: 'USE_MOCKED_KEYCARD_LIB',
description: 'Decides whether the mocked status-keycard-go library is built.',
defaultValue: false
)
}
options {
timestamps()
/* Prevent Jenkins jobs from running forever */
timeout(time: 25, unit: 'MINUTES')
/* manage how many builds we keep */
buildDiscarder(logRotator(
numToKeepStr: '10',
daysToKeepStr: '30',
artifactNumToKeepStr: '1',
))
/* Allows combined build to copy */
copyArtifactPermission('/status-desktop/*')
/* Abort old PR builds. */
disableConcurrentBuilds(
abortPrevious: isPRBuild
)
}
environment {
TARGET = "linux/${getArch()}"
/* Improve make performance */
MAKEFLAGS = "-j4 V=${params.VERBOSE}"
/* Avoid weird bugs caused by stale cache. */
QML_DISABLE_DISK_CACHE = "true"
/* Control output the filename */
STATUS_CLIENT_APPIMAGE = "pkg/${utils.pkgFilename(ext: 'AppImage', arch: getArch())}"
STATUS_CLIENT_TARBALL = "pkg/${utils.pkgFilename(ext: 'tar.gz', arch: getArch())}"
}
stages {
stage('Deps') {
steps { script {
nix.shell('make update --debug V=1', pure: true)
nix.shell('make deps --debug V=1', pure: true)
} }
}
stage('status-go') {
steps { script {
nix.shell('make status-go --debug V=1', pure: true)
} }
}
stage('Package') {
steps { script {
linux.bundle('--debug=b tgz-linux', 1, true)
} }
}
stage('Parallel Upload') {
parallel {
stage('Upload') {
steps { script {
env.PKG_URL = s3.uploadArtifact(env.STATUS_CLIENT_TARBALL)
jenkins.setBuildDesc(AppImage: env.PKG_URL)
} }
}
stage('Archive') {
steps { script {
archiveArtifacts("${env.STATUS_CLIENT_TARBALL}*")
} }
}
}
}
}
post {
success { script { github.notifyPR(true) } }
failure { script { github.notifyPR(false) } }
// Windows workspace often becomes broken if stoped during checkout.
// Post cleanup will fail too.
// Use 'Wipe out repository and force clone' manual UI option to prevent it.
cleanup { cleanWs() }
}
}
def getArch() {
def tokens = Thread.currentThread().getName().split('/')
for (def arch in ['x86_64', 'aarch64']) {
if (tokens.contains(arch)) { return arch }
}
}

37
nix/overlay.nix Normal file
View File

@ -0,0 +1,37 @@
# Override some packages and utilities in 'pkgs'
# and make them available globally via callPackage.
#
# For more details see:
# - https://nixos.wiki/wiki/Overlays
# - https://nixos.org/nixos/nix-pills/callpackage-design-pattern.html
final: prev: let
inherit (prev) callPackage;
in rec {
linuxdeployqt = callPackage ./pkgs/linuxdeployqt/default.nix { };
# Copyied from d9424d2191d6439a276b69ae1fd0a800586135ca
# 2018-07-27 -> 2020-12-31
appimagekit = callPackage ./pkgs/appimagekit/default.nix { };
# Requirement from Makefile - 3.19
cmake_3_19 = prev.cmake.overrideAttrs ( attrs : rec {
version = "3.19.7";
src = prev.fetchurl {
url = "${attrs.meta.homepage}files/v${prev.lib.versions.majorMinor version}/cmake-${version}.tar.gz";
# compare with https://cmake.org/files/v${lib.versions.majorMinor version}/cmake-${version}-SHA-256.txt
sha256 = "sha256-WKFfDVagr8zDzFNxI0/Oc/zGyPnb13XYmOUQuDF1WI4=";
};
});
# Copyied from bootstrap121 from 0e2a36815d2310886458ac1aab14350160e6b12a
# autoPatchelfHook is disabled
# TODO: compile, not binary
go_1_20 = callPackage ./pkgs/go/bootstrap120.nix { };
# Fix for linuxdeployqt so it's not upset shell interpreter from host system
lddWrapped = prev.writeShellScriptBin "ldd" ''
"${final.bash}/bin/sh" "${final.glibc.bin}/bin/ldd" "$@"
'';
}

18
nix/pkgs.nix Normal file
View File

@ -0,0 +1,18 @@
# This file controls the pinned version of nixpkgs we use for our Nix environment
# as well as which versions of package we use, including their overrides.
let
# For testing local version of nixpkgs
#nixpkgsSrc = (import <nixpkgs> { }).lib.cleanSource "/home/jakubgs/work/nixpkgs";
# We follow the release-20.09 branch of official nixpkgs.
nixpkgsSrc = builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/66b0db71f463164486a36dded50bedee185e45c2.tar.gz";
sha256 = "sha256:0wam1m12qw9rrijhvbvhm5psj2a0ksms77xzxzyr5laz94j60cb0";
};
# Override some packages and utilities
pkgsOverlay = import ./overlay.nix;
in
(import nixpkgsSrc) {
overlays = [ pkgsOverlay ];
}

View File

@ -0,0 +1,125 @@
{ lib, stdenv, fetchFromGitHub
, pkg-config, cmake, autoconf, automake, libtool, makeWrapper
, wget, xxd, desktop-file-utils, file
, gnupg, glib, zlib, cairo, openssl, fuse, xz, squashfuse, inotify-tools, libarchive
, squashfsTools
, gtest
}:
let
appimagekit_src = fetchFromGitHub {
owner = "AppImage";
repo = "AppImageKit";
rev = "8bbf694455d00f48d835f56afaa1dabcd9178ba6";
sha256 = "sha256-pqg+joomC5CI9WdKP/h/XKPsruMgZEaIOjPLOqnNPZw=";
fetchSubmodules = true;
};
# squashfuse adapted to nix from cmake experession in "${appimagekit_src}/lib/libappimage/cmake/dependencies.cmake"
appimagekit_squashfuse = squashfuse.overrideAttrs (attrs: rec {
pname = "squashfuse";
version = "unstable-2016-10-09";
src = fetchFromGitHub {
owner = "vasi";
repo = pname;
rev = "1f980303b89c779eabfd0a0fdd36d6a7a311bf92";
sha256 = "sha256-BZd1+7sRYZHthULKk3RlgMIy4uCUei45GbSEiZxLPFM=";
};
patches = [
"${appimagekit_src}/lib/libappimage/src/patches/squashfuse.patch"
"${appimagekit_src}/lib/libappimage/src/patches/squashfuse_dlopen.patch"
];
postPatch = ''
cp -v ${appimagekit_src}/lib/libappimage/src/patches/squashfuse_dlopen.[hc] .
'';
preConfigure = ''
sed -i "/PKG_CHECK_MODULES.*/,/,:./d" configure
sed -i "s/typedef off_t sqfs_off_t/typedef int64_t sqfs_off_t/g" common.h
'';
configureFlags = [
"--disable-demo" "--disable-high-level" "--without-lzo" "--without-lz4"
];
postConfigure = ''
sed -i "s|XZ_LIBS = -llzma |XZ_LIBS = -Bstatic -llzma/|g" Makefile
'';
# only static libs and header files
installPhase = ''
mkdir -p $out/lib $out/include
cp -v ./.libs/*.a $out/lib
cp -v ./*.h $out/include
'';
});
in stdenv.mkDerivation rec {
pname = "appimagekit";
version = "unstable-2020-12-31";
src = appimagekit_src;
patches = [ ./nix.patch ];
postPatch = ''
patchShebangs src/embed-magic-bytes-in-file.sh
'';
nativeBuildInputs = [
pkg-config cmake autoconf automake libtool wget xxd
desktop-file-utils makeWrapper
];
buildInputs = [
glib zlib cairo openssl fuse xz inotify-tools
libarchive squashfsTools appimagekit_squashfuse
];
preConfigure = ''
export HOME=$(pwd)
'';
cmakeFlags = [
"-DUSE_SYSTEM_XZ=ON"
"-DUSE_SYSTEM_SQUASHFUSE=ON"
"-DSQUASHFUSE=${appimagekit_squashfuse}"
"-DUSE_SYSTEM_LIBARCHIVE=ON"
"-DUSE_SYSTEM_GTEST=ON"
"-DUSE_SYSTEM_MKSQUASHFS=ON"
];
postInstall = ''
mkdir -p $out/lib/appimagekit
cp "${squashfsTools}/bin/mksquashfs" "$out/lib/appimagekit/"
cp "${desktop-file-utils}/bin/desktop-file-validate" "$out/bin"
wrapProgram "$out/bin/appimagetool" \
--prefix PATH : "${lib.makeBinPath [ file gnupg ]}" \
--unset SOURCE_DATE_EPOCH
'';
checkInputs = [ gtest ];
# for debugging
passthru = {
squashfuse = appimagekit_squashfuse;
};
meta = with lib; {
description = "A tool to package desktop applications as AppImages";
longDescription = ''
AppImageKit is an implementation of the AppImage format that
provides tools such as appimagetool and appimaged for handling
AppImages.
'';
license = licenses.mit;
maintainers = with maintainers; [ taeer ];
homepage = src.meta.homepage;
platforms = platforms.linux;
};
}

View File

@ -0,0 +1,82 @@
Submodule lib/libappimage contains modified content
diff --git a/lib/libappimage/cmake/dependencies.cmake b/lib/libappimage/cmake/dependencies.cmake
index 8d96484..c7b17a1 100644
--- a/lib/libappimage/cmake/dependencies.cmake
+++ b/lib/libappimage/cmake/dependencies.cmake
@@ -91,9 +91,18 @@ if(NOT USE_SYSTEM_SQUASHFUSE)
INCLUDE_DIRS "<SOURCE_DIR>"
)
else()
- message(STATUS "Using system squashfuse")
+ message(STATUS "Using system squashfsfuse from ${SQUASHFUSE}")
- import_pkgconfig_target(TARGET_NAME libsquashfuse PKGCONFIG_TARGET squashfuse)
+ add_library(libsquashfuse INTERFACE IMPORTED GLOBAL)
+
+ set(squashfuse_INCLUDE_DIRS "${SQUASHFUSE}/include")
+ set(squashfuse_LIBRARIES "${SQUASHFUSE}/lib/libsquashfuse.a;${SQUASHFUSE}/lib/libsquashfuse_ll.a;${SQUASHFUSE}/lib/libfuseprivate.a")
+
+ set_property(
+ TARGET libsquashfuse
+ PROPERTY INTERFACE_LINK_LIBRARIES ${squashfuse_LIBRARIES}
+ )
+ include_directories(${squashfuse_INCLUDE_DIRS})
endif()
diff --git a/src/appimagetool.c b/src/appimagetool.c
index 6b37419..23425e7 100644
--- a/src/appimagetool.c
+++ b/src/appimagetool.c
@@ -38,7 +38,7 @@
#include <argp.h>
#include <fcntl.h>
-#include "squashfuse.h"
+#include <squashfuse.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -96,7 +96,7 @@ static void die(const char *msg) {
}
/* Function that prints the contents of a squashfs file
-* using libsquashfuse (#include "squashfuse.h") */
+* using libsquashfuse (#include <squashfuse.h>) */
int sfs_ls(char* image) {
sqfs_err err = SQFS_OK;
sqfs_traverse trv;
diff --git a/src/appimagetoolnoglib.c b/src/appimagetoolnoglib.c
index f900e76..ffa87f8 100644
--- a/src/appimagetoolnoglib.c
+++ b/src/appimagetoolnoglib.c
@@ -3,7 +3,7 @@
#include <stdlib.h>
#include <fcntl.h>
-#include "squashfuse.h"
+#include <squashfuse.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -118,7 +118,7 @@ int is_regular_file(const char *path)
}
/* Function that prints the contents of a squashfs file
- * using libsquashfuse (#include "squashfuse.h") */
+ * using libsquashfuse (#include <squashfuse.h>) */
int sfs_ls(char* image) {
sqfs_err err = SQFS_OK;
sqfs_traverse trv;
diff --git a/src/runtime.c b/src/runtime.c
index bada3af..70a642b 100644
--- a/src/runtime.c
+++ b/src/runtime.c
@@ -29,7 +29,7 @@
#define _GNU_SOURCE
-#include "squashfuse.h"
+#include <squashfuse.h>
#include <squashfs_fs.h>
#include <nonstd.h>

40
nix/pkgs/go/binary.nix Normal file
View File

@ -0,0 +1,40 @@
{ lib, stdenv, fetchurl, version, hashes, autoPatchelfHook }:
let
toGoKernel = platform:
if platform.isDarwin then "darwin"
else platform.parsed.kernel.name;
toGoCPU = platform: {
"i686" = "386";
"x86_64" = "amd64";
"aarch64" = "arm64";
"armv6l" = "armv6l";
"armv7l" = "armv6l";
"powerpc64le" = "ppc64le";
}.${platform.parsed.cpu.name} or (throw "Unsupported CPU ${platform.parsed.cpu.name}");
toGoPlatform = platform: "${toGoKernel platform}-${toGoCPU platform}";
platform = toGoPlatform stdenv.hostPlatform;
in
stdenv.mkDerivation rec {
name = "go-${version}-${platform}-bootstrap";
src = fetchurl {
url = "https://go.dev/dl/go${version}.${platform}.tar.gz";
sha256 = hashes.${platform} or (throw "Missing Go bootstrap hash for platform ${platform}");
};
#nativeBuildInputs = lib.optionals stdenv.isLinux [ autoPatchelfHook ];
# We must preserve the signature on Darwin
dontStrip = stdenv.hostPlatform.isDarwin;
installPhase = ''
runHook preInstall
mkdir -p $out/share/go $out/bin
cp -r . $out/share/go
ln -s $out/share/go/bin/go $out/bin/go
runHook postInstall
'';
}

View File

@ -0,0 +1,15 @@
{ callPackage }:
callPackage ./binary.nix {
version = "1.20.13";
hashes = {
# Use `print-hashes.sh ${version}` to generate the list below
darwin-amd64 = "713051aa0da66839f5a31a8ec677a7c61717b6fba62bf47eadb25542df3e9ee7";
darwin-arm64 = "4b7e8d0260b7376c77a0caea7b19dad6e1426c316671a15bc31036f92af2eb12";
linux-386 = "4da6f08510a21b829a065d3f99914bfbe1d8b212664cea230485a64e7e6d00d8";
linux-amd64 = "9a9d3dcae2b6a638b1f2e9bd4db08ffb39c10e55d9696914002742d90f0047b5";
linux-arm64 = "a2d811cef3c4fc77c01195622e637af0c2cf8b3814a95a0920cf2f83b6061d38";
linux-armv6l = "d4c6c671423ce6eef3f240bf014115b2673ad6a89e12429b5a331b95952c7279";
linux-ppc64le = "5f632b83323e16f8c6ceb676cd570b3f13f1826e06a81d92985d1301b643a7d3";
linux-s390x = "ae6c8f75df9b15c92374cfeae86e97d2744d4d4cdafcb999fea5b63e20c22651";
};
}

View File

@ -0,0 +1,21 @@
{
stdenv, fetchFromGitHub, qt515
}:
stdenv.mkDerivation rec {
pname = "linuxdeployqt";
version = "20230423-8428c59";
src = fetchFromGitHub {
owner = "probonopd";
repo = "linuxdeployqt";
rev = "8428c59318b250058e6cf93353e2871072bbf7f9";
sha256 = "sha256-b1iWpWQRRSjmkNVuWTKRjzxmWGy4czteYNgFWb6Lofs=";
};
dontWrapQtApps = true;
nativeBuildInputs = [
qt515.qmake
];
}

View File

@ -1,25 +1,35 @@
{ pkgs ? import (builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/e7603eba51f2c7820c0a182c6bbb351181caa8e7.zip";
sha256 = "sha256:0mwck8jyr74wh1b7g6nac1mxy6a0rkppz8n12andsffybsipz5jw";
}) { } }:
{
pkgs ? import ./nix/pkgs.nix
}:
let
qtCustom = with pkgs.qt515;
qtCustom = (with pkgs.qt515;
# TODO:check the required modules after Qt upgrade
env "qt-custom-${qtbase.version}" ([
qtbase
qtdeclarative
qtquickcontrols
qtquickcontrols2
qtsvg
qtmultimedia
qtwebview
qttools
qtwebchannel
qtgraphicaleffects
qtbase qttools qtdeclarative
qtlottie qtmultimedia
qtquickcontrols qtquickcontrols2
qtsvg qtwebengine qtwebview
]);
qtwebengine
qtlocation
# qtlottie # TODO: was missing in 5.15.2, review after upgrade
]));
in pkgs.mkShell {
name = "status-desktop-build-shell";
# TODO:check the required packages after Qt upgrade
buildInputs = with pkgs; [
qt5Full
bash curl wget git file unzip jq lsb-release
cmake gnumake pkg-config gnugrep qtCustom
bash curl wget git file unzip jq lsb-release which cacert gnupg
linuxdeployqt appimagekit
libglvnd # TODO: Qt 5.15.2 fix, review after upgrade
cmake_3_19 gnumake pkg-config gnugrep qtCustom
go_1_21
pcre nss pcsclite extra-cmake-modules
xorg.libxcb xorg.libX11 libxkbcommon
@ -35,8 +45,66 @@ in pkgs.mkShell {
LANGUAGE = "en_US.UTF-8";
QTDIR = qtCustom;
# TODO: still needed?
# https://github.com/NixOS/nixpkgs/pull/109649
QT_INSTALL_PLUGINS = "${qtCustom}/${pkgs.qt515.qtbase.qtPluginPrefix}";
shellHook = ''
export MAKEFLAGS="-j$NIX_BUILD_CORES"
export PATH="${pkgs.lddWrapped}/bin:$PATH"
'';
# Used to workaround missing lib links in qt-custom
# TODO:check if it's still needed after Qt upgrade
LIBRARY_PATH = with pkgs.qt515; pkgs.lib.makeLibraryPath [
qtdeclarative
qtmultimedia
qtquickcontrols
qtquickcontrols2
qtsvg
qtwebchannel
qtwebview
];
# Used for linuxdeployqt
# TODO:check if qt modules are still needed here after Qt upgrade
LD_LIBRARY_PATH = with pkgs; lib.makeLibraryPath (
[
alsaLib
expat
fontconfig
freetype
gcc-unwrapped
glib
gmp
harfbuzz
libglvnd
libkrb5
libpng
libpulseaudio
libxkbcommon
p11-kit
zlib
] ++ (with qt515; [
qtbase
qtdeclarative
qtlocation
qtmultimedia
qtquickcontrols2
qtsvg
qtwebengine
]) ++ (with xorg; [
libICE
libSM
libX11
libXrender
libxcb
xcbutil
xcbutilimage
xcbutilkeysyms
xcbutilrenderutil
xcbutilwm
]) ++ (with gst_all_1; [
gst-plugins-base
gstreamer
]));
}