{
  pkgs,
  config,
  osConfig,
  lib,
  ...
}:
let
  getIfHas =
    path: attrs:
    if path == [ ] then
      attrs
    else if builtins.hasAttr (builtins.head path) attrs then
      getIfHas (builtins.tail path) (builtins.getAttr (builtins.head path) attrs)
    else
      null;

  osConfigGetIfHasOrFalse = path: lib.defaultTo false (getIfHas (lib.splitString "." path) osConfig);

  user = config.home.username;
  homedir = config.home.homeDirectory;
  graphical = osConfigGetIfHasOrFalse "grimmShared.graphical";
in
{
  home.preferXdgDirectories = true;

  home.packages =
    with pkgs;
    [
      deskwhich
    ]
    ++ lib.optionals graphical [
      # imhex
      # libreoffice-qt
      filezilla
      obsidian
      nomacs
      pdfarranger
      krita
      # weasis

      # kicad
      prusa-slicer
      # freecad
      openscad
      iamb
      confy

      vlc
      # blender
    ];

  home.shellAliases = {
    ":q" = "exit";
    "ls" = "eza";
    "lix" = "nix";
    "l" = "eza -hla";
    "vi" = "hx";
    "bat" = "bat --theme=Dracula";
  };
  programs.thunderbird = {
    enable = graphical;
    profiles.default = {
      isDefault = true;
    };
  };

  programs.zathura.enable = graphical;
  programs.bash = {
    enable = true;
    enableCompletion = true;
  };

  services.mpris-proxy.enable = true;
  # services.ssh-agent.enable = true;

  programs.alacritty = {
    enable = graphical;
    settings = {
      font.size = 16;
      font.normal = {
        family = "Noto Sans Mono";
      };
      window.opacity = 0.85;
    };
  };

  programs.starship = {
    enable = true;
    enableBashIntegration = true;
    settings = {
      format = "$all$directory$character";
      nodejs.disabled = true;
      cmake.symbol = "cmake ";
      custom.shell = {
        command = "basename $SHELL";
        when = "test -v SHELL";
        format = " in [$output]($style)";
        # ignore_timeout = true;
      };
      # env_var.SHELL = {variable = "SHELL"; default = ""; };
    };
  };

  programs.fzf.enable = true;
  programs.fzf.tmux.enableShellIntegration = true;

  programs.thefuck = {
    enable = true;
    enableBashIntegration = true;
  };

  programs.helix = {
    enable = true;
    defaultEditor = true;
    settings = {
      editor.cursor-shape.insert = "bar";
      theme = "base16_transparent";
    };
    extraPackages = with pkgs; [
      marksman
      nixd
    ];
  };

  gtk.iconTheme = {
    package = pkgs.adwaita-icon-theme;
    name = "Adwaita";
  };

  gtk.theme = {
    package = pkgs.adw-gtk3;
    name = "adw-gtk3-dark";
  };

  gtk.enable = true;

  programs.tmux = {
    enable = true;
    clock24 = true;
    historyLimit = 50000;
    newSession = true;
  };

  systemd.user.enable = true;
  systemd.user.tmpfiles.rules = lib.optional (osConfigGetIfHasOrFalse "services.printing.cups-pdf.enable") "L ${homedir}/PDF - - - - /var/spool/cups-pdf-pdf/users/${user}";

  xdg.userDirs = {
    enable = true;
    createDirectories = true;
  };

  programs.gradle = {
    enable = true;
    settings = {
      # "org.gradle.java.home" = "${pkgs.openjdk}/lib/openjdk";
      "org.gradle.java.installations.auto-detect" = false;
    };
  };

  programs.gpg = {
    enable = true;
    mutableKeys = true;
    publicKeys = [
      {
        source = ./grimmauld.gpg;
        trust = 5;
      }
    ];
  };

  services.gpg-agent = {
    enable = true;
    enableBashIntegration = true;
    pinentryPackage = if graphical then pkgs.pinentry-qt else pkgs.pinentry-tty;
  };

  # xdg.mimeApps.enable = true;
}