# Generate lock file:
#   nix run github:jlesquembre/clj-nix#deps-lock

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
    clj-nix.url = "github:jlesquembre/clj-nix";
  };

  outputs = { self, nixpkgs, flake-utils, clj-nix }:
    flake-utils.lib.eachDefaultSystem (system:
      let pkgs = import nixpkgs {
            inherit system;
            overlays = [
              # devshell.overlays.default
              clj-nix.overlays.default
            ];
          };

          sydnix-cli-unwrapped = clj-nix.lib.mkCljApp {
            pkgs = nixpkgs.legacyPackages.${system};
            modules = [
              {
                name = "msyds/sydnix-cli";
                version = "1.0.0";
                main-ns = "sydnix-cli.main";
                projectSrc = ./.;

                nativeImage = {
                  # Disable for faster build times.
                  enable = true;
                };
              }
            ];
          };
      in {
        packages.default = pkgs.symlinkJoin {
          name = "sydnix-cli";
          version = "1.0.0";
          paths = [ sydnix-cli-unwrapped ];
          nativeBuildInputs = [ pkgs.makeWrapper ];
          postBuild = ''
            # The name `sydnix-cli` seems to be automatically chosen by clj-nix.
            # Not a fan!
            mv $out/bin/sydnix-cli $out/bin/sydnix
            wrapProgram $out/bin/sydnix \
              --prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.asciidoctor ]}
          '';
        };

        devShells.default = pkgs.mkShell {
          inputsFrom = [
            # FIXME: clj-nix causes some `fake-git` tool to come into scope,
            # which shadows the actual git.
            # self.packages.${system}.default
          ];

          packages = with pkgs; [
            clojure-lsp
            clojure
            babashka
            asciidoctor
          ];
        };
      });
}
