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

nixos/omnom: init module #357830

Merged
merged 1 commit into from
Nov 29, 2024
Merged

nixos/omnom: init module #357830

merged 1 commit into from
Nov 29, 2024

Conversation

eljamm
Copy link
Contributor

@eljamm eljamm commented Nov 21, 2024

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/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 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.

@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Nov 21, 2024
@eljamm eljamm force-pushed the modules/omnom branch 2 times, most recently from 72b9a54 to 0a5c1db Compare November 21, 2024 09:05
@eljamm eljamm added the 8.has: module (new) This PR adds a module in `nixos/` label Nov 21, 2024
options = {
services.omnom = {
enable = lib.mkEnableOption "the omnom webpage bookmarking and snapshotting service.";
debug = lib.mkEnableOption "the omnom debug mode.";
Copy link
Contributor

Choose a reason for hiding this comment

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

We do we have this option and the settings.app.debug option

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That does seem a bit redundant. What do you think about keeping cfg.debug and removing cfg.settings.app.debug as the former is easier to set?

nixos/modules/services/misc/omnom.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/omnom.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/omnom.nix Outdated Show resolved Hide resolved
};

# If the service user is not dynamic, a normal group must exist
users.groups = lib.mkIf ((!isDynamicUser) && (cfg.group == "omnom")) { omnom = { }; };
Copy link
Contributor

Choose a reason for hiding this comment

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

What use-case is there for running the service without DynamicUser?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, you can't register users from the command line if the service is running as a DynamicUser. This is because the Omnom CLI tool runs as the user that starts it and it requires that all the files it needs are in its CWD.

As such, you'd need to cd into dataDir and run the command, but normal users/groups can't access the DynamicUser's work directory.

Another use-case is if you want to run the service as a normal user in your system.

Copy link
Contributor

@xanderio xanderio Nov 22, 2024

Choose a reason for hiding this comment

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

Currently, you can't register users from the command line if the service is running as a DynamicUser. This is because the Omnom CLI tool runs as the user that starts it and it requires that all the files it needs are in its CWD.

In that case we should create a wrapper script that changes the user and set the CWD to the dataDir. See the occ wrapper in nextcloud module for example.

Another use-case is if you want to run the service as a normal user in your system.

As this disables some security features that systemd provides when using DynamicUser I would personally recommend against 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.

In that case we should create a wrapper script that changes the user and set the CWD to the dataDir. See the occ wrapper in nextcloud module for example.

This is a great idea, but even with this, I wasn't able to create users from the command line as a DynamicUser, as it can't cd there (which I even tried to do with systemd-run).

I think that it'd probably be better to run the service non-dynamically for now until the program doesn't need to run from the CWD anymore. What do you think?


services.omnom.settings = {
app.debug = lib.mkDefault cfg.debug;
storage.type = lib.mkDefault "fs";
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please move this into an option, this makes this default show option in the documentation.

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 originally an option, but I removed it because fs is currently the only variant for the storage type, so I don't think it's that useful for users.

nixos/modules/services/misc/omnom.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/omnom.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/omnom.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/omnom.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/omnom.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/omnom.nix Outdated Show resolved Hide resolved
@eljamm eljamm added the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Nov 21, 2024
@eljamm
Copy link
Contributor Author

eljamm commented Nov 21, 2024

Should I squash the commits?

@pluiedev
Copy link
Contributor

Yes please :)

@wegank wegank removed the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Nov 22, 2024
Copy link
Contributor

@xanderio xanderio left a comment

Choose a reason for hiding this comment

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

I hope I don't seam to picky :)

One thing that currently completely missing from the module is handling the SMTP password, this will probably require some preStart config patching. Have a look at the wg-access-server module I've done something like that there.

nixos/modules/services/misc/omnom.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/omnom.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/omnom.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/omnom.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/omnom.nix Outdated Show resolved Hide resolved
Group = cfg.group;
ExecStart = ''
${lib.getExe cfg.package} listen \
--config /etc/omnom/config.yml \
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need to link the config into /etc we can just pass the store path directly.

By placing this in the let in at the top, where settingsFormat is defined.

configFile = settingsFormat.generate "omnom-config.yml" cfg.settings; 

And then replacing this line with --config ${configFile}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my opinion having the config in /etc makes it easier for the users to find and read, without having to hunt down the generated config.

nixos/modules/services/misc/omnom.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/omnom.nix Show resolved Hide resolved
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Nov 22, 2024
@eljamm
Copy link
Contributor Author

eljamm commented Nov 22, 2024

One thing that currently completely missing from the module is handling the SMTP password, this will probably require some preStart config patching. Have a look at the wg-access-server module I've done something like that there.

I'll probably have a look at this tomorrow, thanks!

@eljamm eljamm force-pushed the modules/omnom branch 2 times, most recently from aa3d3fa to 0a745b6 Compare November 23, 2024 16:38
@eljamm
Copy link
Contributor Author

eljamm commented Nov 23, 2024

These are the main changes from the recent squash:

  • Remove debug option and use settings.app.debug instead.
  • Add secretsFile option and handle starting service with secrets.
  • Add settings.smtp and settings.storage.type settings.
  • Assert that settings.smtp.{username,password} are set in secretsFile.
  • Assert that settings.storage.root is in dataDir.

Please let me know if there is anything else that should be improved :)

@eljamm eljamm requested review from pluiedev and xanderio November 23, 2024 16:46
Copy link
Contributor

@xanderio xanderio left a comment

Choose a reason for hiding this comment

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

Think this is going to be the final review round :)

nixos/modules/services/misc/omnom.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/omnom.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/omnom.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/omnom.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/omnom.nix Show resolved Hide resolved
nixos/modules/services/misc/omnom.nix Outdated Show resolved Hide resolved
nixos/modules/services/misc/omnom.nix Outdated Show resolved Hide resolved
@eljamm eljamm added the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Nov 26, 2024
@wegank wegank added 12.approvals: 2 This PR was reviewed and approved by two reputable people and removed 12.approvals: 1 This PR was reviewed and approved by one reputable person labels Nov 26, 2024
@fricklerhandwerk fricklerhandwerk merged commit b9da4f2 into NixOS:master Nov 29, 2024
33 checks passed
@fricklerhandwerk
Copy link
Contributor

Thanks everyone for your help and patience! ❤️

@misuzu
Copy link
Contributor

misuzu commented Nov 29, 2024

This probably deserves a release notes entry

@eljamm eljamm deleted the modules/omnom branch November 29, 2024 18:19
@eljamm eljamm mentioned this pull request Nov 29, 2024
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (new) This PR adds a module in `nixos/` 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 12.approvals: 2 This PR was reviewed and approved by two reputable people
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants