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

Conversation

claucambra
Copy link
Collaborator

Nix flakes makes it very easy to create builds and dev shells of the desktop client with minimal maintenance load, by using nix and nixpkgs.

This nix flake includes support for both macOS and Linux. The Linux build is fully reproducible — nix downloads and builds the necessary dependencies independently of system packages. Unfortunately the macOS build is “impure” as we need to use the system Xcode to build the finder sync extension, but besides that everything else is shared with the Linux build

Adopting this will make it easier to build the desktop client and create a dev environment for contributors and for ourselves, as well as make it easier to package the desktop client if we adopt this for our build infra

@claucambra claucambra self-assigned this Oct 4, 2022
@sonarcloud
Copy link

sonarcloud bot commented Oct 4, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@szaimen
Copy link
Contributor

szaimen commented Oct 4, 2022

I am interested: why are docker containers not a solution to this as well?

@claucambra
Copy link
Collaborator Author

claucambra commented Oct 4, 2022

I am interested: why are docker containers not a solution to this as well?

Nix is primarily intended as a solution for distributing build and development environments. Docker has a wider scope that really encompasses every step of the production "life-cycle" -- development, build, and crucially, production. The two tools overlap in a lot of ways and a docker container would fill a similar role, but Nix has a couple of advantages:

  1. Its primary focus is on reproducibility, and it goes much further than Docker in providing reproducible results. Nix guarantees (in pure builds) that the result will always be the same no matter where or when the build is run provided a set of inputs. With Docker, it is not quite as predictable as we are still beholden to the distribution used as a base image and its packages
  2. A corollary to this that Nix makes it really easy to be very specific with what inputs are provided in the creation of the desired environment. With flakes it is far, far easier to swap out the default package for a dependency for another than with Docker; if, say, we want to use a custom version of Qt to build the client, Nix contains tools to automatically fetch and build a specific revision from a specific git repository
  3. Nix is more efficient at doing what we want it to do in a CI environment, both in terms of build-time and storage consumption thanks to it's dependency management systems

This blog post explains things more clearly than I am able to:

http://sandervanderburg.blogspot.com/2020/07/on-using-nix-and-docker-as-deployment.html

@szaimen
Copy link
Contributor

szaimen commented Oct 4, 2022

Interesting! Sounds really cool! Will read more about it! Thanks for the Link! :)

@szaimen
Copy link
Contributor

szaimen commented Oct 4, 2022

Very cool article! Thanks for sharing! :)

@claucambra
Copy link
Collaborator Author

Very cool article! Thanks for sharing! :)

no worries :)

@claucambra
Copy link
Collaborator Author

A good article on nix flakes specifically: https://www.tweag.io/blog/2020-05-25-flakes/

@sonarcloud
Copy link

sonarcloud bot commented Nov 9, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@allexzander
Copy link
Contributor

@claucambra This one has been approved for a while. Were you going to merge it?

@claucambra
Copy link
Collaborator Author

@claucambra This one has been approved for a while. Were you going to merge it?

yes :)

Signed-off-by: Claudio Cambra <claudio.cambra@gmail.com>
Signed-off-by: Claudio Cambra <claudio.cambra@gmail.com>
@claucambra claucambra merged commit d0d16e4 into master Dec 13, 2022
@claucambra claucambra deleted the feature/nix branch December 13, 2022 15:45
@nextcloud-desktop-bot
Copy link

AppImage file: nextcloud-PR-5007-19a2f8cc7da52f62b6e7f4ca3b68ba7056b46f4e-x86_64.AppImage

To test this change/fix you can simply download above AppImage file and test it.

Please make sure to quit your existing Nextcloud app and backup your data.

@sonarcloud
Copy link

sonarcloud bot commented Dec 13, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@mgallien mgallien added this to the 3.7.0 milestone Jan 30, 2023
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.

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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants