{ config, pkgs, pkgs-kdenlive, pkgs-blender, userSettings, ... }:

{
  # Home Manager needs a bit of information about you and the paths it should
  # manage.
  home.username = userSettings.username;
  home.homeDirectory = "/home/"+userSettings.username;

  programs.home-manager.enable = true;

  imports = [
              (./. + "../../../user/wm"+("/"+userSettings.wm+"/"+userSettings.wm)+".nix") # My window manager selected from flake
              ../../user/shell/sh.nix # My zsh and bash config
              ../../user/shell/cli-collection.nix # Useful CLI apps
              ../../user/app/doom-emacs/doom.nix # My doom emacs config
              ../../user/app/ranger/ranger.nix # My ranger file manager config
              ../../user/app/git/git.nix # My git config
              ../../user/app/keepass/keepass.nix # My password manager
              (./. + "../../../user/app/browser"+("/"+userSettings.browser)+".nix") # My default browser selected from flake
              ../../user/app/virtualization/virtualization.nix # Virtual machines
              #../../user/app/flatpak/flatpak.nix # Flatpaks
              #../../user/app/blender/default.nix
              #../../user/app/input-remapper/input-remapper.nix # input-remapper service
              #../../user/app/icesl/icesl.nix # 3D Printer Slicer - ( my go to option )
              ../../user/style/stylix.nix # Styling and themes for my apps
              ../../user/lang/cc/cc.nix # C and C++ tools
              ../../user/lang/godot/godot.nix # Game development
              #../../user/pkgs/blockbench.nix # Blockbench ## marked as insecure
              ../../user/hardware/bluetooth.nix # Bluetooth
              #../../user/hardware/peripherals.nix # Peripheral Configurations ( input-remapper, mouse )
            ];

  home.stateVersion = "22.11"; # Please read the comment before changing.

  home.packages = (with pkgs; [
    # Core
    zsh
    alacritty
    librewolf
    brave
    qutebrowser
    dmenu
    rofi
    git
    syncthing
    ntfs3g
    nwg-displays
    input-remapper
    ark
    nh

    # Office
    libreoffice-fresh
    mate.atril
    openboard
    xournalpp
    gnome.adwaita-icon-theme
    shared-mime-info
    glib
    newsflash
    foliate
    gnome.nautilus
    gnome.gnome-calendar
    gnome.seahorse
    gnome.gnome-maps
    gnome.gnome-screenshot
    openvpn
    #evolution
    #evolution-ews
    protonmail-bridge
    texliveSmall
    numbat

    wine
    bottles
    # The following requires 64-bit FL Studio (FL64) to be installed to a bottle
    # With a bottle name of "FL Studio"
    (pkgs.writeShellScriptBin "flstudio" ''
       #!/bin/sh
       if [ -z "$1" ]
         then
           bottles-cli run -b "FL Studio" -p FL64
           #flatpak run --command=bottles-cli com.usebottles.bottles run -b FL\ Studio -p FL64
         else
           filepath=$(winepath --windows "$1")
           echo \'"$filepath"\'
           bottles-cli run -b "FL Studio" -p "FL64" --args \'"$filepath"\'
           #flatpak run --command=bottles-cli com.usebottles.bottles run -b FL\ Studio -p FL64 -args "$filepath"
         fi
    '')
    (pkgs.makeDesktopItem {
      name = "flstudio";
      desktopName = "FL Studio 64";
      exec = "flstudio %U";
      terminal = false;
      type = "Application";
      mimeTypes = ["application/octet-stream"];
    })

    # Media
    gimp
    pinta
    krita
    inkscape
    musikcube
    vlc
    mpv
    yt-dlp
    # blender
    orca-slicer
    kdePackages.print-manager
    gnomeExtensions.printers
    cura
    curaengine_stable
    (stdenv.mkDerivation {
      name = "cura-slicer";
      version = "0.0.7";
      src = fetchFromGitHub {
        owner = "Spiritdude";
        repo = "Cura-CLI-Wrapper";
        rev = "ff076db33cfefb770e1824461a6336288f9459c7";
        sha256 = "sha256-BkvdlqUqoTYEJpCCT3Utq+ZBU7g45JZFJjGhFEXPXi4=";
      };
      phases = "installPhase";
      installPhase = ''
        mkdir -p $out $out/bin $out/share $out/share/cura-slicer
        cp $src/cura-slicer $out/bin
        cp $src/settings/fdmprinter.def.json $out/share/cura-slicer
        cp $src/settings/base.ini $out/share/cura-slicer
        sed -i 's+#!/usr/bin/perl+#! /usr/bin/env nix-shell\n#! nix-shell -i perl -p perl538 perl538Packages.JSON+g' $out/bin/cura-slicer
        sed -i 's+/usr/share+/home/${userSettings.username}/.nix-profile/share+g' $out/bin/cura-slicer
      '';
      propagatedBuildInputs = with pkgs; [
        curaengine_stable
      ];
    })

    obs-studio
    ffmpeg
    (pkgs.writeScriptBin "kdenlive-accel" ''
      #!/bin/sh
      DRI_PRIME=0 kdenlive "$1"
    '')
    movit
    mediainfo
    libmediainfo
    mediainfo-gui
    audio-recorder
    gnome.cheese
    ardour
    rosegarden
    tenacity
    spotify-player

    # Various dev packages
    texinfo
    libffi
    zlib
    nodePackages.ungit
    #cudatoolkit
    pkgs-blender.blender
  ]) ++ ([ pkgs-kdenlive.kdenlive ]);

  # programs.nh = {
  #   enable = true;
  #   clean.enable = true;
  #   clean.extraArgs = "--keep-since 4d --keep 3";
  #   flake = "${config.home.homedirectory}/.dotfiles";
  # };

  services = {
      syncthing = {
        enable = true;
    };
  };

  xdg.enable = true;
  xdg.userDirs = {
    enable = true;
    createDirectories = true;
    music = "${config.home.homeDirectory}/Media/Music";
    videos = "${config.home.homeDirectory}/Media/Videos";
    pictures = "${config.home.homeDirectory}/Media/Pictures";
    templates = "${config.home.homeDirectory}/Templates";
    download = "${config.home.homeDirectory}/Downloads";
    documents = "${config.home.homeDirectory}/Documents";
    desktop = null;
    publicShare = null;
    extraConfig = {
      XDG_DOTFILES_DIR = "${config.home.homeDirectory}/.dotfiles";
      XDG_ARCHIVE_DIR = "${config.home.homeDirectory}/Archive";
      XDG_VM_DIR = "${config.home.homeDirectory}/Machines";
      XDG_ORG_DIR = "${config.home.homeDirectory}/Org";
      XDG_PODCAST_DIR = "${config.home.homeDirectory}/Media/Podcasts";
      XDG_BOOK_DIR = "${config.home.homeDirectory}/Media/Books";
      XDG_ICESL_DIR = "${config.home.homeDirectory}/.icesl";
    };
  };
  xdg.mime.enable = true;
  xdg.mimeApps.enable = true;
  xdg.mimeApps.associations.added = {
    "application/octet-stream" = "flstudio.desktop;";
  };
  xdg.configFile = {
      #"${config.home.homeDirectory}/.dotfiles/user/app/icesl/result/icesl-effects".source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/.dotfiles/user/app/icesl/config/icesl-effects";
      #"${config.home.homeDirectory}/.dotfiles/user/app/icesl/result/icesl-infillers".source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/.dotfiles/user/app/icesl/config/icesl-infillers";
      #"${config.home.homeDirectory}/.dotfiles/user/app/icesl/result/icesl-libs".source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/.dotfiles/user/app/icesl/config/icesl-libs";
      #"${config.home.homeDirectory}/.dotfiles/user/app/icesl/result/icesl-models".source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/.dotfiles/user/app/icesl/config/icesl-models";
      #"${config.home.homeDirectory}/.dotfiles/user/app/icesl/result/icesl-plugins".source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/.dotfiles/user/app/icesl/config/icesl-plugins";
      #"${config.home.homeDirectory}/.dotfiles/user/app/icesl/result/icesl-printers".source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/.dotfiles/user/app/icesl/config/icesl-printers";
      #"${config.home.homeDirectory}/.icesl/icesl-themes".source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/.dotfiles/user/app/icesl/result/icesl-themes";
      "${config.home.homeDirectory}/.icesl/icesl-plugins/libsampleInfillerPlugin.so".source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/.dotfiles/user/app/icesl/result/icesl-plugins/libsampleInfillerPlugin.so";
      "${config.home.homeDirectory}/.icesl/icesl-plugins/libsampleMachineCodePlugin.so".source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/.dotfiles/user/app/icesl/result/icesl-plugins/libsampleMachineCodePlugin.so";
      "${config.home.homeDirectory}/.icesl/icesl-plugins/libsamplePostProcessingPlugin.so".source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/.dotfiles/user/app/icesl/result/icesl-plugins/libsamplePostProcessingPlugin.so";
      "${config.home.homeDirectory}/.icesl/icesl-printers/fff/ARES_RED_CUSTOM/materials/pla.lua".source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/.dotfiles/user/app/icesl/result/icesl-printers/fff/ARES_RED_CUSTOM/materials/pla.lua";
      "${config.home.homeDirectory}/.icesl/icesl-printers/fff/ARES_RED_CUSTOM/profiles/high.lua".source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/.dotfiles/user/app/icesl/result/icesl-printers/fff/ARES_RED_CUSTOM/profiles/high.lua";
      "${config.home.homeDirectory}/.icesl/icesl-printers/fff/ARES_RED_CUSTOM/profiles/low.lua".source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/.dotfiles/user/app/icesl/result/icesl-printers/fff/ARES_RED_CUSTOM/profiles/low.lua";
      "${config.home.homeDirectory}/.icesl/icesl-printers/fff/ARES_RED_CUSTOM/profiles/medium.lua".source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/.dotfiles/user/app/icesl/result/icesl-printers/fff/ARES_RED_CUSTOM/profiles/medium.lua";
      "${config.home.homeDirectory}/.icesl/icesl-printers/fff/ARES_RED_CUSTOM/end.g".source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/.dotfiles/user/app/icesl/result/icesl-printers/fff/ARES_RED_CUSTOM/end.g";
      "${config.home.homeDirectory}/.icesl/icesl-printers/fff/ARES_RED_CUSTOM/start.g".source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/.dotfiles/user/app/icesl/result/icesl-printers/fff/ARES_RED_CUSTOM/start.g";
      "${config.home.homeDirectory}/.icesl/icesl-printers/fff/ARES_RED_CUSTOM/startpre.g".source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/.dotfiles/user/app/icesl/result/icesl-printers/fff/ARES_RED_CUSTOM/startpre.g";
      "${config.home.homeDirectory}/.icesl/icesl-printers/fff/ARES_RED_CUSTOM/swap.g".source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/.dotfiles/user/app/icesl/result/icesl-printers/fff/ARES_RED_CUSTOM/swap.g";
      "${config.home.homeDirectory}/.icesl/icesl-printers/fff/ARES_RED_CUSTOM/swappre.g".source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/.dotfiles/user/app/icesl/result/icesl-printers/fff/ARES_RED_CUSTOM/swappre.g";
      "${config.home.homeDirectory}/.icesl/icesl-printers/fff/ARES_RED_CUSTOM/wait.g".source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/.dotfiles/user/app/icesl/result/icesl-printers/fff/ARES_RED_CUSTOM/wait.g";
      "${config.home.homeDirectory}/.icesl/icesl-printers/fff/ARES_RED_CUSTOM/features.lua".source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/.dotfiles/user/app/icesl/result/icesl-printers/fff/ARES_RED_CUSTOM/features.lua";
      "${config.home.homeDirectory}/.icesl/icesl-printers/fff/ARES_RED_CUSTOM/printer.lua".source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/.dotfiles/user/app/icesl/result/icesl-printers/fff/ARES_RED_CUSTOM/printer.lua";
      "${config.home.homeDirectory}/.icesl/icesl-themes/mymonochrome.icss".source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/.dotfiles/user/app/icesl/result/icesl-themes/mymonochrome.icss";

    };
    #home.file.".icesl/icesl-plugins".source = "${config.home.homeDirectory}/.dotfiles/user/app/icesl/result/icesl-plugins";
    #home.file.".icesl/icesl-printers".source = "${config.home.homeDirectory}/.dotfiles/user/app/icesl/result/icesl-printers";
    #home.file.".icesl/icesl-themes".source = "${config.home.homeDirectory}/.dotfiles/user/app/icesl/result/icesl-themes";

   home.sessionVariables = {
    EDITOR = userSettings.editor;
    SPAWNEDITOR = userSettings.spawnEditor;
    TERM = userSettings.term;
    BROWSER = userSettings.browser;
  };

}
