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

piwik & piwik service: init at 3.0.4 #26073

Merged
merged 1 commit into from
Jun 27, 2017
Merged

Conversation

florianjacob
Copy link
Contributor

Motivation for this change

Piwik is an open analytics application. Resolves #25266.

Things done
  • Tested by @Alphor
  • Tested using sandboxing
    (nix.useSandbox on NixOS,
    or option build-use-sandbox in nix.conf
    on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • Linux
  • 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.

@mention-bot
Copy link

@florianjacob, thanks for your PR! By analyzing the history of the files in this pull request, we identified @edolstra, @joachifm and @offlinehacker to be potential reviewers.

@@ -295,6 +295,7 @@
aria2 = 277;
clickhouse = 278;
rslsync = 279;
piwik = 280;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is a static uid required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My initial thought was so that the whole dataDir folder /var/lib/piwik can be easily restored from a backup, e.g. after a failure that needed a reinstall or on another machine.

In the meantime I learned that actually only a single file, /var/lib/piwik/config/config.ini.php needs to be backed up. It's probably easy enough to fix uid+gid for a single file manually on restores, so I guess it's not that required anymore. Nothing in the code depends on it, I could simply remove the static assignment again.

This is my first nixpkg package, could you tell me more about in which cases and for what purposes it's considered good pratice to use static ids, and in which it isn't?

Copy link
Contributor

Choose a reason for hiding this comment

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

The most clear-cut use for static uids is if you need to refer to a user before the user/uid mapping is established. Otherwise, you need to make a judgement about the kind of data the daemon generates, whether you'd transfer the data between hosts, whether ownership can be easily fixed up, what the privacy or security implications would be if the data ended up being owned (however transiently) by another user etc.

Relying on static uids to maintain ownership invariants is fragile imo (it won't help if you transfer data to a non-NixOS host, for example). Better to have code that enforces invariants you care about directly.

Now, I don't mean to say you should overthink this but there should be a reason for doing it :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks alot for that explanation, that was very helpful. :)

I decided to remove the static ids and added a small chown+chmod script in the systemd unit that is executed as root and enforces the right ownership and permissions on startup instead. I figured that's much more beneficial to what I wanted to achieve, keeping things private while allowing an occasional but easy restore/move.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good to me. If it turns out that a static uid makes more sense, it can always be added later (the other way 'round is a little harder).

@florianjacob
Copy link
Contributor Author

@joachifm thanks for taking a look! 😄

@florianjacob florianjacob force-pushed the piwik-package branch 5 times, most recently from 258b4c1 to 3dd9633 Compare June 15, 2017 17:23
Copy link
Contributor

@joachifm joachifm left a comment

Choose a reason for hiding this comment

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

Added some nitpicks for you to consider. None of them blockers.

home = dataDir;
group = "${user}";
};
users.extraGroups = [ { name = "${user}"; } ];
Copy link
Contributor

Choose a reason for hiding this comment

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

I think users.extraGroups.${user} = {} would work as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Much more elegant. 😃

requiredBy = [ "${phpExecutionUnit}.service" ];
before = [ "${phpExecutionUnit}.service" ];
# the update part of the script can only work if the database is already up and running
requires = [ "${databaseService}" ];
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that "${foo}" could be simplified to foo.

serviceConfig = {
Type = "oneshot";
User = user;
Group = user;
Copy link
Contributor

Choose a reason for hiding this comment

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

Group is strictly redundant, it defaults to the primary group of User.

sha512 = "2i0vydr073ynv7wcn078zxhvywdv85c648hympkzicdd746g995878py9006m96iwkmk4q664wn3f8jnfqsl1jd9f26alz1nssizbn9";
};

phases = [ "unpackPhase" "patchPhase" "installPhase" ];
Copy link
Contributor

Choose a reason for hiding this comment

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

Please consider disabling problematic phases instead of listing phases; this is a known source of bugs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could just throw this out completely, did learn that all default phases don't do anything like the buildPhase doesn't do anything if there is no Makefile.


phases = [ "unpackPhase" "patchPhase" "installPhase" ];

buildInputs = [ makeWrapper ];
Copy link
Contributor

Choose a reason for hiding this comment

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

Can go innativeBuildInputs.


