{
  description = "JEM's macOS config powered by NixOS Flakes and nix-darwin";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    nix-darwin.url = "github:LnL7/nix-darwin";
    nix-darwin.inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = inputs@{ self, nix-darwin, nixpkgs }:
  let
    configuration = { pkgs, ... }: {
      # List packages installed in system profile. To search by name, run:
      # $ nix-env -qaP | grep wget
      environment.systemPackages =
        [
            # pkgs.latexindent
            # pkgs.bash
            pkgs.cacert
            pkgs.curl
            pkgs.emacs
            pkgs.fish
            pkgs.gawk
            pkgs.git
            pkgs.htop
            # pkgs.julia
            pkgs.nano
            pkgs.pueue
            pkgs.ruby_3_3
            pkgs.xz
        ];

      # Auto upgrade nix package and the daemon service.
      services.nix-daemon.enable = true;
      # nix.package = pkgs.nix;

      # Necessary for using flakes on this system.
      nix.settings.experimental-features = "nix-command flakes";

      # Create /etc/zshrc that loads the nix-darwin environment.
      # programs.zsh.enable = true;  # default shell on catalina
      programs.fish.enable = true;

      # Set Git commit hash for darwin-version.
      system.configurationRevision = self.rev or self.dirtyRev or null;

      # Used for backwards compatibility, please read the changelog before changing.
      # $ darwin-rebuild changelog
      system.stateVersion = 4;

      # The platform the configuration will be used on.
      nixpkgs.hostPlatform = "aarch64-darwin";

      # My configs
      users.users.yonkeltron = {
        packages = with pkgs; [
          atuin
          autoconf
          automake
          awscli
          bash
          bat
          bison
          bmon
          bottom
          broot
          brotli
          bupstash
          cairo
          capnproto
          capstone
          cheat
          cjson
          clang
          cmake
          coreutils
          darwin.apple_sdk.frameworks.CoreServices
          darwin.apple_sdk.frameworks.Foundation
          darwin.Libnotify
          deno
          dockfmt
          dog
          dtc
          du-dust
          earthly
          elixir
          erlang
          eza
          fd
          ffmpeg
          figlet
          flac
          flex
          fontconfig
          freetype
          fribidi
          gawk
          gitui
          gnupg
          gnutls
          gpgme
          guile
          harfbuzz
          hwloc
          imagemagick
          imath
          isl
          jansson
          jasper
          just
          lame
          leptonica
          less
          libarchive
          libass
          libassuan
          libb2
          libbluray
          libde265
          libepoxy
          libevent
          libgcrypt
          libgee
          libgit2
          libgpg-error
          libheif
          libidn
          libidn2
          libksba
          liblinear
          libmicrohttpd
          libmpc
          libnghttp2
          libogg
          libpng
          libpsl
          libraw
          librist
          librsvg
          libsamplerate
          libshout
          libslirp
          libsndfile
          libsodium
          libsoup
          libssh
          libssh2
          libsixel
          libtasn1
          libtiff
          libtool
          libusb
          libvorbis
          libvpx
          libxml2
          libyaml
          llvmPackages_latest.lld
          llvmPackages_latest.llvm
          lua
          lz4
          lzo
          m4
          magic-wormhole
          mbedtls
          metis
          mosh
          mpg123
          ncurses
          netcat
          nettle
          nixfmt
          nmap
          nodejs
          npth
          nspr
          nss
          nushell
          oniguruma
          openblas
          opencore-amr
          openexr
          openjdk
          openjpeg
          openldap
          openlibm
          openssl
          openssl.dev
          pandoc
          pango
          pcre
          pcre2
          pijul
          pinentry
          pixman
          pkg-config
          poppler
          procs
          protobuf
          pugixml
          pv
          python311Full
          qrencode
          R
          rage
          rclone
          readline
          riff
          ripgrep
          rustup
          sbcl
          scc
          sd
          SDL2
          SDL2.dev
          shared-mime-info
          shellcheck
          shfmt
          skim
          snappy
          speex
          srt
          srtp
          ssh-copy-id
          starship
          svt-av1
          swig
          taglib
          tbb
          terminal-notifier
          tesseract
          texinfo
          tokei
          topgrade
          tree
          tree-sitter
          typst
          unbound
          watch
          x264
          x265
          xml2
          xz
          youtube-dl
          z3
          zeromq
          zimg
          zoxide
          zstd
        ];
        shell = pkgs.fish;
      };

      homebrew = {
        enable = true;
        onActivation.cleanup = "zap";
        taps = [
          "homebrew/cask-fonts"
          "homebrew/bundle"
          "railwaycat/emacsmacport"
          "rusty-ferris-club/tap"
        ];
        brews = [
          "docuum"
          "faac"
          "gnu-tar"
          "gnu-time"
          "juliaup"
          "keyring"
          "latexindent"
          "libcuefile"
          "opus"
          "pdfpc"
          "theora"
          "webp"
          "whalebrew"
        ];
        casks = [
          "alfred"
          "alloy"
          "audacity"
          "bambu-studio"
          "calibre"
          "chromium"
          "cyberduck"
          "daisydisk"
          "dash"
          "docker"
          "dropbox"
          "duckduckgo"
          "element"
          "firefox"
          "font-comic-neue"
          "font-fira-code"
          "font-fira-mono"
          "font-fira-sans"
          "font-gochi-hand"
          "font-roboto-mono-nerd-font"
          "google-chrome"
          "handbrake"
          "inkscape"
          "iterm2"
          "keka"
          "keycastr"
          "mactex-no-gui"
          "microsoft-auto-update"
          "microsoft-teams"
          "minecraft"
          "mixxx"
          "monodraw"
          "pika"
          "postgres-unofficial"
          "racket"
          "remarkable"
          "sabaki"
          "scribus"
          "send-to-kindle"
          "signal"
          "slack"
          "spotify"
          "starcraft"
          "stats"
          "stremio"
          "syncthing"
          "transmission"
          "twine"
          "visual-studio-code"
          "vlc"
          "webtorrent"
          "whatsapp"
          "windscribe"
          "zoom"
        ];
      };

      launchd.user.agents = {
        pueued = {
          serviceConfig = {
            Label = "pueued";
            ProgramArguments = [
              "/run/current-system/sw/bin/pueued"
              "-vv"
            ];
            UserName = "yonkeltron";
            GroupName = "yonkeltron";
            RunAtLoad = true;

            StandardOutPath = "/tmp/pueued.log";
            StandardErrorPath = "/tmp/pueued.error.log";
          };
        };
      };

      #
      security.pam.enableSudoTouchIdAuth = true;
      system.defaults = {
        dock.autohide = false;
        dock.mru-spaces = false;
        finder.FXPreferredViewStyle = "iconv";
        loginwindow.GuestEnabled = false;
        menuExtraClock.ShowAMPM = true;
        menuExtraClock.ShowDate = 1;
        screensaver.askForPassword = true;
        screensaver.askForPasswordDelay = 20;
      };
      system.keyboard.enableKeyMapping = true;
      system.keyboard.remapCapsLockToControl = true;
      time.timeZone = "America/New_York";
    };
  in
  {
    # Build darwin flake using:
    # $ darwin-rebuild build --flake .#simple
    darwinConfigurations."Qafih" = nix-darwin.lib.darwinSystem {
      modules = [ configuration ];
    };

    # Expose the package set, including overlays, for convenience.
    darwinPackages = self.darwinConfigurations."Qafih".pkgs;
  };
}