-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
matrix-synapse: create and connect to local postgresql db #31223
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
Conversation
@Ralith This is still a bit messy, but I'd appreciate your thoughts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is that the user still has to manually enable postgres, but no longer has to manually configure the database by hand on a new HS, right? That's definitely appealing. Has this been tested live?
logConfigFile = pkgs.writeText "log_config.yaml" cfg.logConfig; | ||
mkResource = r: ''{names: ${builtins.toJSON r.names}, compress: ${boolToString r.compress}}''; | ||
mkListener = l: ''{port: ${toString l.port}, bind_address: "${l.bind_address}", type: ${l.type}, tls: ${boolToString l.tls}, x_forwarded: ${boolToString l.x_forwarded}, resources: [${concatStringsSep "," (map mkResource l.resources)}]}''; | ||
# TODO: finish this and put it in lib somewhere | ||
toYaml = value: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't yaml a superset of JSON? That's how we're getting away with toJSON
elsewhere.
createHome = true; | ||
shell = "${pkgs.bash}/bin/bash"; | ||
uid = config.ids.uids.matrix-synapse; | ||
uid = config.ids.uids."${user}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't config.ids.uids
a static table? I don't think this is useful, and it brings into question the whole dynamic user name option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I suppose it is. I didn't actually expose the user name, I was just trying to avoid duplication. i'll put it back the way it was.
{ name = "matrix-synapse"; | ||
gid = config.ids.gids.matrix-synapse; | ||
{ name = group; | ||
gid = config.ids.gids."${group}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment on uid
.
--lc-collate=C \ | ||
--lc-ctype=C \ | ||
--template=template0 \ | ||
${cfg.database_name} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these db setup commands guaranteed to be idempotent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They will fail if you remove db-created
without dropping the db/role. It's not a very elegant solution, but it's what's used in other similar modules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Er, right, not sure how I managed to forget the guard file even though it's right there.
Yeah, that's the idea. Postgres doesn't need to be enabled, but you do need to switch |
And yeah, I'm using it on my home server. I switched my VPS to this config, shut down matrix-synapse, ran The database setup is based on how other PG dependants (gitlab, mattermost) do it. |
8c009b2
to
15a089a
Compare
user = cfg.database_user; | ||
database = cfg.database_name; | ||
}; | ||
}."${cfg.database_type}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems wrong to me, but it's useful and seems to work. Is there a better way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It didn't even occur to me you could do this. I'm no Nix language expert, so no strong feelings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, an alternative is to have two different options for two databases, I guess. Maybe defining with mkIf
, so that you cannot set the wrong one.
I am not sure that would be better.
Defaulting based on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm generally in favor of this, and I don't see any obvious issues in the approach. It doesn't strike me as noticeably messier than what's already there, either; as far as I'm concerned, trusting that it works, it's okay to merge as soon as you're happy with it.
I'm thinking it's ok to use |
I made the |
nixos/tests/matrix-synapse.nix
Outdated
server_postgres = server; | ||
|
||
server_sqlite = args: server args // { | ||
system.stateVersion = "17.09"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better for this to just explicitly turn on sqlite? Who knows what other side effects this specific stateVersion might come to have over time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I guess I originally intended to verify that it was using the correct db for each stateVersion, but I didn't actually test for it. I suppose the stateVersion logic is pretty simple, and it would be more intuitive to explicitly test the backends.
04d8df8
to
a58d1c0
Compare
@fpletz I noticed you approved the changes this conflicts with, so would you mind taking a look at this before I rebase? |
@GrahamcOfBorg test matrix-synapse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failure for system: x86_64-linux
Merge failed
@corngood can you rebase? |
a58d1c0
to
bc57fc6
Compare
Yeah, just did. Testing locally now. I wonder if I can do this: @GrahamcOfBorg test matrix-synapse |
@fpletz You merged the last matrix-synapse change, so would you mind taking a look? Thanks |
bc57fc6
to
1c8bd9b
Compare
Resolved conflicts. Can anyone suggest changes or push this along? |
@GrahamcOfBorg test matrix-synapse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failure for system: x86_64-linux
Merge failed
@GrahamcOfBorg test matrix-synapse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failure for system: x86_64-linux
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
5 61.1M 5 3175k 0 0 3175k 0 0:00:19 0:00:01 0:00:18 1625k
42 9015k 42 3813k 0 0 3813k 0 0:00:02 0:00:01 0:00:01 2050k
17 6058k 17 1086k 0 0 1086k 0 0:00:05 0:00:01 0:00:04 1065k
9 916k 9 86669 0 0 86669 0 0:00:10 --:--:-- 0:00:10 133k
45 37.5M 45 16.9M 0 0 8699k 0 0:00:04 0:00:02 0:00:02 6368k
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
35 6058k 35 2146k 0 0 1073k 0 0:00:05 0:00:02 0:00:03 1063k
7 61.1M 7 4519k 0 0 2259k 0 0:00:27 0:00:02 0:00:25 1529k
61 9015k 61 5541k 0 0 2770k 0 0:00:03 0:00:02 0:00:01 1936k
76 916k 76 703k 0 0 703k 0 0:00:01 0:00:01 --:--:-- 439k
65 916k 65 600k 0 0 600k 0 0:00:01 0:00:01 --:--:-- 420k
68 37.5M 68 25.9M 0 0 8850k 0 0:00:04 0:00:03 0:00:01 6998k
100 916k 100 916k 0 0 916k 0 0:00:01 0:00:01 --:--:-- 479k
building path(s) ‘/nix/store/xv9xbqmlzxb0b3aai73m13iy0v36r8yg-append-initrd-secrets’
killing process 4537
killing process 4533
killing process 4565
killing process 4588
killing process 4481
error: a ‘aarch64-linux’ is required to build ‘/nix/store/k6q6y9vqnhvzz1ypvw9zb8pnkza2zp7g-append-initrd-secrets.drv’, but I am a ‘x86_64-linux’
@Mic92 Any idea about this test failure? I'll rebase and run tests locally when I have a chance. Edit: looks like GOB has been posting similar failures on a variety of PRs recently. |
da73a16
to
013a01e
Compare
Ok, I rebased on master, and tests passed locally. |
@corngood this is a bug in the bot. It tries to build the aarch64 build on |
013a01e
to
e591f11
Compare
Rebased again... can someone give me some feedback? This will hopefully save people having to do migrations when they discover it's not using the recommended DB. The documentation and state version will need to be changed if this doesn't make 18.03. |
Probably wouldn't hurt to add a release note regarding the (stateVersion-guarded) breaking change to defaults. Hopefully someone will merge this before 18.03 releases. |
@GrahamcOfBorg test matrix-synapse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine in general
user = cfg.database_user; | ||
database = cfg.database_name; | ||
}; | ||
}."${cfg.database_type}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, an alternative is to have two different options for two databases, I guess. Maybe defining with mkIf
, so that you cannot set the wrong one.
I am not sure that would be better.
Success on aarch64-linux (full log) Partial log (click to expand)
|
Failure on x86_64-linux (full log) Partial log (click to expand)
|
FYI I just ran the tests locally and they passed on x86_64-linux. |
Yes, I don't always trust borg timeouts, and I would be very surprised if you managed to write a matrix service that genuinely works better on aarch64. |
Motivation for this change
A better default configuration for matrix-synapse when
database_type = "psycopg2"
. Postgresql will be enabled, the role/database will be created, and matrix-synapse will connect using the unix socket.TODO:
stateVersion
?Things done
build-use-sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)