{
  description = "A very basic flake";

  inputs = {
    flake-utils.url = "github:numtide/flake-utils";
    devenv.url = "github:cachix/devenv";
  };

  outputs = {
    self,
    nixpkgs,
    flake-utils,
    devenv,
  } @ inputs:
    flake-utils.lib.eachDefaultSystem (
      system: let
        pkgs = import nixpkgs {
          inherit system;
        };

        lib = pkgs.lib;

        beamPackages = pkgs.beam.packagesWith pkgs.beam.interpreters.erlang_26;

        erlang = beamPackages.erlang;

        elixir = beamPackages.elixir_1_15;

        elixir-ls = beamPackages.elixir-ls.override {elixir = elixir;};

        hex = beamPackages.hex;

        rebar3 = beamPackages.rebar3;
        rebar = beamPackages.rebar;
      in {
        devShells.default = devenv.lib.mkShell {
          inherit inputs pkgs;
          modules = [
            {
              packages = [
                elixir
                elixir-ls
                erlang
                hex
                rebar
                rebar3
                pkgs.flyctl
                pkgs.inotify-tools
                pkgs.sqlite
              ];
            }
          ];
        };

        packages.default = beamPackages.mixRelease rec {
          pname = "wish";
          version = "nightly-231124";

          src = ./.;

          postUnpack = ''
            export ELIXIR_MAKE_CACHE_DIR=$TMP
          '';

          mixFodDeps = beamPackages.fetchMixDeps {
            inherit src version;
            pname = "mix-deps-${pname}";
            hash = "sha256-W/peopoh52iM3K068eu5gQ9dsKJTIVZ+5M6lZjP+vcE=";
          };
        };

        nixosModules.default = {
          config,
          lib,
          pkgs,
          ...
        }:
          with lib; let
            cfg = config.wish.service;
          in {
            options.wish.service = {
              enable = mkEnableOption "Enable the wish service.";

              stateDir = mkOption {
                type = types.str;
                default = "/var/lib/wish";
                description = lib.mdDoc "Wish data directory.";
              };

              environmentFile = mkOption {
                type = types.path;
                description = lib.mdDoc ''
                  Environment file as defined in {manpage}`systemd.exec(5)` passed to the service.
                '';
              };

              databasePath = mkOption {
                type = types.str;
                default = "${cfg.stateDir}/data/wish.db";
                description = lib.mdDoc "Path to the sqlite3 database file.";
              };

              secretKeyBase = mkOption {
                type = types.str;
                description = lib.mdDoc "Phoenix secret key base.";
              };
            };

            config = mkIf cfg.enable {
              systemd.services."wish" = {
                wantedBy = ["multi-user.target"];

                serviceConfig = let
                  pkg = self.packages.${system}.default;
                in {
                  EnvironmentFile = cfg.environmentFile;
                  Restart = "on-failure";
                  ExecStart = "${pkg}/bin/wish start";
                };

                environment = {
                  DATABASE_PATH = cfg.databasePath;
                  SECRET_KEY_BASE = cfg.secretKeyBase;
                };
              };
            };
          };
      }
    );
}
