Add a Nix Flake
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!
- [x] Built and ran the programs in NixOS
- [x] Make sure the overlay works
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.
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$varinstead. 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.
Thank you for creating this! We'll work on getting it reviewed.
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 [email protected] to get the process started?
I sent an email 3 days ago, still waiting to hear back
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 I flagged it to @tlefky. Should get back to you shortly. Already done :^)
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? 🙂
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
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.
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.
@Toby222 We added a new CLA manager that might be easier for you. Let us know if you have issues.
It sounds like the plan is to open a PR directly to nixpkgs rather than mirroring in this repo, so we'll close this PR. Feel free to reopen if that's wrong.