From f06bd002115d1d5338f49b0601b0b33c954cc82e Mon Sep 17 00:00:00 2001 From: Tobias Berger Date: Fri, 3 May 2024 20:16:19 +0200 Subject: [PATCH] Initial commit --- .gitignore | 1 + flake.lock | 48 +++++++++++++++++++++++++++++++++++ flake.nix | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++ treefmt.nix | 8 ++++++ 4 files changed, 130 insertions(+) create mode 100644 .gitignore create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 treefmt.nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b2be92b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..46c72f1 --- /dev/null +++ b/flake.lock @@ -0,0 +1,48 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1714635257, + "narHash": "sha256-4cPymbty65RvF1DWQfc+Bc8B233A1BWxJnNULJKQ1EY=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "63c3a29ca82437c87573e4c6919b09a24ea61b0f", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "treefmt-nix": "treefmt-nix" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1714058656, + "narHash": "sha256-Qv4RBm4LKuO4fNOfx9wl40W2rBbv5u5m+whxRYUMiaA=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "c6aaf729f34a36c445618580a9f95a48f5e4e03f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..bb9b39b --- /dev/null +++ b/flake.nix @@ -0,0 +1,73 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + + treefmt-nix = { + url = "github:numtide/treefmt-nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = + { + self, + nixpkgs, + treefmt-nix, + }: + let + supportedSystems = [ + "x86_64-linux" + "aarch64-linux" + ]; + forEachSupportedSystem = + f: nixpkgs.lib.genAttrs supportedSystems (system: f { pkgs = import nixpkgs { inherit system; }; }); + in + { + formatter = forEachSupportedSystem ( + { pkgs }: (treefmt-nix.lib.evalModule pkgs ./treefmt.nix).config.build.wrapper + ); + packages = forEachSupportedSystem ( + { pkgs }: + let + system-map = { + "x86_64-linux" = "amd64"; + "aarch64-linux" = "arm64"; + }; + system = system-map.${pkgs.system}; + hash-map = { + "x86_64-linux" = "sha256-kDZYBSElpNkKxx4VXNa7d3WIv4EU8jgbWh731wChueQ="; + "aarch64-linux" = "sha256-kDZYBSElpNkKxx4VXNa7d3WIv4EU8jgbWh731wChueQ="; + }; + hash = hash-map.${pkgs.system}; + in + { + default = pkgs.stdenv.mkDerivation rec { + pname = "spacetime-bin"; + version = "v0.9.0-beta"; + src = pkgs.fetchzip { + url = "https://github.com/clockworklabs/SpacetimeDB/releases/download/${version}/spacetime.linux-${system}.tar.gz"; + inherit hash; + }; + buildPhase = '' + ls -la + patchelf \ + --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \ + --set-rpath ${pkgs.stdenv.cc.cc.lib}/lib64 \ + ./spacetime + mkdir -p $out/bin + cp spacetime $out/bin/spacetime + ''; + }; + } + ); + devShells = forEachSupportedSystem ( + { pkgs }: + { + default = pkgs.mkShell { + nativeBuildInputs = [ ]; + buildInputs = [ ]; + }; + } + ); + }; +} diff --git a/treefmt.nix b/treefmt.nix new file mode 100644 index 0000000..a54f850 --- /dev/null +++ b/treefmt.nix @@ -0,0 +1,8 @@ +{ ... }: +{ + projectRootFile = "flake.nix"; + programs = { + nixfmt-rfc-style.enable = true; + rustfmt.enable = true; + }; +}