streamrip icon indicating copy to clipboard operation
streamrip copied to clipboard

Create a nix flake for nix users

Open imadnyc opened this issue 1 year ago • 3 comments

Hey, I created a simple nix flake for people who use nix like me. The issue I'm running into with is that the --no-db seems to still want to assert a path from the executable dir, which in NixOS it can't do because the executable dir is immutable. The fix should be simple -- just make the assert path in db.py a conditional that checks if no-db is passed first. I don't want to change that though because I'm unfamiliar with the code and am unsure if it'll break something, so I'd like some more feedback first.

imadnyc avatar Apr 22 '24 19:04 imadnyc

The folder where streamrip stores configuration is generated using the appdirs package. If it's generating a folder that's immutable on Nix that suggests appdirs doesn't support NixOS. Maybe you should open a bug report there too.

In the meantime, a fix could simply be to override the folder in

https://github.com/nathom/streamrip/blob/87579566365b3d354b6ec941618bee256b0df659/streamrip/rip/user_paths.py#L4-L10

if NixOS is detected.

nathom avatar Apr 22 '24 23:04 nathom

Hey, sorry, I forgot to attach logs that I thought would be helpful.

➜  streamrip git:(dev) ✗ run .# -- --config-path ./config.toml --no-db search qobuz  album 'rael'
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /nix/store/p4j7bl3paq27d64ifxbygcfk5cphc8g3-python3.11-streamrip-2.0.5/bin/.rip-wrapped:9 in     │
│ <module>                                                                                         │
│                                                                                                  │
│    6 from streamrip.rip import rip                                                               │
│    7 if __name__ == "__main__":                                                                  │
│    8 │   sys.argv[0] = re.sub(r"(-script\.pyw|\.exe)?$", "", sys.argv[0])                        │
│ ❱  9 │   sys.exit(rip())                                                                         │
│   10                                                                                             │
│                                                                                                  │
│ /nix/store/wkqfh7y23c3qlmg8igdaw256whsvqndv-python3.11-click-8.1.7/lib/python3.11/site-packages/ │
│ click/core.py:1157 in __call__                                                                   │
│                                                                                                  │
│                                     ... 10 frames hidden ...                                     │
│                                                                                                  │
│ /nix/store/p4j7bl3paq27d64ifxbygcfk5cphc8g3-python3.11-streamrip-2.0.5/lib/python3.11/site-packa │
│ ges/streamrip/rip/main.py:64 in __init__                                                         │
│                                                                                                  │
│    61 │   │   │   downloads_db = db.Dummy()                                                      │
│    62 │   │                                                                                      │
│    63 │   │   if c.failed_downloads_enabled:                                                     │
│ ❱  64 │   │   │   failed_downloads_db = db.Failed(c.failed_downloads_path)                       │
│    65 │   │   else:                                                                              │
│    66 │   │   │   failed_downloads_db = db.Dummy()                                               │
│    67                                                                                            │
│                                                                                                  │
│ /nix/store/p4j7bl3paq27d64ifxbygcfk5cphc8g3-python3.11-streamrip-2.0.5/lib/python3.11/site-packa │
│ ges/streamrip/db.py:67 in __init__                                                               │
│                                                                                                  │
│    64 │   │   """                                                                                │
│    65 │   │   assert self.structure != {}                                                        │
│    66 │   │   assert self.name                                                                   │
│ ❱  67 │   │   assert path                                                                        │
│    68 │   │                                                                                      │
│    69 │   │   self.path = path                                                                   │
│    70                                                                                            │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
AssertionError

How nix works is that the the entire repo is copied to an immutable folder, so any thing that changes/creates a file in the repo dir is impossible. That said, the program seems to continue fine if I comment out the assert path, which doesn't make sense -- the path should exist, it should just be immutable.

If I print("this is the name of the path", path) like so in db.py:

assert self.structure != {}
assert self.name
print("This is the path name",path)
if (path == ""):
        print("yup, it's an empty string")
assert path

I get that path is just an empty string. If I then set path = "<some path>" (thereby passing the assert, commenting works also) it works fine. Is this still related to the appdirs thing or something else? I could start a diff bug report if you'd like. I'm kind of unsure as to why it's getting an empty string -- if this is something that I can only get on my machine let me know and I'll do some more testing.

Worst comes to worst I could just add a .patch that's only used in my flake but maybe other non-nix users have this too

imadnyc avatar Apr 22 '24 23:04 imadnyc

Do you have db paths set in the config?

nathom avatar Apr 23 '24 00:04 nathom