Can I configure a modified sway config

The wiki says that I can specify sway’s config file using "sway/config".source = ./dotfiles/sway/config;.

But is there a way to build the source through pkgs.callPackage?

For example, what I was thinking is:

environment.etc."sway".source = (pkgs.callPackage ./build-sway-config.nix { });

and build-sway-config.nix would start with:

pkgs.runCommand "sway-conf" { } ''
   mkdir -p $out
   cat <<EOM >$out/config
   set $mod Mod4

The problem I get is:

duplicate entry sway/config -> /nix/store/4zplbkm6shk9agsy52pmhx9ia0vqdavq-sway-1.4/etc/sway/config
mismatched duplicate entry  <-> /nix/store/4zplbkm6shk9agsy52pmhx9ia0vqdavq-sway-1.4/etc/sway/config

Is there a way to build a sway config file through nix?

I think what is happening here, is you’re writing the file twice hence the duplicate error. environment.etc.*.source = is expecting a path and it will write the contents of the path to the store and link it into /etc/ for you. You’re returning a derivation which I believe can be interpolated as a path. So when you call pkgs.runCommand which is a simple builder it’s also writing the string to the store. Since they have the exact same contents the inputs are identical and so is the hash.

If you make build-sway-config.nix a function that directly returns a string instead of using pkgs.runCommand, you could call it like this to get the effect I think you want:

environment.etc."sway/config".text = (pkgs.callPackage ./build-sway-config.nix { });

Yes, this is possible. As @wkral says, the problem is that the option is defined twice — once by the NixOS sway module:

and once by your config.

To override the definition from the sway module, you can use lib.mkForce to give your definition higher priority:

{ pkgs, lib, ...}: {
  programs.sway.enable = true;
  environment.etc."sway/config".source = lib.mkForce (pkgs.callPackage ./build-sway-config.nix {});

That aside, the way you have written it currently will cause the symlink at /etc/sway/config to point to a directory, which is probably not what you want :slight_smile: write directly to $out in your build script rather than creating $out as a directory to fix that, or make it more concise using writeText:

{ writeText, kanshi }:
writeText "sway.conf" ''
  set $mod Mod4
  # ...
  exec "${kanshi}/bin/kanshi"
  # ...