Add custom wallpapers via scrpt

Hi again,
The following scripts are what I’m using to try and copy a collection of personal wallpapers into a brand-new installation of Nixos, but I can’t figure out where it goes when it does.

Even though I followed the instructions on the nix wiki regarding the fonts directory, nothing seems to be working for me.

Before you ask, I am aware that the link is for fonts troubleshooting, but that is what I want to accomplish next.

I would appreciate any assistance.

So the layout is:
/Documents/NixOS Scripts/NixOS-SETUP/

mkdir -p ~/.wallpapers
cp ./wallpapers/* ~/.wallpapers/
mkdir -p "$wallpapersDir"
cp "$sourceDir"/* "$wallpapersDir"

I am not an expert in neither Nix or NixOS, but I’m sure you would want to avoid using #!/bin/bash as much as possible and instead place the current store path.

I am not sure how would you do that without defining that script in a nix file and using something like:

writeShellScript = ''
  bla bla bla

Also, if you’re just using UNIX stuff in your shellscript —which I’m almost sure you’re— you could simple use #!/bin/sh which is an already present symlink and a good practice since it removes the dependency on bash. You can make use of ShellCheck.

And now, skiping the pedantery; why do you need a script for that? Isn’t it just simpler to do cp -r foo/bar/wallpapers/ ~/wherever/you/want/to/place/them?

Thanks for your response, at this stage the shebang #!/bin/bash works with no issues and its a personal preference. I also want to utlilise the bash extentions.

You can make use of ShellCheck.

That looks awesome, thanks for the share! :sunglasses:

And now, skiping the pedantery; why do you need a script for that? Isn’t it just simpler to do cp -r foo/bar/wallpapers/ ~/wherever/you/want/to/place/them ?

Doing what you suggested doesn’t seem to be working the same way as my past tries for some weird reason?

1 Like

Really fine project indeed. :ok_hand:

May you please give me a bit more of context of what you’re trying to achieve? I’m a bit lost but I might be able to provide some help. :)

The goal is automatting the copying process by copying the pictures from the wallpapers folder, located in the same directory as my script, and pasting them into the user’s home directory.

However, I’m encountering difficulties due to the use of symbolic links in NixOS to reference the current user’s home directory. The usual command cp -r foo/bar/wallpapers/ ~/wherever/you/want/to/place/them doesn’t achieve the desired outcome. Even with root permissions, the files are only copied to the root home folder instead of the specific user’s folder (e.g., /home/joes). This issue also applies to fonts being copied out of the fonts folder were the script is run.

Additionally, if the process were to work, appropriate permissions should match the current user’s permissions in the wallpapers folder when copied across to enable deletion if desired.

I’m struggling with the symbolic path names and permission referencing to automate the process. :face_with_raised_eyebrow:

Note that the implementation of writeShellScript already contains the shebang: nixpkgs/pkgs/build-support/trivial-builders/default.nix at 6b08e553b4d829ce2758b68a8fa783100667f5af · NixOS/nixpkgs · GitHub

I’d recommend writeShellApplication if you want your scripts to be shellchecked. It’s in general a bit nicer to use, and automatically shellchecks your script.

That said, I don’t think this a problem at all. Your script runs successfully, which is weird, /bin/bash should not exist, but that’s besides the point.

This isn’t caused by symlinks. Executing a script with sudo means that the root user runs it, and ~ refers to the current user’s home directory, i.e. root’s home directory.

Yes, that’s the other problem caused by copying files around as root.

I’m going to need a bit more context here, what exactly is your plan for this script? It’s very imperative, you need to manually run it at some point, so:

  • When do you intend to run this script? Sounds like part of an installation process, but after it has finished?
  • What computer does it run on - some target you’ve ssh’d to?
  • Why do you run it as root?
  • Where do you get “the folder”? I gather it’s just some pictures and fonts you have downloaded in the past?

There’s probably a way to do this much more declaratively in your NixOS config instead of a bash script like this.