Skip to content
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

Add a Nix Flake #2345

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants