{
  inputs = {
    src = {
      url = "github:MTeaHead/niri-session-manager";
      flake = false;
    };
  };

  outputs =
    {
      nixpkgs,
      src,
      self,
    }:
    {
      packages.x86_64-linux.default = nixpkgs.legacyPackages.x86_64-linux.rustPlatform.callPackage (
        { pkgs, buildRustPackage }:
        buildRustPackage (finalAttrs: {
          pname = "niri-session-manager";
          version = "git-${src.rev or src.dirtyRev or "dirty"}";
          inherit src;

          cargoLock = {
            lockFile = "${src}/Cargo.lock";
          };

          meta.mainProgram = "niri-session-manager";
        })
      ) { };

      nixosModules.niri-session-manager =
        {
          config,
          lib,
          pkgs,
          ...
        }:
        {
          options = {
            services.niri-session-manager = {
              enable = lib.mkEnableOption "Niri Session Manager";
            };
          };
          config =
            let
              cfg = config.services.niri-session-manager;
            in
            lib.mkIf cfg.enable {
              systemd.user.services.niri-session-manager = {
                enable = true;
                description = "Niri Session Manager";
                wantedBy = [ "graphical-session.target" ];
                partOf = [ "graphical-session.target" ];
                wants = [ "graphical-session.target" ];
                after = [ "graphical-session.target" ];
                serviceConfig = {
                  Type = "simple";
                  Restart = "always";
                  ExecStart = "${self.packages.${pkgs.system}.default}";
                  PrivateTmp = true;
                };
              };
            };
        };
    };
}
