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

meguca: init at 2018-05-17 #39482

Merged
merged 7 commits into from May 27, 2018
Merged

meguca: init at 2018-05-17 #39482

merged 7 commits into from May 27, 2018

Conversation

Chiiruno
Copy link
Contributor

@Chiiruno Chiiruno commented Apr 25, 2018

Motivation for this change

meguca is a great piece of software, and I thought I'd make a package for it.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

@Chiiruno
Copy link
Contributor Author

Chiiruno commented Apr 25, 2018

That said, putting together this package I'm pretty sure there are things in it that can be done better.
If you know any ways to improve it and make it "safer", please do tell.

If there's a way to include cmake in the buildinputs without it autofiring cmake, I'd like to know so that I can add an option to compile the WASM (optional) client, that uses emscripten.

I also can't do the checkPhase because the tests require a postgresql connection and temporary database, in which I don't have the permissions. Is there a way to be able to do the tests?

export HOME=$PWD/.home
export GOPATH=$HOME/go
export GIT_SSL_CAINFO=/etc/ssl/certs/ca-certificates.crt
export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
Copy link
Contributor Author

@Chiiruno Chiiruno Apr 25, 2018

Choose a reason for hiding this comment

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

I'd like especially if someone could tell me a better way to do this.
I'm not familiar with buildGoPackage and couldn't find a way to make it work with the way meguca's build flow goes.

url = "https://github.com/bakape/meguca.git";
rev = "4961e76743fc22c002fcf8f1bc8f77bbe73b2623";
sha256 = "055m323s5vki6dg77mm8sfj88ymh46bjckx8w474gyx5q59jprgp";
fetchSubmodules = false;
Copy link
Member

Choose a reason for hiding this comment

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

If you are not using fetchSubmodules, you can use fetchFromGitHub as well.

@Mic92
Copy link
Member

Mic92 commented Apr 28, 2018

dontUseCmakeConfigure can be set to avoid the cmake hook: https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/tools/build-managers/cmake/setup-hook.sh#L92

@Mic92
Copy link
Member

Mic92 commented Apr 28, 2018

@GrahamcOfBorg build meguca

@GrahamcOfBorg
Copy link

Failure on x86_64-linux (full log)

Attempted: meguca

Partial log (click to expand)

fatal: unable to access 'https://github.com/jteeuwen/go-bindata/': Could not resolve host: github.com
package github.com/jteeuwen/go-bindata/...: exit status 128
github.com/mailru/easyjson (download)
# cd .; git clone https://github.com/mailru/easyjson /build/meguca-4961e76/.home/go/src/github.com/mailru/easyjson
Cloning into '/build/meguca-4961e76/.home/go/src/github.com/mailru/easyjson'...
fatal: unable to access 'https://github.com/mailru/easyjson/': Could not resolve host: github.com
package github.com/mailru/easyjson/...: exit status 128
make: *** [Makefile:61: generate] Error 1
builder for '/nix/store/9yb0qwrknqx4ry1sqm9clplwbnwbdip2-meguca-unstable-2018-04-25.drv' failed with exit code 2
error: build of '/nix/store/9yb0qwrknqx4ry1sqm9clplwbnwbdip2-meguca-unstable-2018-04-25.drv' failed

@GrahamcOfBorg
Copy link

Failure on aarch64-linux (full log)

Attempted: meguca

Partial log (click to expand)

npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

npm ERR! Please include the following file with any support request:
npm ERR!     /build/meguca-4961e76/npm-debug.log
make: *** [Makefile:31: client_deps] Error 1
builder for '/nix/store/8ql02pxvrb20jw6h3qhqz4zn88aj4kjk-meguca-unstable-2018-04-25.drv' failed with exit code 2
�[31;1merror:�[0m build of '/nix/store/8ql02pxvrb20jw6h3qhqz4zn88aj4kjk-meguca-unstable-2018-04-25.drv' failed

@GrahamcOfBorg
Copy link

Failure on x86_64-darwin (full log)

Attempted: meguca

Partial log (click to expand)

+-- gulp-typescript@3.2.4
+-- gulp-uglify@3.0.0
+-- gulp-util@3.0.8
+-- proxy-polyfill@0.1.7
+-- typescript@2.7.2
+-- uglify-es@3.3.10
`-- whatwg-fetch@2.0.4

builder for '/nix/store/df0s5qwj3gfhnaajbfmndl9scqjlfjlr-meguca-unstable-2018-04-25.drv' failed with exit code 2
error: build of '/nix/store/df0s5qwj3gfhnaajbfmndl9scqjlfjlr-meguca-unstable-2018-04-25.drv' failed

@Chiiruno Chiiruno changed the title meguca: init at git-2018-04-25 meguca: init at git-2018-04-28 Apr 29, 2018
@Chiiruno
Copy link
Contributor Author

Chiiruno commented Apr 29, 2018

Pending a review and a hydra build, I believe this is ready to be pulled.

@Chiiruno Chiiruno force-pushed the init/meguca branch 3 times, most recently from 87bd352 to 1316d44 Compare May 1, 2018 20:49
@Chiiruno Chiiruno changed the title meguca: init at git-2018-04-28 meguca: init at git-2018-05-01 May 1, 2018
@Chiiruno Chiiruno force-pushed the init/meguca branch 2 times, most recently from 9c9a232 to 64a7f95 Compare May 1, 2018 21:19
@Chiiruno
Copy link
Contributor Author

Chiiruno commented May 3, 2018

This (may) not build until #39955 is fixed.

@Chiiruno Chiiruno changed the title meguca: init at git-2018-05-01 meguca: init at git-2018-05-03 May 4, 2018
@Chiiruno
Copy link
Contributor Author

Chiiruno commented May 5, 2018

I just realized that I've been using the sandboxing wrong, I'll commit a fix and squash the merge soon.

@Chiiruno Chiiruno changed the title meguca: init at git-2018-05-05 meguca: init at git-2018-05-17 May 18, 2018
@Chiiruno
Copy link
Contributor Author

@Mic92 Hopefully this is the last time I ping you on this pull request.
It seems to be all good.

@Mic92 Mic92 changed the title meguca: init at git-2018-05-17 meguca: init at 2018-05-17 May 20, 2018
WorkingDirectory = "${cfg.baseDir}";
ExecStart = ''${pkgs.meguca}/bin/meguca${if cfg.reverseProxy != null then " -R ${cfg.reverseProxy}" else ""}${if cfg.sslCertificate != null then " -S ${cfg.sslCertificate}" else ""}${if cfg.listenAddress != null then " -a ${cfg.listenAddress}" else ""}${if cfg.cacheSize != null then " -c ${cfg.cacheSize}" else ""}${if cfg.postgresArgs != null then " -d ${cfg.postgresArgs}" else ""}${if cfg.compressTraffic then " -g" else ""}${if cfg.assumeReverseProxy then " -r" else ""}${if cfg.httpsOnly then " -s" else ""} start'';
ExecStop = "${pkgs.meguca}/bin/meguca stop";
ExecRestart = "${pkgs.meguca}/bin/meguca restart";
Copy link
Member

Choose a reason for hiding this comment

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

There is no explicit restart in systemd.

User = "meguca";
Group = "meguca";
WorkingDirectory = "${cfg.baseDir}";
ExecStart = ''${pkgs.meguca}/bin/meguca${if cfg.reverseProxy != null then " -R ${cfg.reverseProxy}" else ""}${if cfg.sslCertificate != null then " -S ${cfg.sslCertificate}" else ""}${if cfg.listenAddress != null then " -a ${cfg.listenAddress}" else ""}${if cfg.cacheSize != null then " -c ${cfg.cacheSize}" else ""}${if cfg.postgresArgs != null then " -d ${cfg.postgresArgs}" else ""}${if cfg.compressTraffic then " -g" else ""}${if cfg.assumeReverseProxy then " -r" else ""}${if cfg.httpsOnly then " -s" else ""} start'';
Copy link
Member

@Mic92 Mic92 May 20, 2018

Choose a reason for hiding this comment

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

Can you break this into multiple lines for readability? You could make it a list that is joined by a spaces.
Also use lib.optionalString to add optional parameter.

password = mkOption {
type = types.str;
default = "meguca";
description = "Password for the meguca database.";
Copy link
Member

Choose a reason for hiding this comment

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

The password is stored in clear text in nix readable for all users. We usually have at least an alternative option that stored the password in a file outside the nix store: #24288
Btw where is this password used in the service?

Copy link
Member

Choose a reason for hiding this comment

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

If meguca also accepts unix sockets for database connections, authentication could be also done via user without any password.
I would not hardcode meguca as default password and rather let the user choose.

Copy link
Contributor Author

@Chiiruno Chiiruno May 20, 2018

Choose a reason for hiding this comment

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

meguca is hard coded into upstream itself as the default, however with postgresArgs you can define the password to access the database with, in which is set each service start with password field.

Copy link
Member

@Mic92 Mic92 left a comment

Choose a reason for hiding this comment

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

The packaging side seems fine. I was not able to the test the service fully yet since the database password is not set in meguca.

@Chiiruno
Copy link
Contributor Author

@Mic92 How is this?

${optionalString (cfg.assumeReverseProxy) " -r"}\
${optionalString (cfg.httpsOnly) " -s"} start
rm -f /run/meguca/start
EOF
Copy link
Member

@Mic92 Mic92 May 21, 2018

Choose a reason for hiding this comment

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

I think you accidentally dropped ExecStart from the service.
You can also use the script property instead of writing your own shell script.

script = ''
  exec ${pkgs.meguca}/bin/meguca -d "$(cat ${cfg.postgresArgsFile})"\
    ${optionalString (cfg.reverseProxy != null) " -R ${cfg.reverseProxy}"}\
    ${optionalString (cfg.sslCertificate != null) " -S ${cfg.sslCertificate}"}\
    ${optionalString (cfg.listenAddress != null) " -a ${cfg.listenAddress}"}\
    ${optionalString (cfg.cacheSize != null) " -c ${toString cfg.cacheSize}"}\
    ${optionalString (cfg.compressTraffic) " -g"}\
    ${optionalString (cfg.assumeReverseProxy) " -r"}\
    ${optionalString (cfg.httpsOnly) " -s"} start
'';

It works the same way preStart works.

Copy link
Member

@Mic92 Mic92 May 21, 2018

Choose a reason for hiding this comment

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

Update just saw the script reference above. This can be just inlined, no need to create a separate script.

Type = "forking";
User = "meguca";
Group = "meguca";
Copy link
Member

Choose a reason for hiding this comment

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

Why did you removed the meguca user here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The meguca user is no longer necessary, since it's running in /run/.
Actually, it was never really necessary, I don't know why I added it to begin with.
If it's part of some standard, I'll re-add.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually never mind, I'll re-add it, since being able to configure the directory in which meguca starts in would be useful.

Copy link
Member

Choose a reason for hiding this comment

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

But then the server would run as root, right? If it can be avoided network-facing services should not run as root.

@Chiiruno Chiiruno force-pushed the init/meguca branch 2 times, most recently from 436678d to 2d0e613 Compare May 21, 2018 12:35
@Chiiruno
Copy link
Contributor Author

@Mic92 Ok, that should do it.
Diff for convenience.

script = ''
cd ${cfg.baseDir}

${pkgs.meguca}/bin/meguca -d "$(cat ${cfg.postgresArgsFile})"\
Copy link
Member

Choose a reason for hiding this comment

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

Too bad the password is not cleared in meguca and visible to any other process such as top:

/nix/store/7l3naj8wdpg9akp8bjps4nwl863nb216-meguca-unstable-2018-05-26-bin/bin/meguca -d user=meguca password=meguca dbname=meguca sslmode=disable start

This is an upstream issue however and should not be fixed in this pull request.

Copy link
Member

Choose a reason for hiding this comment

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

tracked here: bakape/shamichan#729

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.

None yet

5 participants