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

Autostart doesn't work on NixOS #1975

Closed
YizhePKU opened this issue Oct 14, 2021 · 3 comments · Fixed by #1979
Closed

Autostart doesn't work on NixOS #1975

YizhePKU opened this issue Oct 14, 2021 · 3 comments · Fixed by #1979
Labels
Hacktoberfest Unconfirmed Bug The bug is not confirmed by anyone else.

Comments

@YizhePKU
Copy link
Contributor

YizhePKU commented Oct 14, 2021

Flameshot version
Tested on both master and v0.11.1

Describe the bug

Autostart doesn't work.

On NixOS, if the directory ~/.config/autostart doesn't exist, Flameshot will try to write the desktop file to somewhere in /nix/store. However, /nix/store is read-only, so that fails.

To Reproduce

Install Flameshot on NixOS. Launch it with strace flameshot 2>&1 | grep open so that we can observe where it tries to write files. When flipping Launch at startup in configuations, strace will print some like this:

openat(AT_FDCWD, "/nix/store/nkgiwqxc5i6fhkzm4lj8p11gjpclm5cj-plasma-workspace-5.21.5/etc/xdg/autostart/Flameshot.desktop", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0666) = -1 EROFS (Read-only file system)

Expected behavior

The desktop file should be written to ~/.config/autostart, creating the directory if necessary.

System Information

NixOS 21.05

@YizhePKU
Copy link
Contributor Author

YizhePKU commented Oct 14, 2021

The buggy code is in src/utils/confighandler.cpp, function ConfigHandler::setStartupLaunch.

    QString path = QStandardPaths::locate(QStandardPaths::GenericConfigLocation,
                                          "autostart/",
                                          QStandardPaths::LocateDirectory);
    QDir autostartDir(path);
    if (!autostartDir.exists()) {
        autostartDir.mkpath(".");
    }

    QFile file(path + "Flameshot.desktop");

I think QStandardPaths::locate prefers existent path to writable path. My suggested fix is:

    QString path = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/autostart/";
    QDir autostartDir(path);
    if (!autostartDir.exists()) {
        autostartDir.mkpath(".");
    }

    QFile file(path + "Flameshot.desktop");

@veracioux
Copy link
Contributor

veracioux commented Oct 14, 2021

@YizhePKU I suspect your solution is correct. If you have a development environment set up and you are up for it, feel free to submit a pull request. If not, I can do that.

@veracioux veracioux added Unconfirmed Bug The bug is not confirmed by anyone else. Hacktoberfest labels Oct 14, 2021
@YizhePKU
Copy link
Contributor Author

I tested my solution locally and it works nicely. Didn't run the test suite though, this should be fine?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hacktoberfest Unconfirmed Bug The bug is not confirmed by anyone else.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants