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

Draupnir: init at 2.0.0-beta.6 #274052

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

TheArcaneBrony
Copy link
Contributor

Description of changes

NOTE: This PR is a successor of #222939. The previous PR was closed by accident during a rebase operation.

Original description:

Draupnir is a hardfork of Mjolnir. Mjolnir package has been unmaintained due to upstream bugs. This package is mostly a drop-in replacement. This package also uses newer methods of handling dependencies.

Repository can be found at:
https://github.com/the-draupnir-project/Draupnir

Note on testing: package and module were (and still are) tested in our production environment, works fine as far as it's been used.
Note on replacing Mjolnir: Not sure whether this is appropriate, due to general usage of the bot changing. You can however fully automatically migrate from mjolnir to draupnir.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.05 Release Notes (or backporting 23.05 and 23.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@gaykitty
Copy link
Contributor

Result of nixpkgs-review pr 274052 run on x86_64-linux 1

2 packages blacklisted:
  • nixos-install-tools
  • tests.nixos-functions.nixos-test
1 package built:
  • draupnir

Copy link
Member

@mweinelt mweinelt left a comment

Choose a reason for hiding this comment

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

I see a lot of potential to improve the module and to bring it in line with today's standards.

I can see that it is a copy of the mjolnir module, but I'm not willing to accept a new module of similar quality, because it is hard to maintain.

This is especially relevant with RFC42 (settings & formatters) in mind

pkgs/servers/draupnir/default.nix Outdated Show resolved Hide resolved
pkgs/servers/draupnir/default.nix Outdated Show resolved Hide resolved
pkgs/servers/draupnir/default.nix Outdated Show resolved Hide resolved
pkgs/servers/draupnir/default.nix Outdated Show resolved Hide resolved
pkgs/servers/draupnir/default.nix Outdated Show resolved Hide resolved
nixos/modules/services/matrix/draupnir.nix Outdated Show resolved Hide resolved
nixos/modules/services/matrix/draupnir.nix Outdated Show resolved Hide resolved
nixos/modules/services/matrix/draupnir.nix Outdated Show resolved Hide resolved
nixos/modules/services/matrix/draupnir.nix Outdated Show resolved Hide resolved
nixos/modules/services/matrix/draupnir.nix Outdated Show resolved Hide resolved
@TheArcaneBrony TheArcaneBrony changed the title Draupnir: init at 1.85.1 Draupnir: init at 1.86.0 Jan 20, 2024
@github-actions github-actions bot removed the 6.topic: lib The Nixpkgs function library label Jan 20, 2024
@TheArcaneBrony
Copy link
Contributor Author

Time for the almighty rebase on nixos:master... Please don't close the PR again...

@TheArcaneBrony
Copy link
Contributor Author

🎊 It didn't close as merged!

@TheArcaneBrony
Copy link
Contributor Author

(Renamed the package init commit)

@TheArcaneBrony
Copy link
Contributor Author

(^ master rebase)

@teutat3s
Copy link
Member

This now looks good to go for me. A co-authored-by on the test commit would be nice, but is not a requirement for me. Thanks for continuing to push this forward.

Copy link
Member

@mweinelt mweinelt left a comment

Choose a reason for hiding this comment

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

Went over everything except the test.

maintainers/maintainer-list.nix Show resolved Hide resolved
preBuild = ''
# copy built modules to package...
echo "Copying built matrix-sdk-crypto-nodejs modules to package..."
cp -a ${matrix-sdk-crypto-nodejs}/lib/node_modules/* node_modules/
Copy link
Member

Choose a reason for hiding this comment

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

This could probably just be a symlink.

pkgs/by-name/dr/draupnir/package.nix Outdated Show resolved Hide resolved
pkgs/by-name/dr/draupnir/package.nix Outdated Show resolved Hide resolved
Comment on lines 50 to 69
{
services.draupnir = {
enable = true;
pantalaimon = {
enable = true;
username = "draupnir";
passwordFile = "/run/secrets/draupnir-password";
options = {
homeserver = "http://localhost:8008";
ssl = false;
};
};
settings = {
managementRoom = "!yyy:domain.tld";
protectedRooms = [
"https://matrix.to/#/!xxx:domain.tld"
];
};
};
}
Copy link
Member

Choose a reason for hiding this comment

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

Make sure to format this with nixfmt-rfc-style.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can nixfmt-rfc-style handle markdown files, or should i extract this nix excerpt into a separate file to process?

Copy link
Member

@mweinelt mweinelt Jul 23, 2024

Choose a reason for hiding this comment

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

Extract, format, reinsert.

nixos/modules/services/matrix/draupnir.nix Outdated Show resolved Hide resolved
nixos/modules/services/matrix/draupnir.nix Outdated Show resolved Hide resolved
nixos/modules/services/matrix/draupnir.nix Outdated Show resolved Hide resolved
nixos/modules/services/matrix/draupnir.nix Outdated Show resolved Hide resolved
nixos/modules/services/matrix/draupnir.nix Outdated Show resolved Hide resolved
@TheArcaneBrony
Copy link
Contributor Author

^ just renamed the maintainers commit and added the co author to the tests pr :)

Copy link
Member

@teutat3s teutat3s left a comment

Choose a reason for hiding this comment

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

What's the intention behind moving homeserverUrl? This now needs changing in the docs to fix the manual.

nixos/modules/services/matrix/draupnir.md Outdated Show resolved Hide resolved
Comment on lines +35 to +36
yarnLock = src + "/yarn.lock";
packageJSON = ./package.json;
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need these? I can build the package without setting these.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This confused me as well to figure out, the package builds fine without these but the nixpkgs CI fails due to importing the package.json from source. I'm not sure what the yarnLock there is for though as it seems to be duplicated from offlineCache.yarnLock

Copy link
Member

Choose a reason for hiding this comment

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

I see, apparently this causes IFD. Disregard this then ^^

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unresolved this conversation, does anyone think it would be possible to address this in favor of #320528 and #327064?

Copy link
Member

Choose a reason for hiding this comment

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

No, that would be scope creep at this point.

tests = {
inherit (nixosTests) draupnir;
};
updateScript = ./update.sh;
Copy link
Member

Choose a reason for hiding this comment

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

Is there anything special here, that nix-update-script couldn't handle? It can also deal with updating the Yarn cache hash in the derivation.

Suggested change
updateScript = ./update.sh;
updateScript = nix-update-script { };

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hashes are stored in a separate file, I think the reason was that nix-update-script couldn't handle the Yarn cache hash? I'd have to test this once a new Draupnir version comes out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Question, does anyone know how to make better-sqlite3 work under nix? Seems adding sqlite as nativeBuildInput doesn't work, and this causes the roomStateBackingStore feature of Draupnir to cause a startup failure as better-sqlite3 fails to find it's bindings file.

Copy link
Member

Choose a reason for hiding this comment

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

share/draupnir/node_modules/better-sqlite3/
share/draupnir/node_modules/better-sqlite3/src/better_sqlite3.cpp
share/draupnir/node_modules/better-sqlite3/src/better_sqlite3.hpp

Looks like it is here, but does not get build. Ideally we can build it outside of draupnir, as a dedicated package, and patch it in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, from earlier testing, seems to also be possible to rebuild it with a single command, and when I raised possibly making it a sub-package I was recommended not to.

Copy link
Contributor

Choose a reason for hiding this comment

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

diff
diff --git a/pkgs/by-name/dr/draupnir/package.nix b/pkgs/by-name/dr/draupnir/package.nix
index fb2faad56350..81a8ee568fbd 100644
--- a/pkgs/by-name/dr/draupnir/package.nix
+++ b/pkgs/by-name/dr/draupnir/package.nix
@@ -3,7 +3,10 @@
 , makeWrapper
 , nodejs
 , matrix-sdk-crypto-nodejs
+, python3
 , sqlite
+, srcOnly
+, removeReferencesTo
 , mkYarnPackage
 , fetchYarnDeps
 , nixosTests
@@ -12,6 +15,7 @@
 # docs: https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/javascript.section.md#yarn2nix-javascript-yarn2nix
 let
   hashesFile = builtins.fromJSON (builtins.readFile ./hashes.json);
+  nodeSources = srcOnly nodejs;
 in
   mkYarnPackage rec {
     pname = "draupnir";
@@ -37,11 +41,30 @@ in
     yarnLock = src + "/yarn.lock";
     packageJSON = ./package.json;
 
+    pkgConfig = {
+      "@matrix-org/matrix-sdk-crypto-nodejs" = {
+        postInstall = ''
+          # replace with the built package
+          cd ..
+          rm -r matrix-sdk-crypto-nodejs
+          ln -s ${matrix-sdk-crypto-nodejs}/lib/node_modules/@matrix-org/* ./
+        '';
+      };
+
+      better-sqlite3 = {
+        nativeBuildInputs = [ python3 ];
+        postInstall = ''
+          # build native sqlite bindings
+          npm run build-release --offline --nodedir="${nodeSources}"
+          find build -type f -exec \
+            ${removeReferencesTo}/bin/remove-references-to \
+            -t "${nodeSources}" {} \;
+       '';
+      };
+    };
+
     #prebuild phase
     preBuild = ''
-      # copy built modules to package...
-      echo "Copying built matrix-sdk-crypto-nodejs modules to package..."
-      cp -a ${matrix-sdk-crypto-nodejs}/lib/node_modules/* node_modules/
       echo "Adding version.txt..."
       mkdir -p deps/draupnir/
       echo "${version}-nix" > deps/draupnir/version.txt

matrix-appservice-discord also seems to bundle it in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Forgot to mention, I applied your patch in bd7179d

mkdir -p deps/draupnir/
echo "${version}-nix" > deps/draupnir/version.txt

sed -i 's/corepack //g' deps/draupnir/package.json
Copy link
Contributor Author

Choose a reason for hiding this comment

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

(Copy paste from commit description)
fixup! draupnir: init at 2.0.0-beta.6 - ugly sed hack to drop corepack

Fixes build with corepack upstream introduced by the-draupnir-project/Draupnir#472
Upstream may move to yarn v4, need to investigate options. (the-draupnir-project/Draupnir#475)
Looks like the recommended option is to use a fixed-output derivation?

Sources:

Any suggestions? I'm sure this is an ugly, unnecessary hack, but I couldn't find any documentation on the topic.

@TheArcaneBrony TheArcaneBrony changed the title Draupnir: init at 2.0.0-beta.4 Draupnir: init at 2.0.0-beta.6 Sep 15, 2024
…x-sdk-crypto-nodejs and better-sqlite3

Co-Authored-By: div72 <div72@localhost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.