about summary refs log tree commit diff stats
path: root/pkgs/by-name/mp/mpp/package.nix
blob: 0d2f6c8d05d674b0e3a2a78224276f4a5e6ab225 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# nixos-config - My current NixOS configuration
#
# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of my nixos-config.
#
# You should have received a copy of the License along with this program.
# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
{
  writeShellApplication,
  symlinkJoin,
  stdenv,
  # Dependencies
  mpc,
  mpp-searchadd,
  mpp-lyrics,
  mpp-beetrm,
  # Build dependencies
  fd,
  zsh,
}: let
  script = writeShellApplication {
    name = "mpp";
    text = builtins.readFile ./mpp.sh;
    inheritPath = false;

    runtimeInputs = [
      mpc
      mpp-searchadd
      mpp-lyrics
      mpp-beetrm
    ];
  };

  mpcShare = stdenv.mkDerivation {
    name = "mpp-only-share";
    nativeBuildInputs = [fd];
    strictDeps = true;

    src = mpc;

    buildPhase = ''
      fixMpc() {
        file_path="$1"

        new_file_path="$(echo "$file_path" | sed "s|mpc|mpp|g")"

        echo "Fixing '$file_path' -> '$new_file_path'.."

        [ -f "$file_path"] && mkdir --parents "$(dirname "$new_file_path")"

        mv "$file_path" "$new_file_path"
      }

      # Copy the zsh bundled `mpc` completions to `mpp`
      # TODO: Also add completions for the new subcommands <2024-11-17>
      mkdir --parents share/zsh/site-functions;
      cp "${zsh}/share/zsh/${zsh.version}/functions/_mpc" "share/zsh/site-functions"

      # Replace all reverences to `mpc`. First all files
      fd "mpc" "." --hidden --type file | while read -r file_path; do
        fixMpc "$file_path"
      done
      # Then their possible parent directories.
      fd "mpc" "." --hidden --type directory | while read -r file_path; do
        fixMpc "$file_path"
      done
      # Now patch all reverences to `mpc` away
      fd "." --hidden --type file | while read -r file_path; do
        sed --in-place 's/mpc/mpp/g' "$file_path"
      done
    '';

    installPhase = ''
      mkdir "$out";
      cp --recursive ./share "$out/share";
    '';
  };
in
  symlinkJoin {
    name = "mpp-merged";
    paths = [script mpcShare];
  }