feat: build backend with Nix
This commit is contained in:
parent
9d0cfd1795
commit
9b5d6d87ed
3
.gitignore
vendored
3
.gitignore
vendored
@ -31,3 +31,6 @@ dist
|
|||||||
|
|
||||||
## Node dependencies
|
## Node dependencies
|
||||||
node_modules
|
node_modules
|
||||||
|
|
||||||
|
# Nix
|
||||||
|
result
|
||||||
|
|||||||
55
backend/nix/package.nix
Normal file
55
backend/nix/package.nix
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
{
|
||||||
|
rust-overlay,
|
||||||
|
inputs,
|
||||||
|
system,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
rust = import ./rust-version.nix { inherit rust-overlay inputs system; };
|
||||||
|
pkgs = rust.pkgs;
|
||||||
|
rustPlatform = pkgs.makeRustPlatform {
|
||||||
|
cargo = rust.version;
|
||||||
|
rustc = rust.version;
|
||||||
|
};
|
||||||
|
cargoToml = builtins.fromTOML (builtins.readFile ../Cargo.toml);
|
||||||
|
name = cargoToml.package.name;
|
||||||
|
version = cargoToml.package.version;
|
||||||
|
rustBuild = rustPlatform.buildRustPackage {
|
||||||
|
pname = name;
|
||||||
|
inherit version;
|
||||||
|
src = ../.;
|
||||||
|
cargoLock.lockFile = ../Cargo.lock;
|
||||||
|
};
|
||||||
|
makeDockerImage = tag:
|
||||||
|
pkgs.dockerTools.buildLayeredImage {
|
||||||
|
name = "phundrak/${name}";
|
||||||
|
inherit tag;
|
||||||
|
created = "now";
|
||||||
|
config = {
|
||||||
|
Entrypoint = ["${rustBuild}/bin/${name}"];
|
||||||
|
Env = [
|
||||||
|
"SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
|
||||||
|
];
|
||||||
|
ExposedPorts = {
|
||||||
|
"3100/tcp" = {};
|
||||||
|
};
|
||||||
|
Labels = {
|
||||||
|
"org.opencontainers.image.title" = name;
|
||||||
|
"org.opencontainers.image.version" = version;
|
||||||
|
"org.opencontainers.image.description" = "REST API backend for phundrak.com";
|
||||||
|
"org.opencontainers.image.authors" = "Lucien Cartier-Tilet <lucien@phundrak.com>";
|
||||||
|
"org.opencontainers.image.licenses" = "AGPL-3.0-only";
|
||||||
|
"org.opencontainers.image.source" = "https://labs.phundrak.com/phundrak/phundrak.com";
|
||||||
|
"org.opencontainers.image.url" = "https://labs.phundrak.com/phundrak/phundrak.com";
|
||||||
|
"org.opencontainers.image.documentation" = "https://labs.phundrak.com/phundrak/phundrak.com";
|
||||||
|
"org.opencontainers.image.vendor" = "Phundrak";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
contents = [rustBuild pkgs.cacert];
|
||||||
|
};
|
||||||
|
dockerImageLatest = makeDockerImage "latest";
|
||||||
|
dockerImageVersioned = makeDockerImage version;
|
||||||
|
in {
|
||||||
|
backend = rustBuild;
|
||||||
|
backendDocker = dockerImageVersioned;
|
||||||
|
backendDockerLatest = dockerImageLatest;
|
||||||
|
}
|
||||||
6
backend/nix/rust-version.nix
Normal file
6
backend/nix/rust-version.nix
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{rust-overlay, inputs, system, ...}: let
|
||||||
|
overlays = [(import rust-overlay)];
|
||||||
|
in rec {
|
||||||
|
pkgs = import inputs.nixpkgs {inherit system overlays;};
|
||||||
|
version = pkgs.rust-bin.stable.latest.default;
|
||||||
|
}
|
||||||
@ -6,9 +6,7 @@
|
|||||||
rust-overlay,
|
rust-overlay,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
overlays = [(import rust-overlay)];
|
rustPlatform = import ./rust-version.nix { inherit rust-overlay inputs system; };
|
||||||
rustPkgs = import inputs.nixpkgs {inherit system overlays;};
|
|
||||||
rustVersion = rustPkgs.rust-bin.stable.latest.default;
|
|
||||||
in
|
in
|
||||||
inputs.devenv.lib.mkShell {
|
inputs.devenv.lib.mkShell {
|
||||||
inherit inputs pkgs;
|
inherit inputs pkgs;
|
||||||
@ -20,8 +18,8 @@ in
|
|||||||
pkgs.lib.mkIf (devenvRootFileContent != "") devenvRootFileContent;
|
pkgs.lib.mkIf (devenvRootFileContent != "") devenvRootFileContent;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
packages = with rustPkgs; [
|
packages = with rustPlatform.pkgs; [
|
||||||
(rustVersion.override {
|
(rustPlatform.version.override {
|
||||||
extensions = [
|
extensions = [
|
||||||
"clippy"
|
"clippy"
|
||||||
"rust-src"
|
"rust-src"
|
||||||
@ -33,12 +33,12 @@
|
|||||||
forEachSystem = nixpkgs.lib.genAttrs (import systems);
|
forEachSystem = nixpkgs.lib.genAttrs (import systems);
|
||||||
in {
|
in {
|
||||||
formatter = forEachSystem (system: alejandra.defaultPackage.${system});
|
formatter = forEachSystem (system: alejandra.defaultPackage.${system});
|
||||||
|
packages = forEachSystem (system: import ./backend/nix/package.nix { inherit rust-overlay inputs system; });
|
||||||
devShells = forEachSystem (
|
devShells = forEachSystem (
|
||||||
system: let
|
system: let
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
in {
|
in {
|
||||||
backend = import ./backend/shell.nix {
|
backend = import ./backend/nix/shell.nix {
|
||||||
inherit inputs pkgs system self rust-overlay;
|
inherit inputs pkgs system self rust-overlay;
|
||||||
};
|
};
|
||||||
frontend = import ./frontend/shell.nix {
|
frontend = import ./frontend/shell.nix {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user