{
  description = "Configuration for the bob project";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
    devenv.url = "github:cachix/devenv";
    mk-shell-bin.url = "github:rrbutani/nix-mk-shell-bin";
    flake-root.url = "github:srid/flake-root";
    treefmt-nix.url = "github:numtide/treefmt-nix";
    versionsTool.url = "git+https://gitlab.schukai.com/oss/utilities/version.git";
    nix-templates.url = "git+https://gitlab.schukai.com/schukai/entwicklung/nix-flakes.git";
  };

  nixConfig = {
    extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=";
    extra-substituters = "https://devenv.cachix.org";
  };

  outputs = inputs @ {
    self,
    flake-parts,
    versionsTool,
    nix-templates,
    ...
  }:
    flake-parts.lib.mkFlake {inherit inputs;} {
      imports = [
        inputs.devenv.flakeModule
        inputs.flake-root.flakeModule
        inputs.treefmt-nix.flakeModule
      ];

      systems = (import ./project.nix).supportedSystems;

      perSystem = let
        common-script = import ./system/scripts/common.nix;
      in
        {
          config,
          self',
          inputs',
          pkgs,
          system,
          ...
        }: let
          projectDefinition = import ./project.nix;
          buildRoot = ./.;

          enableDebugPackage = true;

          portAsString = toString projectDefinition.k8s.port;
        in {
          packages = rec {
            default = self.packages.${system}.bob;

            bob = let
              projectDefinition = import ./project.nix;
              sourcePath = ./source;

              timestamp = with (import <nixpkgs> {});
                builtins.readFile (
                  runCommand "timestamp"
                  {when = builtins.currentTime;}
                  "echo -n `date -d @$when +%Y-%m-%d_%H-%M-%S` > $out"
                );
            in
              # https://nixos.wiki/wiki/Go
              pkgs.buildGoModule {
                pname = projectDefinition.name;
                version = projectDefinition.version;

                src = sourcePath;

                tags = []; # add your tags here (eq  "netgo" "osusergo" "static_build")

                # The -w turns off DWARF debugging information:
                # The -s flag will omit the symbol table and debug information.
                ldflags = [
                  "-s -w"
                  "-X '${projectDefinition.modulePath}/release.version=${projectDefinition.version}'"
                  "-X '${projectDefinition.modulePath}/release.commit=${projectDefinition.commitHash}'"
                  "-X '${projectDefinition.modulePath}/release.name=${projectDefinition.name}'"
                  "-X '${projectDefinition.modulePath}/release.mnemonic=${projectDefinition.mnemonic}'"
                  "-X '${projectDefinition.modulePath}/release.buildDate=${timestamp}'"
                ];

                #vendorHash = null;
                vendorHash = projectDefinition.vendorHash;
                #vendorHash = system.lib.fakeHash;
                proxyVendor = true;

                meta = with system.lib; {
                  description = projectDefinition.description;
                  homepage = "https://" + projectDefinition.modulePath;
                  maintainers = with maintainers; ["schukai GmbH"];
                };

                buildInputs = [pkgs.bash];
                nativeBuildInputs = with system; [pkgs.alejandra pkgs.shellcheck pkgs.shfmt];

                doCheck = true;

                checkPhase = ''
                  cd ${sourcePath}
                  if ! go test -v ./... 2>&1 | cat ; then
                    echo "Test failed."
                    exit 1
                  fi

                  echo "Test passed: '$out' is as expected."
                '';
              };
          };

          treefmt.config = {
            inherit (config.flake-root) projectRootFile;
            programs.alejandra.enable = true;
            programs.gofmt.enable = true;
            programs.shfmt.enable = true;
            programs.shellcheck.enable = true;
            programs.yamlfmt.enable = true;
            programs.prettier.enable = true;
          };

          devenv.shells = let
            projectDefinition = import ./project.nix;
            buildRoot = ./.;
          in {
            default = rec {
              name = projectDefinition.name;

              scripts = let
                versionsTool = inputs.versionsTool.defaultPackage."${builtins.currentSystem}";

                workingDirectory = builtins.getEnv "PWD";
              in {
                treefmt.exec = ''
                  ${config.treefmt.build.wrapper}/bin/treefmt
                '';

                rm-gitlab-pipelines.exec = import ./system/scripts/rm-gitlab-pipelines.nix {
                  inherit pkgs config buildRoot projectDefinition;
                };

                update-files.exec = import ./system/scripts/update-files.nix {
                  inherit pkgs config buildRoot projectDefinition;
                };

                check-licences.exec = import ./system/scripts/check-licences.nix {
                  inherit pkgs config buildRoot projectDefinition;
                };

                update-hashes.exec = import ./system/scripts/update-hashes.nix {
                  inherit pkgs config buildRoot projectDefinition workingDirectory;
                };

                update-version.exec = import ./system/scripts/update-version.nix {
                  inherit pkgs config buildRoot projectDefinition versionsTool workingDirectory;
                };
              };

              imports = [];

              packages = with pkgs; [
                inputs.versionsTool.defaultPackage."${builtins.currentSystem}"
                inputs.nix-templates.packages."${builtins.currentSystem}".git-commit
                nodePackages.prettier-plugin-toml
                nodePackages.prettier
                go-task
                alejandra
              ];

              languages.nix.enable = true;
              languages = {go = {enable = true;};};

              difftastic.enable = true;

              enterShell = ''
                post-init-setup
              '';
            };
          };
        };

      flake = {
        defaultPackage = self.packages.${builtins.currentSystem}.bob;
      };
    };
}