{
  pkgs,
  lib,
  fetchurl,
  hostname,
  headless,
  ...
}: let
  idea = with pkgs;
    symlinkJoin {
      name = "idea-ultimate";
      paths = [
        jetbrains.idea-ultimate
      ];
      buildInputs = [makeWrapper];
      postBuild = ''
        wrapProgram $out/bin/idea-ultimate --prefix PATH : ${symlinkJoin {
          name = "rust-toolchain";
          paths = [rustc cargo rustfmt];
        }}/bin
      '';
    };

  cliPackages = with pkgs; [
    age
    direnv
    elixir_1_15
    elixir-ls
    entr
    erlang_26
    gnumake
    go
    gopls
    minisign
    nb
    nodejs
    oh-my-zsh
    (
      let
        my-python-packages = python-packages:
          with python-packages; [
            tkinter
            requests
          ];
        python-with-my-packages = python3.withPackages my-python-packages;
      in
        python-with-my-packages
    )
    restic
    rust-analyzer
    unzip
    zip
  ];

  guiPackages = with pkgs; [
    _1password
    _1password-gui
    discord
    feh
    fraunces
    grim
    iosevka
    idea
    inkscape
    # jellyfin-mpv-shim
    mpv
    obsidian
    pamixer
    pavucontrol
    playerctl
    slurp
    spotify
    swaylock
    udiskie
    wl-clipboard
    xclip
    zathura
  ];

  defaultUser = "daniel";
in {
  imports =
    [
      ../configs/system
    ]
    ++ lib.optionals (!headless) [
      ../configs/desktop
    ]
    ++ lib.optionals (builtins.pathExists ./host-specific/${hostname}) [
      ./host-specific/${hostname}
    ];

  home = {
    username = defaultUser;
    homeDirectory = "/home/${defaultUser}";
    sessionPath = [
      "$HOME/go/bin"
    ];

    file = {
      ".icons/default".source = "${pkgs.capitaine-cursors}/share/icons/capitaine-cursors";

      ".rust".source = pkgs.rustPlatform.rustcSrc;

      "bin/update" = {
        source = ../../scripts/update;
        executable = true;
      };

      "bin/supdate" = {
        source = ../../scripts/supdate;
        executable = true;
      };
    };

    packages = cliPackages ++ lib.optionals (!headless) guiPackages;

    keyboard = {
      layout = "gb";
      options = [
        "caps:escape"
      ];
    };

    stateVersion = "21.05";
  };

  programs = {
    # Let Home Manager install and manage itself.
    home-manager.enable = true;

    fzf = {
      enable = true;
      enableZshIntegration = true;
    };

    git = {
      enable = true;
      package = pkgs.gitFull;
      userName = "Daniel Patterson";
      userEmail = "me@danielpatterson.dev";
      extraConfig = {
        pull.rebase = true;
        init.defaultBranch = "main";
        format.signOff = "yes";
        sendemail = {
          smtpUser = "me@danielpatterson.dev";
          smtpServer = "smtp.fastmail.com";
          smtpEncryption = "tls";
          smtpServerPort = 587;
        };
      };
    };

    lazygit = {
      enable = true;
      settings = {
        gui.theme = {
          selectedLineBgColor = ["reverse"];
          selectedRangeBgColor = ["reverse"];
        };
      };
    };

    starship.enable = true;

    vscode.enable = true;

    zsh = {
      enable = true;
      enableAutosuggestions = true;
      initExtra = ''
        eval "$(direnv hook zsh)"
      '';
      oh-my-zsh = {
        enable = true;
        plugins = ["git" "fzf"];
        theme = "agnoster";
      };
    };
  };
}
