Nixos-rebuild fail: src path with space character

(I think this is a simple issue so forgive me if the solution is stupidly simple ,:3)

Problem

I am adding custom font called “Arcane Nine” through flake. the font file is named Arcane Nine.otf. The space in this name is not being seen as space but two separate files. I tried adding the quotes but they weren’t helping for some reason.

Beside renaming the file, how can I solve this?


This is the content of my custom font file arcaneNine.nix, (notice the quotes around the src path):

#arcaneNine.nix
{ pkgs, ... }:

pkgs.stdenv.mkDerivation {
  name = "Arcane Nine";
  src = "./fonts/Arcane Nine.otf";
  
  phases = [ "installPhase" ];

  installPhase = ''
    mkdir -p $out/share/fonts/opentype
    cp $src $out/share/fonts/opentype/
  '';
}

This is the error that I get, (notice the system sees two separate paths ./fonts/Arcane and ./fonts/Nine.otf):

error: builder for '/nix/store/w44wivw9vk4xqz62b70bpvc95ahl0daa-Arcane-Nine.drv' failed with exit code 1;
       last 3 log lines:
       > Running phase: installPhase
       > cp: cannot stat './fonts/Arcane': No such file or directory
       > cp: cannot stat 'Nine.otf': No such file or directory
       For full logs, run 'nix log /nix/store/w44wivw9vk4xqz62b70bpvc95ahl0daa-Arcane-Nine.drv'.
error: 1 dependencies of derivation '/nix/store/083j79ngpq5lp5b33qkza0cj6w0kdx9d-fc-00-nixos-cache.conf.drv' failed to build
error: 1 dependencies of derivation '/nix/store/q1phvxjm0azqrx3kc9vmw2pgihw1fxbf-steam-run-usr-target.drv' failed to build
error: 1 dependencies of derivation '/nix/store/z783y59z7pv2gf4vvbyk81pbyjnxj4c3-steam-usr-target.drv' failed to build
error: 1 dependencies of derivation '/nix/store/i9cmi2k8jsgv7kk7961v6dgcxisrxzkg-xserver.conf.drv' failed to build
error: 1 dependencies of derivation '/nix/store/5bgmf6gs79dmf7l21lkabpv2vi8vbcvx-fontconfig-conf.drv' failed to build
error: 1 dependencies of derivation '/nix/store/5r3k9nzcav54w5n5zplj941hfyd0bvys-steam-fhs.drv' failed to build
error: 1 dependencies of derivation '/nix/store/09r8b0y9mx9amx5ca48i64bcw7zgjpg6-steam-run-fhs.drv' failed to build
error: 1 dependencies of derivation '/nix/store/9qlfmhy3xcq5rm44h7r3qv2mcsmp78vj-unit-display-manager.service.drv' failed to build
error: 1 dependencies of derivation '/nix/store/zcx2ag8fg7qbpxm0xkrazq2plj8fmgzw-fontconfig-etc.drv' failed to build
error: 1 dependencies of derivation '/nix/store/f01qppvv5ywx3h9yz06knz6mg8spkdcx-steam-bwrap.drv' failed to build
error: 1 dependencies of derivation '/nix/store/mvnmj5nix1rp57h39599194dnz4c262f-steam-run-bwrap.drv' failed to build
error: 1 dependencies of derivation '/nix/store/ifbf9bzjci6bhzzm3hhwv3f8v9m2rzhf-etc.drv' failed to build
error: 1 dependencies of derivation '/nix/store/j8dfn93sicn91sb3phqy757xm7bvbzz6-steam-run.drv' failed to build
error: 1 dependencies of derivation '/nix/store/4bm9w66vdsyg6hnapslyjffwvsh8xfmb-steam.drv' failed to build
error: 1 dependencies of derivation '/nix/store/pfvfanhwzj7q73swlbbx5s82vawa8wgs-nixos-system-nixos-24.11.20240904.ad416d0.drv' failed to build

Edit: changed word “parenthesis” to “quotes”. Silly english error~

Why did you put quotes around the path?

it was giving me a different error. This is end section of the error it was giving me:

error: undefined variable 'Nine'

       at /nix/store/vwhgnjnkyqwywwji4gwyzda94y8bxx1d-source/arcaneNine.nix:6:24:

            5|   name = "Arcane Nine";
            6|   src = ./fonts/Arcane Nine.otf;
             |                        ^
            7|

Path literals can’t have strings in them to my knowledge. You need to concat a string containing the name with space with a path literal like so:

./fonts + "/Arcane Nine.otf"

That still won’t get you very far though because store paths can’t have spaces in them either and forcing the path would cause Nix to copy the path to the store, copying its original name.
I don’t know the solution to that honestly.

Here’s a simpler reproducer:

pkgs.runCommand "arcane-nine" ''
  install ${./fonts + "/Arcane Nine.otf"} -Dt $out/share/fonts/opentype/
''
1 Like

This hack would work but it’d copy the entire fonts dir to the Nix store and the drv would change when anything about the dir changes:

pkgs.runCommand "arcane-nine" { } ''
  install ${./fonts}"/Arcane Nine.otf" -Dt $out/share/fonts/opentype/
''
1 Like