summaryrefslogtreecommitdiff
path: root/accounts/gkleen@skadhi/zsh/default.nix
blob: ddc69f0d620aeb7c098eebd3c5ddb0ce6c99cead (plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
{ pkgs, lib, config, sysConfig, flakeInputs, ... }:
let
  zshrc = pkgs.resholve.mkDerivation {
    pname = "zshrc";
    version = "0.0.0";

    src = ./zshrc;

    dontUnpack = true;
    dontConfigure = true;
    dontBuild = true;

    installPhase = ''
      mkdir -p $out/share
      install "$src" $out/share/zshrc
    '';

    solutions = {
      default = {
        scripts = [ "share/zshrc" ];
        interpreter = "none";
        inputs = with pkgs; [
          coreutils
          rpm
          binutils
          squashfsTools
          unzip
          config.programs.git.package
          magickWrapped
          curl
          file
          gnutar
          cpio
          magic-wormhole
          config.programs.zsh.package
          util-linux
          findutils
          qrencode
          tty-clock
          config.programs.jq.package
          eza
          less
          sysConfig.systemd.package
          sysConfig.programs.ssh.package
          gnused
          miniserve
          p7zip
        ];
        execer = with pkgs; [
          "cannot:${lib.getExe' rpm "rpm2cpio"}"
          "cannot:${lib.getExe' squashfsTools "unsquashfs"}"
          "cannot:${lib.getExe' unzip "unzip"}"
          "cannot:${lib.getExe config.programs.git.package}"
          "cannot:${lib.getExe cpio}"
          "cannot:${lib.getExe' magic-wormhole "wormhole"}"
          "cannot:${lib.getExe' fuse "fusermount"}"
          "cannot:${lib.getExe less}"
          "cannot:${lib.getExe' sysConfig.systemd.package "systemctl"}"
          "cannot:${lib.getExe sysConfig.programs.ssh.package}"
          "cannot:${lib.getExe' p7zip "7z"}"
        ];
        wrapper = with pkgs; [
          "${lib.getExe' magickWrapped "magick"}:${lib.getExe' imagemagick "magick"}"
        ];
        fake = {
          builtin = ["print"];
          external = lib.mapAttrsToList (_: cfg: cfg.program) sysConfig.security.wrappers;
        };
      };
    };
  };
  magickWrapped = pkgs.symlinkJoin {
    inherit (pkgs.imagemagick) name;
    paths = [ pkgs.imagemagick ];

    buildInputs = with pkgs; [ makeWrapper ];
    postBuild = ''
      wrapProgram $out/bin/magick \
        --prefix PATH : ${lib.makeBinPath (with pkgs; [ ghostscript ])}
    '';
  };
in {
  config = {
    programs.zsh.initContent = ''
      source ${zshrc}/share/zshrc
    '';
    programs.zsh.dirHashes = let
      flakeHashes = lib.mapAttrs' (n: v: lib.nameValuePair (inputNames.${n} or n) (toString v)) flakeInputs;
      inputNames = {
        self = "nixos";
      };
    in flakeHashes // {
        docs = "$HOME/documents";
        dl = "$HOME/Downloads";
        scrot = "$HOME/screenshots";
        media = "$HOME/media";
    };
    programs.starship.settings = {
      directory.substitutions = lib.mapAttrs' (name: value: let
        value' = builtins.unsafeDiscardStringContext value;
        value'' = if lib.hasPrefix "$HOME/" value' then "~" + lib.removePrefix "$HOME" value' else value';
      in lib.nameValuePair value'' "~${name}"
      ) config.programs.zsh.dirHashes;
    };
  };
}