Skip to content

Add a Nix Flake #2345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Add a Nix Flake #2345

wants to merge 4 commits into from

Conversation

Toby222
Copy link

@Toby222 Toby222 commented Mar 5, 2025

Description of Changes

Create a Nix flake so that SpacetimeDB is to some degree usable via nix :^)
Also formatted the single not-properly-formatted source file in the codebase out of habit (I can remove this if desired)

As-is the binaries it creates are the package names, not sure if that's desired or not.

API and ABI breaking changes

If this is an API or ABI breaking change, please apply the
corresponding GitHub label.

Expected complexity level and risk

How complicated do you think these changes are? Grade on a scale from 1 to 5,
where 1 is a trivial change, and 5 is a deep-reaching and complex change.

2

This complexity rating applies not only to the complexity apparent in the diff,
but also to its interactions with existing and future code.

I did my best to make it as low-maintenance as possible. Unless new binaries get added, or their dependencies change this should keep working indefinitely. And in case that happens I tried to make the changes required as minimal as possible (cf. lines ~105 in flake.nix)

If you answered more than a 2, explain what is complex about the PR,
and what other components it interacts with in potentially concerning ways.

n/A

Testing

Describe any testing you've done, and any testing you'd like your reviewers to do,
so that you're confident that all the changes work as expected!

  • Built and ran the programs in NixOS
  • Make sure the overlay works

Toby222 added 2 commits March 5, 2025 14:40
which for some reason catches this where regular `cargo fmt` misses it
@Toby222 Toby222 marked this pull request as draft March 5, 2025 13:58
@Toby222 Toby222 marked this pull request as ready for review March 5, 2025 14:06
Copy link

@axman6 axman6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got nothing to do with the project, but came here looking for a flake.nix or default.nix, so thought I'd review. Looks good to me, just some minor cleanups.

@PrestonHager
Copy link

PrestonHager commented Mar 6, 2025

I've also used the nix flake, and it worked great! I was able to install it into some local flakes using the following dev shell:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    flake-utils.url = "github:numtide/flake-utils";

    # Spacetime DB flake
    spacetime = {
      url = "github:Toby222/SpacetimeDB";
      #inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  # create a dev shell for each system using flake-utils
  outputs = { self, nixpkgs, flake-utils, spacetime }:
    flake-utils.lib.eachDefaultSystem (system:
    let pkgs = nixpkgs.legacyPackages.${system}; in {
      devShells = {
        default = pkgs.mkShell {
          packages = with pkgs; [
            rustc
            cargo
            llvmPackages.bintools
            # web assembly packages
            binaryen
          ] ++ [
            spacetime.packages.${system}.spacetimedb-cli
          ];
        };
      };
    }
  );
}

I don't love that the binary provided through the flake is spacetimedb-cli instead of the upstream's spacetime binary. A simple alias will fix this, but is it possible to change the flake to provide spacetime as the name instead?

Also, one small suggestion on using "${var}" should be $var instead. I can't find any references in nix documentation, it was a suggestion from the nixpkgs team when I made a pull request awhile ago. It seems like there is not a standard in using variables by themselves in nix strings.

@Toby222
Copy link
Author

Toby222 commented Mar 6, 2025

I don't love that the binary provided through the flake is spacetimedb-cli instead of the upstream's spacetime binary. A simple alias will fix this, but is it possible to change the flake to provide spacetime as the name instead?

Same, definitely fixable, probably best to make an extra derivation that wraps -cli and -standalone? Not quite sure how

Also, one small suggestion on using "${var}" should be $var instead. I can't find any references in nix documentation, it was a suggestion from the nixpkgs team when I made a pull request awhile ago. It seems like there is not a standard in using variables by themselves in nix strings.

Doesn't work with property paths afaict.

@jdetter jdetter added the community Used to mark PRs that were authored by the community (people outside of Clockwork Labs) label Mar 10, 2025
@bfops
Copy link
Collaborator

bfops commented Apr 3, 2025

Thank you for creating this! We'll work on getting it reviewed.

@bfops
Copy link
Collaborator

bfops commented Apr 4, 2025

Hey @Toby222 ! Thanks for opening this. Since this is part of the main SpacetimeDB repo, we ask contributors to sign our Contributor License Agreement (CLA) before we merge their changes.

If you're willing to sign our CLA, could you send an email to cla@clockworklabs.io to get the process started?

@Toby222
Copy link
Author

Toby222 commented Apr 8, 2025

I sent an email 3 days ago, still waiting to hear back

@cloutiertyler
Copy link
Contributor

I sent an email 3 days ago, still waiting to hear back

@Toby222 I flagged it to @tlefky. Should get back to you shortly.

@Toby222
Copy link
Author

Toby222 commented Apr 9, 2025

@Toby222 I flagged it to @tlefky. Should get back to you shortly.
Already done :^)

@bfops
Copy link
Collaborator

bfops commented Apr 23, 2025

Hey @Toby222, sorry for the delay here. After some internal discussion, we're not sure that we're going to be the best maintainers for this flake.

If we create a separate repo like clockworklabs/spacetimedb-nix, would you be willing to be the maintainer for it? 🙂

@Toby222
Copy link
Author

Toby222 commented Apr 23, 2025

I don't think I have the patience for that :p I think best way is to just put the package into nixpkgs and let the community manage it

@PrestonHager
Copy link

I second using nixpkgs repo: https://github.com/NixOS/nixpkgs/. I'll create a PR there later when I have the time to do so. Anyone is free to ping me if they would prefer to pick it up instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Used to mark PRs that were authored by the community (people outside of Clockwork Labs)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants