Compare commits
8 Commits
a8b0e01f88
...
2919906843
Author | SHA1 | Date | |
---|---|---|---|
2919906843 | |||
a34cec60d4 | |||
e46bcfda3f | |||
f6b1f1fc23 | |||
7008e1653b | |||
bd09a1ad7b | |||
b84a60ba69 | |||
25f55cf24d |
@ -1,3 +0,0 @@
|
|||||||
[target.x86_64-unknown-linux-gnu]
|
|
||||||
linker = "clang"
|
|
||||||
rustflags = ["-C", "link-arg=-fuse-ld=mold"]
|
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -4,3 +4,5 @@
|
|||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
*.swp
|
*.swp
|
||||||
/.direnv
|
/.direnv
|
||||||
|
/.cargo
|
||||||
|
/result
|
||||||
|
15
Cargo.lock
generated
15
Cargo.lock
generated
@ -1271,7 +1271,6 @@ dependencies = [
|
|||||||
"http-range",
|
"http-range",
|
||||||
"httpdate",
|
"httpdate",
|
||||||
"hyper",
|
"hyper",
|
||||||
"hyperlocal",
|
|
||||||
"idna",
|
"idna",
|
||||||
"md-5",
|
"md-5",
|
||||||
"multer",
|
"multer",
|
||||||
@ -1465,7 +1464,6 @@ dependencies = [
|
|||||||
"garage_util",
|
"garage_util",
|
||||||
"http",
|
"http",
|
||||||
"hyper",
|
"hyper",
|
||||||
"hyperlocal",
|
|
||||||
"opentelemetry",
|
"opentelemetry",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"tokio",
|
"tokio",
|
||||||
@ -1778,19 +1776,6 @@ dependencies = [
|
|||||||
"tokio-io-timeout",
|
"tokio-io-timeout",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hyperlocal"
|
|
||||||
version = "0.8.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0fafdf7b2b2de7c9784f76e02c0935e65a8117ec3b768644379983ab333ac98c"
|
|
||||||
dependencies = [
|
|
||||||
"futures-util",
|
|
||||||
"hex",
|
|
||||||
"hyper",
|
|
||||||
"pin-project",
|
|
||||||
"tokio",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iana-time-zone"
|
name = "iana-time-zone"
|
||||||
version = "0.1.57"
|
version = "0.1.57"
|
||||||
|
208
default.nix
208
default.nix
@ -1,56 +1,166 @@
|
|||||||
{ system ? builtins.currentSystem, git_version ? null, }:
|
{
|
||||||
|
buildSystem ? builtins.currentSystem,
|
||||||
with import ./nix/common.nix;
|
targetSystem ? buildSystem,
|
||||||
|
gitVersion ? null,
|
||||||
|
release ? false,
|
||||||
|
features ? null,
|
||||||
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
pkgs = import pkgsSrc { };
|
pkgsSrc = import ./nix/pkgs.nix;
|
||||||
compile = import ./nix/compile.nix;
|
newBuildTarget = {
|
||||||
|
nixPkgsSystem,
|
||||||
build_debug_and_release = (target: {
|
rustTarget ? nixPkgsSystem,
|
||||||
debug = (compile {
|
nativeBuildInputs ? pkgsCross: [],
|
||||||
inherit system target git_version pkgsSrc cargo2nixOverlay;
|
rustFlags ? pkgsCross: [],
|
||||||
release = false;
|
}: {
|
||||||
}).workspace.garage { compileMode = "build"; };
|
inherit nixPkgsSystem rustTarget nativeBuildInputs rustFlags;
|
||||||
|
|
||||||
release = (compile {
|
|
||||||
inherit system target git_version pkgsSrc cargo2nixOverlay;
|
|
||||||
release = true;
|
|
||||||
}).workspace.garage { compileMode = "build"; };
|
|
||||||
});
|
|
||||||
|
|
||||||
test = (rustPkgs:
|
|
||||||
pkgs.symlinkJoin {
|
|
||||||
name = "garage-tests";
|
|
||||||
paths =
|
|
||||||
builtins.map (key: rustPkgs.workspace.${key} { compileMode = "test"; })
|
|
||||||
(builtins.attrNames rustPkgs.workspace);
|
|
||||||
});
|
|
||||||
|
|
||||||
in {
|
|
||||||
pkgs = {
|
|
||||||
amd64 = build_debug_and_release "x86_64-unknown-linux-musl";
|
|
||||||
i386 = build_debug_and_release "i686-unknown-linux-musl";
|
|
||||||
arm64 = build_debug_and_release "aarch64-unknown-linux-musl";
|
|
||||||
arm = build_debug_and_release "armv6l-unknown-linux-musleabihf";
|
|
||||||
};
|
};
|
||||||
test = {
|
|
||||||
amd64 = test (compile {
|
# centralize per-target configuration in a single place.
|
||||||
inherit system git_version pkgsSrc cargo2nixOverlay;
|
buildTargets = {
|
||||||
target = "x86_64-unknown-linux-musl";
|
"x86_64-linux" = newBuildTarget {
|
||||||
features = [
|
nixPkgsSystem = "x86_64-unknown-linux-musl";
|
||||||
"garage/bundled-libs"
|
};
|
||||||
"garage/k2v"
|
|
||||||
"garage/sled"
|
"i686-linux" = newBuildTarget {
|
||||||
"garage/lmdb"
|
nixPkgsSystem = "i686-unknown-linux-musl";
|
||||||
"garage/sqlite"
|
};
|
||||||
|
|
||||||
|
"aarch64-linux" = newBuildTarget {
|
||||||
|
nixPkgsSystem = "aarch64-unknown-linux-musl";
|
||||||
|
};
|
||||||
|
|
||||||
|
# Old Raspberry Pi's (not currently supported due to linking errors with
|
||||||
|
# libsqlite3 and libsodium
|
||||||
|
#"armv6l-linux" = newBuildTarget {
|
||||||
|
# nixPkgsSystem = "armv6l-unknown-linux-musleabihf";
|
||||||
|
# rustTarget = "arm-unknown-linux-musleabihf";
|
||||||
|
#};
|
||||||
|
|
||||||
|
"x86_64-windows" = newBuildTarget {
|
||||||
|
nixPkgsSystem = "x86_64-w64-mingw32";
|
||||||
|
rustTarget = "x86_64-pc-windows-gnu";
|
||||||
|
nativeBuildInputs = pkgsCross: [ pkgsCross.windows.pthreads ];
|
||||||
|
rustFlags = pkgsCross: [
|
||||||
|
"-C" "link-arg=-L${pkgsCross.windows.pthreads}/lib"
|
||||||
];
|
];
|
||||||
});
|
|
||||||
};
|
};
|
||||||
clippy = {
|
|
||||||
amd64 = (compile {
|
|
||||||
inherit system git_version pkgsSrc cargo2nixOverlay;
|
|
||||||
target = "x86_64-unknown-linux-musl";
|
|
||||||
compiler = "clippy";
|
|
||||||
}).workspace.garage { compileMode = "build"; };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
buildTarget = buildTargets.${targetSystem};
|
||||||
|
|
||||||
|
pkgs = import pkgsSrc { system = buildSystem; };
|
||||||
|
pkgsCross = import pkgsSrc {
|
||||||
|
system = buildSystem;
|
||||||
|
crossSystem.config = buildTarget.nixPkgsSystem;
|
||||||
|
};
|
||||||
|
|
||||||
|
rustTarget = buildTarget.rustTarget;
|
||||||
|
|
||||||
|
toolchain = let
|
||||||
|
fenix = import (pkgs.fetchFromGitHub {
|
||||||
|
owner = "nix-community";
|
||||||
|
repo = "fenix";
|
||||||
|
rev = "81ab0b4f7ae9ebb57daa0edf119c4891806e4d3a";
|
||||||
|
hash = "sha256-bZmI7ytPAYLpyFNgj5xirDkKuAniOkj1xHdv5aIJ5GM=";
|
||||||
|
}) {
|
||||||
|
system = buildSystem;
|
||||||
|
};
|
||||||
|
|
||||||
|
mkToolchain = fenixTarget: fenixTarget.toolchainOf {
|
||||||
|
channel = "1.68.2";
|
||||||
|
sha256 = "sha256-4vetmUhTUsew5FODnjlnQYInzyLNyDwocGa4IvMk3DM=";
|
||||||
|
};
|
||||||
|
in
|
||||||
|
fenix.combine [
|
||||||
|
(mkToolchain fenix).rustc
|
||||||
|
(mkToolchain fenix).rustfmt
|
||||||
|
(mkToolchain fenix).cargo
|
||||||
|
(mkToolchain fenix).clippy
|
||||||
|
(mkToolchain fenix.targets.${rustTarget}).rust-std
|
||||||
|
];
|
||||||
|
|
||||||
|
naersk = let
|
||||||
|
naerskSrc = pkgs.fetchFromGitHub {
|
||||||
|
owner = "nix-community";
|
||||||
|
repo = "naersk";
|
||||||
|
rev = "d9a33d69a9c421d64c8d925428864e93be895dcc";
|
||||||
|
hash = "sha256-e136hTT7LqQ2QjOTZQMW+jnsevWwBpMj78u6FRUsH9I=";
|
||||||
|
};
|
||||||
|
in
|
||||||
|
pkgs.callPackages naerskSrc {
|
||||||
|
cargo = toolchain;
|
||||||
|
rustc = toolchain;
|
||||||
|
};
|
||||||
|
|
||||||
|
builtFeatures = if features != null then
|
||||||
|
features
|
||||||
|
else (
|
||||||
|
[ "garage/bundled-libs" "garage/sled" "garage/lmdb" "garage/k2v" ] ++ (
|
||||||
|
if release then [
|
||||||
|
"garage/consul-discovery"
|
||||||
|
"garage/kubernetes-discovery"
|
||||||
|
"garage/metrics"
|
||||||
|
"garage/telemetry-otlp"
|
||||||
|
"garage/sqlite"
|
||||||
|
] else [ ]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
# For some reason the pkgsCross.pkgsStatic build of libsodium doesn't contain
|
||||||
|
# a `.a` file when compiled to a windows target, but rather contains
|
||||||
|
# a `.dll.a` file which libsodium-sys doesn't pick up on. Copying the one to
|
||||||
|
# the be the other seems to work.
|
||||||
|
libsodium = pkgs.runCommand "libsodium-wrapped" {
|
||||||
|
libsodium = pkgsCross.pkgsStatic.libsodium;
|
||||||
|
} ''
|
||||||
|
cp -rL "$libsodium" "$out"
|
||||||
|
chmod -R +w "$out"
|
||||||
|
if [ ! -e "$out"/lib/libsodium.a ] && [ -f "$out"/lib/libsodium.dll.a ]; then
|
||||||
|
cp "$out"/lib/libsodium.dll.a "$out"/lib/libsodium.a
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
|
||||||
|
in rec {
|
||||||
|
inherit pkgs pkgsCross;
|
||||||
|
|
||||||
|
# Exported separately so it can be used from shell.nix
|
||||||
|
buildEnv = rec {
|
||||||
|
nativeBuildInputs = (buildTarget.nativeBuildInputs pkgsCross) ++ [
|
||||||
|
toolchain
|
||||||
|
pkgs.protobuf
|
||||||
|
|
||||||
|
# Required for shell because of rust dependency build scripts which must
|
||||||
|
# run on the build system.
|
||||||
|
pkgs.stdenv.cc
|
||||||
|
];
|
||||||
|
|
||||||
|
SODIUM_LIB_DIR = "${libsodium}/lib";
|
||||||
|
|
||||||
|
# Required because ring crate is special. This also seems to have
|
||||||
|
# fixed some issues with the x86_64-windows cross-compile :shrug:
|
||||||
|
TARGET_CC = "${pkgsCross.stdenv.cc}/bin/${pkgsCross.stdenv.cc.targetPrefix}cc";
|
||||||
|
|
||||||
|
CARGO_BUILD_TARGET = rustTarget;
|
||||||
|
CARGO_BUILD_RUSTFLAGS = [
|
||||||
|
"-C" "target-feature=+crt-static"
|
||||||
|
"-C" "link-arg=-static"
|
||||||
|
|
||||||
|
# https://github.com/rust-lang/cargo/issues/4133
|
||||||
|
"-C" "linker=${TARGET_CC}"
|
||||||
|
] ++ (buildTarget.rustFlags pkgsCross);
|
||||||
|
};
|
||||||
|
|
||||||
|
build = naersk.buildPackage (rec {
|
||||||
|
inherit release;
|
||||||
|
|
||||||
|
src = ./.;
|
||||||
|
strictDeps = true;
|
||||||
|
doCheck = false;
|
||||||
|
|
||||||
|
cargoBuildOptions = prev: prev++[
|
||||||
|
"--features=${builtins.concatStringsSep "," builtFeatures}"
|
||||||
|
];
|
||||||
|
} // buildEnv);
|
||||||
}
|
}
|
||||||
|
111
flake.lock
111
flake.lock
@ -1,31 +1,5 @@
|
|||||||
{
|
{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"cargo2nix": {
|
|
||||||
"inputs": {
|
|
||||||
"flake-compat": [
|
|
||||||
"flake-compat"
|
|
||||||
],
|
|
||||||
"flake-utils": "flake-utils",
|
|
||||||
"nixpkgs": [
|
|
||||||
"nixpkgs"
|
|
||||||
],
|
|
||||||
"rust-overlay": "rust-overlay"
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1666087781,
|
|
||||||
"narHash": "sha256-trKVdjMZ8mNkGfLcY5LsJJGtdV3xJDZnMVrkFjErlcs=",
|
|
||||||
"owner": "Alexis211",
|
|
||||||
"repo": "cargo2nix",
|
|
||||||
"rev": "a7a61179b66054904ef6a195d8da736eaaa06c36",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "Alexis211",
|
|
||||||
"repo": "cargo2nix",
|
|
||||||
"rev": "a7a61179b66054904ef6a195d8da736eaaa06c36",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"flake-compat": {
|
"flake-compat": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1688025799,
|
"lastModified": 1688025799,
|
||||||
@ -46,54 +20,19 @@
|
|||||||
"systems": "systems"
|
"systems": "systems"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1681202837,
|
"lastModified": 1701680307,
|
||||||
"narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=",
|
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
|
||||||
"owner": "numtide",
|
"owner": "numtide",
|
||||||
"repo": "flake-utils",
|
"repo": "flake-utils",
|
||||||
"rev": "cfacdce06f30d2b68473a46042957675eebb3401",
|
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "numtide",
|
"id": "flake-utils",
|
||||||
"repo": "flake-utils",
|
"type": "indirect"
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"flake-utils_2": {
|
|
||||||
"inputs": {
|
|
||||||
"systems": "systems_2"
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1681202837,
|
|
||||||
"narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=",
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "flake-utils",
|
|
||||||
"rev": "cfacdce06f30d2b68473a46042957675eebb3401",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "flake-utils",
|
|
||||||
"type": "github"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
|
||||||
"lastModified": 1682109806,
|
|
||||||
"narHash": "sha256-d9g7RKNShMLboTWwukM+RObDWWpHKaqTYXB48clBWXI=",
|
|
||||||
"owner": "NixOS",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "2362848adf8def2866fabbffc50462e929d7fffb",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "NixOS",
|
|
||||||
"ref": "nixpkgs-unstable",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nixpkgs_2": {
|
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1682423271,
|
"lastModified": 1682423271,
|
||||||
"narHash": "sha256-WHhl1GiOij1ob4cTLL+yhqr+vFOUH8E5wAX8Ir8fvjE=",
|
"narHash": "sha256-WHhl1GiOij1ob4cTLL+yhqr+vFOUH8E5wAX8Ir8fvjE=",
|
||||||
@ -111,32 +50,9 @@
|
|||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"cargo2nix": "cargo2nix",
|
|
||||||
"flake-compat": "flake-compat",
|
"flake-compat": "flake-compat",
|
||||||
"flake-utils": [
|
"flake-utils": "flake-utils",
|
||||||
"cargo2nix",
|
|
||||||
"flake-utils"
|
|
||||||
],
|
|
||||||
"nixpkgs": "nixpkgs_2"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"rust-overlay": {
|
|
||||||
"inputs": {
|
|
||||||
"flake-utils": "flake-utils_2",
|
|
||||||
"nixpkgs": "nixpkgs"
|
"nixpkgs": "nixpkgs"
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1682389182,
|
|
||||||
"narHash": "sha256-8t2nmFnH+8V48+IJsf8AK51ebXNlVbOSVYOpiqJKvJE=",
|
|
||||||
"owner": "oxalica",
|
|
||||||
"repo": "rust-overlay",
|
|
||||||
"rev": "74f1a64dd28faeeb85ef081f32cad2989850322c",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "oxalica",
|
|
||||||
"repo": "rust-overlay",
|
|
||||||
"type": "github"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"systems": {
|
"systems": {
|
||||||
@ -153,21 +69,6 @@
|
|||||||
"repo": "default",
|
"repo": "default",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"systems_2": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1681028828,
|
|
||||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
|
||||||
"owner": "nix-systems",
|
|
||||||
"repo": "default",
|
|
||||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "nix-systems",
|
|
||||||
"repo": "default",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": "root",
|
"root": "root",
|
||||||
|
45
flake.nix
45
flake.nix
@ -8,50 +8,23 @@
|
|||||||
|
|
||||||
inputs.flake-compat.url = "github:nix-community/flake-compat";
|
inputs.flake-compat.url = "github:nix-community/flake-compat";
|
||||||
|
|
||||||
inputs.cargo2nix = {
|
outputs = { self, nixpkgs, flake-utils, ... }:
|
||||||
# As of 2022-10-18: two small patches over unstable branch, one for clippy and one to fix feature detection
|
|
||||||
url = "github:Alexis211/cargo2nix/a7a61179b66054904ef6a195d8da736eaaa06c36";
|
|
||||||
|
|
||||||
# As of 2023-04-25:
|
|
||||||
# - my two patches were merged into unstable (one for clippy and one to "fix" feature detection)
|
|
||||||
# - rustc v1.66
|
|
||||||
# url = "github:cargo2nix/cargo2nix/8fb57a670f7993bfc24099c33eb9c5abb51f29a2";
|
|
||||||
|
|
||||||
# Rust overlay as of 2023-04-25
|
|
||||||
inputs.rust-overlay.url =
|
|
||||||
"github:oxalica/rust-overlay/74f1a64dd28faeeb85ef081f32cad2989850322c";
|
|
||||||
|
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
|
||||||
inputs.flake-compat.follows = "flake-compat";
|
|
||||||
};
|
|
||||||
|
|
||||||
inputs.flake-utils.follows = "cargo2nix/flake-utils";
|
|
||||||
|
|
||||||
outputs = { self, nixpkgs, cargo2nix, flake-utils, ... }:
|
|
||||||
let
|
let
|
||||||
git_version = self.lastModifiedDate;
|
gitVersion = self.lastModifiedDate;
|
||||||
compile = import ./nix/compile.nix;
|
compile = import ./nix/compile.nix;
|
||||||
in
|
in
|
||||||
flake-utils.lib.eachDefaultSystem (system:
|
flake-utils.lib.eachDefaultSystem (system:
|
||||||
let pkgs = nixpkgs.legacyPackages.${system};
|
let pkgs = nixpkgs.legacyPackages.${system};
|
||||||
in {
|
in {
|
||||||
packages = {
|
packages = {
|
||||||
default = (compile {
|
default = (import ./default.nix {
|
||||||
inherit system git_version;
|
inherit gitVersion;
|
||||||
pkgsSrc = nixpkgs;
|
buildSystem = system;
|
||||||
cargo2nixOverlay = cargo2nix.overlays.default;
|
|
||||||
release = true;
|
release = true;
|
||||||
}).workspace.garage { compileMode = "build"; };
|
}).build;
|
||||||
};
|
};
|
||||||
devShell = (compile {
|
devShell = (import ./shell.nix {
|
||||||
inherit system git_version;
|
buildSystem = system;
|
||||||
pkgsSrc = nixpkgs;
|
}).rust;
|
||||||
cargo2nixOverlay = cargo2nix.overlays.default;
|
|
||||||
release = false;
|
|
||||||
}).workspaceShell { packages = with pkgs; [
|
|
||||||
rustfmt
|
|
||||||
clang
|
|
||||||
mold
|
|
||||||
]; };
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{ path ? "/../aws-list.txt", }:
|
{ path ? "/../aws-list.txt", }:
|
||||||
|
|
||||||
with import ./common.nix;
|
with import ./pkgs.nix;
|
||||||
let
|
let
|
||||||
pkgs = import pkgsSrc { };
|
pkgs = import pkgsSrc { };
|
||||||
lib = pkgs.lib;
|
lib = pkgs.lib;
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
let
|
|
||||||
lock = builtins.fromJSON (builtins.readFile ../flake.lock);
|
|
||||||
|
|
||||||
inherit (lock.nodes.flake-compat.locked) owner repo rev narHash;
|
|
||||||
|
|
||||||
flake-compat = fetchTarball {
|
|
||||||
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
|
|
||||||
sha256 = narHash;
|
|
||||||
};
|
|
||||||
|
|
||||||
flake = (import flake-compat { system = builtins.currentSystem; src = ../.; });
|
|
||||||
in
|
|
||||||
rec {
|
|
||||||
pkgsSrc = flake.defaultNix.inputs.nixpkgs;
|
|
||||||
cargo2nix = flake.defaultNix.inputs.cargo2nix;
|
|
||||||
cargo2nixOverlay = cargo2nix.overlays.default;
|
|
||||||
}
|
|
8
nix/pkgs.nix
Normal file
8
nix/pkgs.nix
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
let
|
||||||
|
lock = builtins.fromJSON (builtins.readFile ../flake.lock);
|
||||||
|
inherit (lock.nodes.nixpkgs.locked) owner repo rev narHash;
|
||||||
|
in
|
||||||
|
fetchTarball {
|
||||||
|
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
|
||||||
|
sha256 = narHash;
|
||||||
|
}
|
33
shell.nix
33
shell.nix
@ -1,12 +1,12 @@
|
|||||||
{ system ? builtins.currentSystem, }:
|
{
|
||||||
|
buildSystem ? builtins.currentSystem,
|
||||||
|
targetSystem ? buildSystem,
|
||||||
|
}:
|
||||||
|
|
||||||
with import ./nix/common.nix;
|
with import ./nix/pkgs.nix;
|
||||||
|
|
||||||
let
|
let
|
||||||
pkgs = import pkgsSrc {
|
inherit (import ./default.nix { inherit buildSystem targetSystem; }) pkgs pkgsCross buildEnv;
|
||||||
inherit system;
|
|
||||||
overlays = [ cargo2nixOverlay ];
|
|
||||||
};
|
|
||||||
kaniko = (import ./nix/kaniko.nix) pkgs;
|
kaniko = (import ./nix/kaniko.nix) pkgs;
|
||||||
manifest-tool = (import ./nix/manifest-tool.nix) pkgs;
|
manifest-tool = (import ./nix/manifest-tool.nix) pkgs;
|
||||||
winscp = (import ./nix/winscp.nix) pkgs;
|
winscp = (import ./nix/winscp.nix) pkgs;
|
||||||
@ -14,22 +14,13 @@ let
|
|||||||
in {
|
in {
|
||||||
# --- Rust Shell ---
|
# --- Rust Shell ---
|
||||||
# Use it to compile Garage
|
# Use it to compile Garage
|
||||||
rust = pkgs.mkShell {
|
rust = pkgsCross.mkShell (buildEnv // {
|
||||||
nativeBuildInputs = with pkgs; [
|
inputsFrom = [
|
||||||
#rustPlatform.rust.rustc
|
kaniko
|
||||||
rustPlatform.rust.cargo
|
manifest-tool
|
||||||
clang
|
winscp
|
||||||
mold
|
|
||||||
#clippy
|
|
||||||
rustfmt
|
|
||||||
#perl
|
|
||||||
#protobuf
|
|
||||||
#pkg-config
|
|
||||||
#openssl
|
|
||||||
file
|
|
||||||
#cargo2nix.packages.x86_64-linux.cargo2nix
|
|
||||||
];
|
];
|
||||||
};
|
});
|
||||||
|
|
||||||
# --- Integration shell ---
|
# --- Integration shell ---
|
||||||
# Use it to test Garage with common S3 clients
|
# Use it to test Garage with common S3 clients
|
||||||
|
@ -45,7 +45,7 @@ http = "0.2"
|
|||||||
httpdate = "1.0"
|
httpdate = "1.0"
|
||||||
http-range = "0.1"
|
http-range = "0.1"
|
||||||
hyper = { version = "0.14", features = ["server", "http1", "runtime", "tcp", "stream"] }
|
hyper = { version = "0.14", features = ["server", "http1", "runtime", "tcp", "stream"] }
|
||||||
hyperlocal = { version = "0.8.0", default-features = false, features = ["server"] }
|
#hyperlocal = { version = "0.8.0", default-features = false, features = ["server"] }
|
||||||
multer = "2.0"
|
multer = "2.0"
|
||||||
percent-encoding = "2.1.0"
|
percent-encoding = "2.1.0"
|
||||||
roxmltree = "0.18"
|
roxmltree = "0.18"
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
use std::fs::{self, Permissions};
|
//use std::fs::{self, Permissions};
|
||||||
use std::os::unix::fs::PermissionsExt;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
@ -12,9 +11,9 @@ use hyper::service::{make_service_fn, service_fn};
|
|||||||
use hyper::{Body, Request, Response, Server};
|
use hyper::{Body, Request, Response, Server};
|
||||||
use hyper::{HeaderMap, StatusCode};
|
use hyper::{HeaderMap, StatusCode};
|
||||||
|
|
||||||
use hyperlocal::UnixServerExt;
|
//use hyperlocal::UnixServerExt;
|
||||||
|
|
||||||
use tokio::net::UnixStream;
|
//use tokio::net::UnixStream;
|
||||||
|
|
||||||
use opentelemetry::{
|
use opentelemetry::{
|
||||||
global,
|
global,
|
||||||
@ -114,18 +113,18 @@ impl<A: ApiHandler> ApiServer<A> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let unix_service = make_service_fn(|_: &UnixStream| {
|
//let unix_service = make_service_fn(|_: &UnixStream| {
|
||||||
let this = self.clone();
|
// let this = self.clone();
|
||||||
|
|
||||||
let path = bind_addr.to_string();
|
// let path = bind_addr.to_string();
|
||||||
async move {
|
// async move {
|
||||||
Ok::<_, GarageError>(service_fn(move |req: Request<Body>| {
|
// Ok::<_, GarageError>(service_fn(move |req: Request<Body>| {
|
||||||
let this = this.clone();
|
// let this = this.clone();
|
||||||
|
|
||||||
this.handler(req, path.clone())
|
// this.handler(req, path.clone())
|
||||||
}))
|
// }))
|
||||||
}
|
// }
|
||||||
});
|
//});
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
"{} API server listening on {}",
|
"{} API server listening on {}",
|
||||||
@ -140,23 +139,24 @@ impl<A: ApiHandler> ApiServer<A> {
|
|||||||
.with_graceful_shutdown(shutdown_signal)
|
.with_graceful_shutdown(shutdown_signal)
|
||||||
.await?
|
.await?
|
||||||
}
|
}
|
||||||
UnixOrTCPSocketAddress::UnixSocket(ref path) => {
|
UnixOrTCPSocketAddress::UnixSocket(_path) => {
|
||||||
if path.exists() {
|
panic!("Unix sockets are not supported in this fork") // TODO(mediocregopher)
|
||||||
fs::remove_file(path)?
|
} //UnixOrTCPSocketAddress::UnixSocket(ref path) => {
|
||||||
}
|
// use std::os::unix::fs::PermissionsExt;
|
||||||
|
// remove_unix_socket_if_present(path).await?;
|
||||||
|
|
||||||
let bound = Server::bind_unix(path)?;
|
// let bound = Server::bind_unix(path)?;
|
||||||
|
|
||||||
fs::set_permissions(
|
// fs::set_permissions(
|
||||||
path,
|
// path,
|
||||||
Permissions::from_mode(unix_bind_addr_mode.unwrap_or(0o222)),
|
// Permissions::from_mode(unix_bind_addr_mode.unwrap_or(0o222)),
|
||||||
)?;
|
// )?;
|
||||||
|
|
||||||
bound
|
// bound
|
||||||
.serve(unix_service)
|
// .serve(unix_service)
|
||||||
.with_graceful_shutdown(shutdown_signal)
|
// .with_graceful_shutdown(shutdown_signal)
|
||||||
.await?;
|
// .await?;
|
||||||
}
|
//}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -771,11 +771,7 @@ impl BlockManagerLocked {
|
|||||||
// Now, we do an fsync on the containing directory, to ensure that the rename
|
// Now, we do an fsync on the containing directory, to ensure that the rename
|
||||||
// is persisted properly. See:
|
// is persisted properly. See:
|
||||||
// http://thedjbway.b0llix.net/qmail/syncdir.html
|
// http://thedjbway.b0llix.net/qmail/syncdir.html
|
||||||
let dir = fs::OpenOptions::new()
|
let dir = fs::OpenOptions::new().read(true).open(directory).await?;
|
||||||
.read(true)
|
|
||||||
.mode(0)
|
|
||||||
.open(directory)
|
|
||||||
.await?;
|
|
||||||
dir.sync_all().await?;
|
dir.sync_all().await?;
|
||||||
drop(dir);
|
drop(dir);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ use std::collections::HashMap;
|
|||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::net::{IpAddr, SocketAddr};
|
use std::net::{IpAddr, SocketAddr};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::atomic::Ordering;
|
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
@ -198,6 +197,20 @@ pub fn read_node_id(metadata_dir: &Path) -> Result<NodeID, Error> {
|
|||||||
Ok(NodeID::from_slice(&key[..]).unwrap())
|
Ok(NodeID::from_slice(&key[..]).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
fn set_private_key_perms(path: &Path) -> Result<(), Error> {
|
||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
let perm = std::fs::Permissions::from_mode(0o600);
|
||||||
|
std::fs::set_permissions(path, perm)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
fn set_private_key_perms(_path: &Path) -> Result<(), Error> {
|
||||||
|
// TODO(mediocregopher) figure out how to do this, but it's not strictly necessary
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn gen_node_key(metadata_dir: &Path) -> Result<NodeKey, Error> {
|
pub fn gen_node_key(metadata_dir: &Path) -> Result<NodeKey, Error> {
|
||||||
let mut key_file = metadata_dir.to_path_buf();
|
let mut key_file = metadata_dir.to_path_buf();
|
||||||
key_file.push("node_key");
|
key_file.push("node_key");
|
||||||
@ -222,11 +235,8 @@ pub fn gen_node_key(metadata_dir: &Path) -> Result<NodeKey, Error> {
|
|||||||
let (pubkey, key) = ed25519::gen_keypair();
|
let (pubkey, key) = ed25519::gen_keypair();
|
||||||
|
|
||||||
{
|
{
|
||||||
use std::os::unix::fs::PermissionsExt;
|
|
||||||
let mut f = std::fs::File::create(key_file.as_path())?;
|
let mut f = std::fs::File::create(key_file.as_path())?;
|
||||||
let mut perm = f.metadata()?.permissions();
|
set_private_key_perms(key_file.as_path())?;
|
||||||
perm.set_mode(0o600);
|
|
||||||
std::fs::set_permissions(key_file.as_path(), perm)?;
|
|
||||||
f.write_all(&key[..])?;
|
f.write_all(&key[..])?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -890,6 +900,18 @@ impl NodeStatus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
fn update_disk_usage(
|
||||||
|
&mut self,
|
||||||
|
_meta_dir: &Path,
|
||||||
|
_data_dir: &DataDirEnum,
|
||||||
|
_metrics: &SystemMetrics,
|
||||||
|
) {
|
||||||
|
// TODO(mediocregopher) it'd be nice to have this for windows too, but it seems to only be
|
||||||
|
// used for OpenTelemetry so it's not a real requirement.
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(windows))]
|
||||||
fn update_disk_usage(
|
fn update_disk_usage(
|
||||||
&mut self,
|
&mut self,
|
||||||
meta_dir: &Path,
|
meta_dir: &Path,
|
||||||
@ -897,6 +919,7 @@ impl NodeStatus {
|
|||||||
metrics: &SystemMetrics,
|
metrics: &SystemMetrics,
|
||||||
) {
|
) {
|
||||||
use nix::sys::statvfs::statvfs;
|
use nix::sys::statvfs::statvfs;
|
||||||
|
use std::sync::atomic::Ordering;
|
||||||
let mount_avail = |path: &Path| match statvfs(path) {
|
let mount_avail = |path: &Path| match statvfs(path) {
|
||||||
Ok(x) => {
|
Ok(x) => {
|
||||||
let avail = x.blocks_available() as u64 * x.fragment_size() as u64;
|
let avail = x.blocks_available() as u64 * x.fragment_size() as u64;
|
||||||
@ -955,6 +978,7 @@ impl NodeStatus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(windows))]
|
||||||
fn get_default_ip() -> Option<IpAddr> {
|
fn get_default_ip() -> Option<IpAddr> {
|
||||||
pnet_datalink::interfaces()
|
pnet_datalink::interfaces()
|
||||||
.iter()
|
.iter()
|
||||||
@ -963,6 +987,11 @@ fn get_default_ip() -> Option<IpAddr> {
|
|||||||
.map(|a| a.ip())
|
.map(|a| a.ip())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
fn get_default_ip() -> Option<IpAddr> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
async fn resolve_peers(peers: &[String]) -> Vec<(NodeID, SocketAddr)> {
|
async fn resolve_peers(peers: &[String]) -> Vec<(NodeID, SocketAddr)> {
|
||||||
let mut ret = vec![];
|
let mut ret = vec![];
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ futures = "0.3"
|
|||||||
|
|
||||||
http = "0.2"
|
http = "0.2"
|
||||||
hyper = { version = "0.14", features = ["server", "http1", "runtime", "tcp", "stream"] }
|
hyper = { version = "0.14", features = ["server", "http1", "runtime", "tcp", "stream"] }
|
||||||
hyperlocal = { version = "0.8.0", default-features = false, features = ["server"] }
|
#hyperlocal = { version = "0.8.0", default-features = false, features = ["server"] }
|
||||||
|
|
||||||
tokio = { version = "1.0", default-features = false, features = ["net"] }
|
tokio = { version = "1.0", default-features = false, features = ["net"] }
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use std::fs::{self, Permissions};
|
//use std::fs::{self, Permissions};
|
||||||
use std::os::unix::prelude::PermissionsExt;
|
//use std::os::unix::prelude::PermissionsExt;
|
||||||
use std::{convert::Infallible, sync::Arc};
|
use std::{convert::Infallible, sync::Arc};
|
||||||
|
|
||||||
use futures::future::Future;
|
use futures::future::Future;
|
||||||
@ -11,9 +11,9 @@ use hyper::{
|
|||||||
Body, Method, Request, Response, Server, StatusCode,
|
Body, Method, Request, Response, Server, StatusCode,
|
||||||
};
|
};
|
||||||
|
|
||||||
use hyperlocal::UnixServerExt;
|
//use hyperlocal::UnixServerExt;
|
||||||
|
|
||||||
use tokio::net::UnixStream;
|
//use tokio::net::UnixStream;
|
||||||
|
|
||||||
use opentelemetry::{
|
use opentelemetry::{
|
||||||
global,
|
global,
|
||||||
@ -100,18 +100,18 @@ impl WebServer {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let unix_service = make_service_fn(|_: &UnixStream| {
|
//let unix_service = make_service_fn(|_: &UnixStream| {
|
||||||
let web_server = web_server.clone();
|
// let web_server = web_server.clone();
|
||||||
|
|
||||||
let path = addr.to_string();
|
// let path = addr.to_string();
|
||||||
async move {
|
// async move {
|
||||||
Ok::<_, Error>(service_fn(move |req: Request<Body>| {
|
// remove_unix_socket_if_present(&path).await.expect("could not remove existing unix socket");
|
||||||
let web_server = web_server.clone();
|
// Ok::<_, Error>(service_fn(move |req: Request<Body>| {
|
||||||
|
// let web_server = web_server.clone();
|
||||||
web_server.handle_request(req, path.clone())
|
// web_server.handle_request(req, path.clone())
|
||||||
}))
|
// }))
|
||||||
}
|
// }
|
||||||
});
|
//});
|
||||||
|
|
||||||
info!("Web server listening on {}", addr);
|
info!("Web server listening on {}", addr);
|
||||||
|
|
||||||
@ -122,20 +122,22 @@ impl WebServer {
|
|||||||
.with_graceful_shutdown(shutdown_signal)
|
.with_graceful_shutdown(shutdown_signal)
|
||||||
.await?
|
.await?
|
||||||
}
|
}
|
||||||
UnixOrTCPSocketAddress::UnixSocket(ref path) => {
|
UnixOrTCPSocketAddress::UnixSocket(_path) => {
|
||||||
if path.exists() {
|
panic!("Unix sockets are not supported in this fork") // TODO(mediocregopher)
|
||||||
fs::remove_file(path)?
|
} //UnixOrTCPSocketAddress::UnixSocket(ref path) => {
|
||||||
}
|
// if path.exists() {
|
||||||
|
// fs::remove_file(path)?
|
||||||
|
// }
|
||||||
|
|
||||||
let bound = Server::bind_unix(path)?;
|
// let bound = Server::bind_unix(path)?;
|
||||||
|
|
||||||
fs::set_permissions(path, Permissions::from_mode(0o222))?;
|
// fs::set_permissions(path, Permissions::from_mode(0o222))?;
|
||||||
|
|
||||||
bound
|
// bound
|
||||||
.serve(unix_service)
|
// .serve(unix_service)
|
||||||
.with_graceful_shutdown(shutdown_signal)
|
// .with_graceful_shutdown(shutdown_signal)
|
||||||
.await?;
|
// .await?;
|
||||||
}
|
//}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
Reference in New Issue
Block a user