I want to play vintagestory on nixos. The way I play it is:
I have the nixpkgs repository on my disk, and I just run: NIXPKGS_ALLOW_UNFREE=1 NIXPKGS_ALLOW_INSECURE=1 nix-build -A vintagestory
Which createst ./result/bin/vintagestory that I can run. And it works. But if I want to install mods, I would need to add them to ./result/share/vintagestory/Mods but that path is readonly.
Is there a way around this without installing it fully?
Assistant
Yes, you can work around the read-only nature of the path by using a symlink or by overriding the default directory configuration for mods. Here are a couple of methods you can use:
Method 1: Using a Symlink
Create a directory for your mods outside the read-only path. For example:
bash
mkdir -p ~/vintagestory-mods
Create a symlink from the read-only mods directory to your custom directory after building the game:
bash
User
ln: failed to create symbolic link '/home/xxx/dev/nixpkgs-xxx/result/share/vintagestory/Mods/rpvoicechat_2.3.14.zip': Read-only file system
Assistant
If you're receiving a "Read-only file system" error when attempting to create a symbolic link in the read-only directory (./result/share/vintagestory/Mods), that indicates that the result directory produced by Nix is immutable. Here are alternative approaches to handle this situation:
NIXPKGS_ALLOW_UNFREE=1 NIXPKGS_ALLOW_INSECURE=1 nix-build -A vintagestory
ln -s ~/vintagestory-mods ./result/share/vintagestory/Mods
Now you can add your mods to the ~/vintagestory-mods directory, and the game will read them from there.
Method 2: Use Environment Variables
If Vintagestory supports custom mod paths via an environment variable, you can set that environment variable when you run the game. Check the game's documentation, but you might set something like this:
If you prefer a more permanent solution, you can create a small wrapper script to automate the mod handling. Create a file called run_vintagestory.sh with the following content:
bash
#!/bin/bash
MODS_DIR="$HOME/vintagestory-mods"
# Create mod directory if it doesn't exist
mkdir -p "$MODS_DIR"
# Run Vintagestory with the mods directory set up
NIXPKGS_ALLOW_UNFREE=1 NIXPKGS_ALLOW_INSECURE=1 ./result/bin/vintagestory
Make it executable:
bash
chmod +x run_vintagestory.sh
You can then run your mods via this script.
Summary
Choose the method that best fits your workflow. If you want something quick, the symlink method works well. If you want to keep track of your mods more easily, a wrapper script could be a better approach.
Alternative Approach 1: Using nix-shell
You can use nix-shell to temporarily set up an environment where you can run Vintage Story with additional files. It will let you specify an override for the mods during your session:
Create a directory for your mods (if you haven't already):
bash
mkdir -p ~/vintagestory-mods
Use nix-shell to set up a prefered directory for mods:
Another approach is to override the Nix expression used to build Vintage Story to change where it looks for mods. This requires creating a new Nix expression that adjusts the default mods directory, but that can be more complicated depending on your knowledge of Nix.
Summary
The easiest approach is usually copying the build to a writable location and managing your mods there. This way, you’ll avoid any restrictions of the read-only environment and have the freedom to add or modify content as needed.