Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a nix flake for easy building and dev environments #5007

Merged
merged 2 commits into from
Dec 13, 2022
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
143 changes: 143 additions & 0 deletions admin/nix/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
* Copyright (C) by Claudio Cambra <claudio.cambra@nextcloud.com>
*
* 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 2 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. See the GNU General Public License
* for more details.
*/

{
description = "A flake for the Nextcloud desktop client";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils }:
with flake-utils.lib;
eachSystem [ "aarch64-linux" "x86_64-linux" "aarch64-darwin" "x86_64-darwin" ] (system:
let
pkgs = import nixpkgs {
inherit system;
};

inherit (pkgs.lib.lists) optional optionals;
inherit (pkgs.lib.strings) hasPrefix optionalString;
isARM = hasPrefix "aarch64" system;

buildMacOSSymlinks = pkgs.runCommand "nextcloud-build-symlinks" {} ''
mkdir -p $out/bin
ln -s /usr/bin/xcrun /usr/bin/xcodebuild /usr/bin/iconutil $out/bin
'';

nativeBuildInputs = with pkgs; [
cmake
extra-cmake-modules
pkg-config
inkscape
qt5.wrapQtAppsHook
] ++ optionals stdenv.isDarwin [
buildMacOSSymlinks
];

buildInputs = with pkgs; [
sqlite
openssl
pcre

qt5.qtbase
qt5.qtquickcontrols2
qt5.qtsvg
qt5.qtgraphicaleffects
qt5.qtdeclarative
qt5.qttools
qt5.qtwebsockets

libsForQt5.karchive
libsForQt5.qtkeychain
] ++ optionals (!isARM) [
# Qt WebEngine not available on ARM
qt5.qtwebengine
] ++ optionals stdenv.isLinux [
inotify-tools
libcloudproviders
libsecret

libsForQt5.breeze-icons
libsForQt5.qqc2-desktop-style
libsForQt5.kio
] ++ optionals stdenv.isDarwin [
libsForQt5.qt5.qtmacextras

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libsForQt5, qt5 and libsForQt5.qt5 should be the same thing.


darwin.apple_sdk.frameworks.UserNotifications
];

packages.default = with pkgs; stdenv.mkDerivation rec {
inherit nativeBuildInputs buildInputs;
pname = "nextcloud-client";
version = "dev";
src = ../../.;

dontStrip = true;
enableDebugging = true;
separateDebugInfo = false;
enableParallelBuilding = true;

preConfigure = optionals stdenv.isLinux [
Copy link

@SuperSandro2000 SuperSandro2000 Feb 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preConfigure uses a multiline string and this only works because nix mangles lists to strings. In the future this might stop working.

You cab replace optionals with optionalString.

''
substituteInPlace shell_integration/libcloudproviders/CMakeLists.txt \
--replace "PKGCONFIG_GETVAR(dbus-1 session_bus_services_dir _install_dir)" "set(_install_dir "\$\{CMAKE_INSTALL_DATADIR\}/dbus-1/service")"
''
] ++ optionals stdenv.isDarwin [
''
substituteInPlace shell_integration/MacOSX/CMakeLists.txt \
--replace "-target FinderSyncExt -configuration Release" "-scheme FinderSyncExt -configuration Release -derivedDataPath $ENV{NIX_BUILD_TOP}/derivedData"
''
];

cmakeFlags = optionals stdenv.isLinux [
"-DCMAKE_INSTALL_LIBDIR=lib" # expected to be prefix-relative by build code setting RPATH
"-DNO_SHIBBOLETH=1" # allows to compile without qtwebkit
] ++ optionals stdenv.isDarwin [
"-DQT_ENABLE_VERBOSE_DEPLOYMENT=TRUE"
"-DBUILD_OWNCLOUD_OSX_BUNDLE=OFF"
];
postPatch = optionalString stdenv.isLinux ''
for file in src/libsync/vfs/*/CMakeLists.txt; do
substituteInPlace $file \
--replace "PLUGINDIR" "KDE_INSTALL_PLUGINDIR"
done
'';
postFixup = optionalString stdenv.isLinux ''
wrapProgram "$out/bin/nextcloud" \
--set LD_LIBRARY_PATH ${lib.makeLibraryPath [ libsecret ]} \
--set PATH ${lib.makeBinPath [ xdg-utils ]} \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably don't want to overwrite PATH here since it will clear most programs on NixOS systems.

--set QML_DISABLE_DISK_CACHE "1"
'';
};

apps.default = mkApp {
name = "nextcloud";
drv = packages.default;
};

in {
inherit packages apps;
devShell = pkgs.mkShell {
inherit buildInputs;
nativeBuildInputs = with pkgs; nativeBuildInputs ++ optionals (stdenv.isLinux) [
gdb
qtcreator
];
name = "nextcloud-client-dev-shell";
};
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
/* Begin PBXCopyFilesBuildPhase section */
C2B573E11B1CD9CE00303B36 /* Embed App Extensions */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
buildActionMask = 8;
dstPath = "";
dstSubfolderSpec = 13;
files = (
C2B573E21B1CD9CE00303B36 /* FinderSyncExt.appex in Embed App Extensions */,
);
name = "Embed App Extensions";
runOnlyForDeploymentPostprocessing = 0;
runOnlyForDeploymentPostprocessing = 1;
};
/* End PBXCopyFilesBuildPhase section */

Expand Down Expand Up @@ -198,10 +198,12 @@
C2B573B01B1CD91E00303B36 = {
CreatedOnToolsVersion = 6.3.1;
DevelopmentTeam = 9B5WD74GWJ;
ProvisioningStyle = Manual;
};
C2B573D61B1CD9CE00303B36 = {
CreatedOnToolsVersion = 6.3.1;
DevelopmentTeam = 9B5WD74GWJ;
ProvisioningStyle = Manual;
SystemCapabilities = {
com.apple.ApplicationGroups.Mac = {
enabled = 1;
Expand Down Expand Up @@ -384,6 +386,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
Expand Down Expand Up @@ -433,6 +436,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
Expand Down Expand Up @@ -475,6 +479,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_ENTITLEMENTS = FinderSyncExt/FinderSyncExt.entitlements;
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
Expand Down Expand Up @@ -529,7 +534,8 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_ENTITLEMENTS = FinderSyncExt/FinderSyncExt.entitlements;
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO;
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = YES;
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES"
askForAppToLaunch = "Yes"
launchAutomaticallySubstyle = "2">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand Down