# regarding substitutes: looks like this is just a bug / confusion of the directories, and nobod yhas tested this.
# PR at https://github.com/piwik/piwik/pull/11661
patchPhase = ''
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider postPatch; at least in general its nice to allow applying arbitrary patches via override. Specifying a custom patch phase prevents that.

enable = mkOption {
type = types.bool;
default = false;
example = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: examples for booleans are usually skipped, it's self-evident.

type = types.bool;
default = false;
example = true;
description = ''
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that long-form descriptions may not render very well. You can generate the nixos manual to check whether it'll look okay. You can farm out longer documentation fragments to the manual.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, it renders quite bad.

So it would be ok to include a new manual section like II.Configuration > 22. piwik for that longer part? I was struggeling to find a good place for this, but now I see this long description isn't one.

# TODO: Move more unnecessary files from share/, especially using PIWIK_INCLUDE_PATH.
# See https://forum.piwik.org/t/bootstrap-php/5926/10 and
# https://github.com/piwik/piwik/issues/11654#issuecomment-297730843
installPhase = ''
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that this will cause install hooks to be skipped (you can run e..g, the post phase hook manually with runHook postInstall).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand. I added runHook call for preInstall / postInstall as first / last commands of my installPhase, mirroring the default implementation I found in pkgs/stdenv/generic/setup.sh. From that file I assume there's no better way to overwrite / have a custom installPhase without having to call the hooks by hand, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Pretty much. At some point I think it's possible hooks may become implicit, making this a bit more natural.

description = "A real-time web analytics application";
license = licenses.gpl3Plus;
homepage = https://piwik.org/;
platforms = platforms.all;
Copy link
Contributor

Choose a reason for hiding this comment

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

If you wish, you could add yourself to the list of maintainers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought you had to be part of the NixOS github organization to be a maintainer. 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

Not at all. It basically means you care about the package, lets other's know to ping you if there are questions or whatever.

@florianjacob
Copy link
Contributor Author

Added some nitpicks for you to consider. None of them blockers.

I can feel the packaging quality is increasing…✨ 😄

@joachifm
Copy link
Contributor

I don't have much more to add, so let me know when you're ready to integrate.

@@ -6,7 +6,7 @@

<title>Piwik</title>
<para>
Piwik is a real-time web analytics application.
Piwik is a real-time web analytics web application.
Copy link

Choose a reason for hiding this comment

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

Might want to revert this line :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was actually intentional, as it is a web application for web analytics, but I admit it sounds really weird in english, adds nothing much and probably irritates the reader more than clarifies stuff. 😆 Thanks!

Copy link

Choose a reason for hiding this comment

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

Yeah, I could see that.

@florianjacob florianjacob force-pushed the piwik-package branch 3 times, most recently from 6b5fd6d to 711507a Compare June 17, 2017 20:44
@florianjacob
Copy link
Contributor Author

@joachifm / @Alphor I've aded a NixOS manual chapter for piwik now, and I think it's good not to try to cram it all into the description. 😄 If you don't have any other suggestions for the manual, I'd be ready to integrate now.

The manual also contains a paragraph on this sendmail issue, I'd remove it later if the issue is resolved, but it seems to be nothing trivial: #26611

@Alphor can I get back on your offer to test other stuff? In case you have some kind of sendmail via nullmailer, postfix or something else, could you hit the „forgot password“ on piwik's login and try to reset it? This should result in an error displayed in the browser, and a journald log error like I posted it in the issue.

@ajarara
Copy link

ajarara commented Jun 19, 2017

@florianjacob
I've never used sendmail/procmail for email. Do I just need an MTA to test this?

@florianjacob
Copy link
Contributor Author

@Alphor yes, an MTA would be enough, it just needs to provide the sendmail command somehow. Does not even need to work and be able to send mails to the outer world, as it'll most likely fail instantly on invoking sendmail. For postfix and nullmailer (did not look at any other MTAs for NixOS so far), just enabling them without any further configuration is enough. (For real operation, at least the fully-qualified domain name needs to be provided if it's not already in your hostname)

@joachifm joachifm merged commit 767a8b2 into NixOS:master Jun 27, 2017
@joachifm
Copy link
Contributor

Thank you

@florianjacob florianjacob deleted the piwik-package branch June 27, 2017 22:08
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.

None yet

4 participants