Making a development flake for Bespoke Synth

I will explain this later if needed as I need to leave, but long story short, this should work with zsh as well (it is compiling right now so I had no time yet to test the binary output):

{
  description = "A flake for developing bespoke synth";

  # Flake outputs
  outputs = { self, nixpkgs }:
    let
      # Systems supported
      allSystems = [
        "x86_64-linux" # 64-bit Intel/AMD Linux
        "aarch64-linux" # 64-bit ARM Linux
        "x86_64-darwin" # 64-bit Intel macOS
        "aarch64-darwin" # 64-bit ARM macOS
      ];

      # Helper to provide system-specific attributes
      forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f {
        pkgs = import nixpkgs { inherit system; };
      });
    in
      {
        # Development environment output
        devShells = forAllSystems ({ pkgs }:
          let
            scripts = with pkgs; [
              (writeScriptBin "repo-path" ''
                ${pkgs.git}/bin/git rev-parse --show-toplevel
              '')
              (writeScriptBin "clean" ''
                rm -rf "$(repo-path)/cmake-build"
              '')
              (writeScriptBin "clean-release" ''
                rm -rf "$(repo-path)/cmake-build-release"
              '')
              (writeScriptBin "configure" ''
                export out=/tmp/out
                source $stdenv/setup
                export NIX_ENFORCE_PURITY=0
                phases="configurePhase" genericBuild
              '')
              (writeScriptBin "configure-release" ''
              cmake -DCMAKE_BUILD_TYPE=Release -B"$(repo-path)/cmake-build-release"
            '')
              (writeScriptBin "build" ''
                export out=/tmp/out
                source $stdenv/setup
                export NIX_ENFORCE_PURITY=0
                phases="buildPhase" genericBuild
              '')
              (writeScriptBin "build-release" ''
              configure-release
              cmake --build "$(repo-path)/cmake-build-release" --parallel "$(nproc)" --config Release
            '')
            ];
          in
            {
              # You can also create a mkShell by basically copying all fields of bespokesynth,
              # but it is easier to reuse stuff
              default = pkgs.bespokesynth.overrideAttrs (finalAttrs: previousAttrs: {
                # Bespokesynth should use this instead of patching LD_…
                NIX_LDFLAGS = "-rpath ${pkgs.lib.makeLibraryPath (with pkgs; with xorg; [ libX11 libXrandr libXinerama libXext libXcursor libXScrnSaver ])}";
                dontPatchELF = true; # needed or nix will try to optimize the binary by removing "useless" rpath   
                # We add some more packages here to quickly build the package
                buildInputs = previousAttrs.buildInputs ++ scripts;
              }); 
            });
      };
}

To use:

$ nix develop -c zsh
$ cd BespokeSynth # make sure to clone it with submodules
$ configure
$ cd build
$ build

This is mostly a proof of concept, but I think we should add this kind of package to nixpkgs to ease development as right now the user experience is really bad.

Proof:

1 Like