Write multiple files to the same nix store

I am trying to use programs.eww.configDir. I have multiple files in my eww config, but I can’t find a way to write multiple files to the same nix store that can then be passed to the argument above.

It’s asking for a path, you just have to provide the directory that contains your config.

1 Like

Yeah but I want to declare my config in the same nix file, I want the eww config files to sit in the nix store and not my home config folder

They get copied to the store from wherever your hm config is located, and then a symlink is created from ~/.config/eww to that path.
So it’s in the store.
If that’s not what you want, please clarify your usecase.

1 Like

I want to do following (my current example doesn’t work because writeTextDir can only write one file from what I understand):

{ config, pkgs, ... }:

let

  ewwConfig = pkgs.writeTextDir "eww-config" {
    "eww.yuck" = ''
      (defwindow bar
      	:monitor 0
      	:geometry (geometry 	:width "125%"
      				:height "23px"
      				:anchor "bottom center")
      	:exclusive true
      	:focusable false
      	(centerbox
      		(box	:halign "start"
      			(date)
      		)
      		(box	:visible {workspaces_visible==true} (workspaces)
      		)
      		(box	:halign "end"
      			(battery)
      			(volume)
      			current_brightness
      		)
      ))
      
      
      (defwidget battery []
      	(label	:class	{jq(EWW_BATTERY, ".[\"macsmc-battery\"].status") == "\"Charging\"" ? "charging" :  jq(EWW_BATTERY, ".[\"macsmc-battery\"].capacity") < 15 ? "low" : "normal" }
      		:text "''${jq(EWW_BATTERY, ".[\"macsmc-battery\"].capacity")}%"
      ))
      
      (defvar date_type "time")
      (defwidget date []
      	(eventbox	:onclick {date_type=="time" ? "eww update date_type=date" : "eww update date_type=time"}
      		{date_type=="time" ? formattime(EWW_TIME, "%H:%M") : formattime(EWW_TIME, "%Y-%m-%d") }
      ))
      
      
      (defpoll current_volume	:initial ""	
      			:interval "86400s"
        "''${EWW_CONFIG_DIR}/scripts/volume.sh get"
      )
      (defwidget volume []
      	(eventbox	:onclick "''${EWW_CONFIG_DIR}/scripts/volume.sh mute"
      		(label	:text current_volume
      )))
      
      
      (defpoll current_brightness	:initial ""
      				:interval "86400s"
        "brillo | awk '{printf(\"%.0f%%\", $1)}'"
      )
      
      
      (deflisten workspace "hyprland-workspaces _ | jq -rc --unbuffered 'map(if .workspaces | length > 1 then . else .workspaces = [] end)'"
      )
      (defvar workspaces_visible true)
      (defwidget workspaces []
          (box :class "workspaces"
            (for i in {workspace[0].workspaces}
              (eventbox
                :onclick "hyprctl dispatch workspace ''${i.id}"
                :class "''${i.class}"
                "''${i.name}"
      ))))
    '';
    "eww.css" = ''
      .bar {
        color: #CDD6F4;
        background: rgba(0,0,0,0);
      }
      
      label {
      	margin: 0px 10px 0px 10px;
      }
      
      .workspace-active {
      	color: #FFFFFF;
      }
      
      .low {
      	color: #EB4D4B;
      }
      
      .charging {
      	color: #7CFC00;
      }
    '';
    "scripts/volume.sh" = ''
      #!/bin/sh
      
      is_muted() {
          wpctl get-volume @DEFAULT_SINK@ | grep -q "\[MUTED\]"
      }
      
      
      case "$1" in
      	mute)
      		wpctl set-mute @DEFAULT_SINK@ toggle
      		if wpctl get-volume @DEFAULT_SINK@ | grep "\[MUTED\]"; then
      			eww update current_volume="m"
      		else
      			eww update current_volume=$(wpctl get-volume @DEFAULT_SINK@ | awk '{print $2 * 100 "%"}')
      		fi
      		;;
      	get)
      		while :; do
          			output=$(wpctl get-volume @DEFAULT_SINK@ | awk '{print $2 * 100 "%"}')
          			if [ -n "$output" ]; then
              			echo "$output"
              			break
          			fi
          			sleep 0.1
      		done
      		;;
      	up|down)
      		if is_muted; then
      			exit 0
      		fi
      		if [ "$1" = "up" ]; then
      		  wpctl set-volume @DEFAULT_SINK@ 5%+ --limit 1
      		else
      		  wpctl set-volume @DEFAULT_SINK@ 5%- --limit 1
      		fi
      
      		# Update the volume in eww
      		eww update current_volume=$(wpctl get-volume @DEFAULT_SINK@ | awk '{print $2 * 100 "%"}')
      		;;
      esac
    '';
  };
	
in 
{
  programs.eww = {
    enable = true;
    configDir = "${ewwConfig}";
  };
}

Then write it out manually, and don’t use programs.eww.configDir.

  xdg.configFile = {
    "eww/eww.yuck".text = '' ... '';
    "eww/eww.css".text = '' ... '';
  };

so using programs.eww.configDir is then just not possible if I want to include multiple config files?

It’s possible but completely backwards.
Why would you bend over backwards to create a directory of files just to put it into an option that’s just stuffing it back into xdg.configFile anyway?

And as said above, if you want to include multiple config files with configDir, then create a directory with multiple files and just provide that path to the configDir option.
If you want to inline it in the nix file directly then use xdg.configFile.

1 Like