Skip to content

Conversation

mushrowan
Copy link
Contributor

@mushrowan mushrowan commented Aug 9, 2025

Add module support for --stdin-from-command flag, which was added to restic in restic/restic#4410. I also made a few very small changes here and there in the nix code to make it look a little neater in my opinion.

I could potentially add support for the --stdin flag too, but this would require prepending the restic command with an external command and a pipe, which seems a bit messy - and the restic documentation says to prefer --stdin-from-command over --stdin anyway.

I could add an option for --stdin-filename, but I feel that this would be better for users to do in extraBackupArgs.

This is my first (well, other than one i did earlier today) nixpkgs contribution so apologies if I've done anything wrong - please let me know!

I have not added myself to maintainers as I'm unsure if this is needed for a patch to an existing module, and also this is done in #432246 anyway.

I have made an assertion that the stdin backup is mutually exclusive with backing up from paths, but I still need to test that this is necessary - I initially thought it was but I'm not so sure now. Edit: I have checked and this check is actually necessary. It would be cool if you could backup from multiple stdin streams and files at once though, cmon restic......

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • [?] Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

Add a 👍 reaction to pull requests you find important.

@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 12.first-time contribution This PR is the author's first one; please be gentle! 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: changelog This PR adds or changes release notes 8.has: module (update) This PR changes an existing module in `nixos/` 8.has: documentation This PR adds or changes documentation 9.needs: reviewer This PR currently has no reviewers requested and needs attention. labels Aug 9, 2025
'';
example = [
"sudo -u postgres pg_dumpall"
"/home/user/backup"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"/home/user/backup"
"/home/user/backup.sh"

Maybe that's a bit clearer to show the intention

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 i messed the example up, because i though the example section was for showcasing multiple examples haha - i'll fix this bit shortly, it should really be ["sudo" "-u" "postgres" "pg_dumpall"]

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've pushed the bit that fixes this - let me know if you see any issues

@Mindavi
Copy link
Contributor

Mindavi commented Aug 11, 2025

I like the feature, was already looking earlier to see whether this existed. Great to see this contribution! The test seems to fail, so that's definitely something to look into. Also because this is a backup module some more eyes on it would be great.

Note that I didn't test this (yet).

@mushrowan
Copy link
Contributor Author

I like the feature, was already looking earlier to see whether this existed. Great to see this contribution! The test seems to fail, so that's definitely something to look into. Also because this is a backup module some more eyes on it would be great.

Note that I didn't test this (yet).

oh shoot, I got this working yesterday but maybe I broke something during the merge. I'll take a look when I'm on lunch, thanks for letting me know :)

@Mindavi
Copy link
Contributor

Mindavi commented Aug 11, 2025

Would be great if some of the PR context would be in the commit message so it doesn't get lost as easily. Definitely has some useful thoughts and context.

@nixpkgs-ci nixpkgs-ci bot removed the 9.needs: reviewer This PR currently has no reviewers requested and needs attention. label Aug 11, 2025
@mushrowan
Copy link
Contributor Author

@ofborg test restic

@mushrowan
Copy link
Contributor Author

@ofborg test restic

@mushrowan mushrowan changed the title services.restic.backups.*: add command option nixos/restic: add command option Aug 11, 2025
@mushrowan
Copy link
Contributor Author

mushrowan commented Aug 11, 2025

anyone have any idea why offborg skips the test with error: cannot open connection to remote store 'daemon': error: reading from file: Connection reset by peer?
edit: found out how to run the tests locally, sorry for the spam haha. figured out what was going wrong

I'll fix when I get home, sorry I've never never written a nixpkgs test before so it was wizardry to me when I first wrote it

@mushrowan mushrowan force-pushed the restic-command branch 2 times, most recently from 60dd29a to 5780853 Compare August 11, 2025 18:47
@mushrowan
Copy link
Contributor Author

ok should be all ready now! it took me longer than i'd like to admit that everything passed into server.succeed was just bash...

the test runs locally now so i'm not really sure what's up with the ofborg skipping, but if anyone has any ideas i'm all ears.

I could potentially add a test to make sure that you can't pass both backups.a.paths and backups.a.command, but maybe this is overdoing it? If it's not I'm more than happy to do that.

@mushrowan
Copy link
Contributor Author

Would be great if some of the PR context would be in the commit message so it doesn't get lost as easily. Definitely has some useful thoughts and context.

I force-pushed a bit more context - do you think it's okay now, or would you suggest adding anything else?

@mushrowan
Copy link
Contributor Author

@ofborg test restic

@Mindavi
Copy link
Contributor

Mindavi commented Aug 12, 2025

The commit messages look great to me now! I'll see if I can find some time tomorrow or so to look at the delta, but generally if the suggestions are applied I think this is in a quite good state. Thanks!

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Aug 20, 2025
@mushrowan
Copy link
Contributor Author

mushrowan commented Aug 21, 2025

Will look at merge conflict tonight

Copy link
Contributor

@Mindavi Mindavi left a comment

Choose a reason for hiding this comment

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

Ok, I'm happy with this. Still not in a situation that I can easily test it but I trust you tried it + the nixos test.

@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Aug 21, 2025
Add module support for --stdin-from-command flag, which was added to
restic in restic/restic#4410. I also made a few
very small changes here and there in the nix code to make it look a
little neater in my opinion.

I could potentially add support for the --stdin flag too, but this would
require prepending the restic command with an external command and a
pipe, which seems a bit messy - and the restic documentation says to
prefer --stdin-from-command over --stdin anyway.

I could add an option for --stdin-filename, but I feel that this would
be better for users to do in extraBackupArgs.
Test checks that we are able to run a backup from a command, and that
the resulting backup has the contents that we passed into it.
@nixpkgs-ci nixpkgs-ci bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Aug 21, 2025
@Mindavi Mindavi merged commit 6b0b155 into NixOS:master Aug 24, 2025
25 of 27 checks passed
@Mindavi
Copy link
Contributor

Mindavi commented Aug 24, 2025

Thanks for your (first) contribution!

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: changelog This PR adds or changes release notes 8.has: documentation This PR adds or changes documentation 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 This PR causes between 1 and 10 packages to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person. 12.first-time contribution This PR is the author's first one; please be gentle!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants