Refactor and update flake
This commit is contained in:
parent
e7c9222070
commit
26ec66d03e
2 changed files with 176 additions and 70 deletions
116
flake.nix
116
flake.nix
|
@ -3,70 +3,80 @@
|
|||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-22.05";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
rust-overlay = {
|
||||
url = "github:oxalica/rust-overlay";
|
||||
inputs = {
|
||||
flake-utils.follows = "flake-utils";
|
||||
nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
naersk = {
|
||||
url = "github:nmattia/naersk";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
tlaternet-templates = {
|
||||
url = "git+https://gitea.tlater.net/tlaternet/tlaternet.git";
|
||||
# No need to override anything here; we can save some downloads
|
||||
# if we rely on the webserver to do that.
|
||||
};
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils, rust-overlay, naersk }@inputs:
|
||||
flake-utils.lib.simpleFlake {
|
||||
inherit self nixpkgs;
|
||||
name = "tlaternet-webserver";
|
||||
preOverlays = [ rust-overlay.overlay ];
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
rust-overlay,
|
||||
naersk,
|
||||
tlaternet-templates,
|
||||
}: let
|
||||
# At the moment, we only deploy to x86_64-linux. Update when we
|
||||
# care about another platform.
|
||||
system = "x86_64-linux";
|
||||
overlays = [
|
||||
rust-overlay.overlays.default
|
||||
];
|
||||
pkgs = import nixpkgs {inherit system overlays;};
|
||||
|
||||
overlay = final: prev: {
|
||||
tlaternet-webserver = let
|
||||
# The rust toolchain to use
|
||||
toolchain =
|
||||
prev.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
|
||||
# Rust build config
|
||||
rust-toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
|
||||
naersk-lib = naersk.lib.${system}.override {
|
||||
cargo = rust-toolchain;
|
||||
rustc = rust-toolchain;
|
||||
};
|
||||
buildInputs = with pkgs; [
|
||||
pkg-config
|
||||
openssl
|
||||
];
|
||||
in {
|
||||
packages.${system} = rec {
|
||||
tlaternet-webserver = naersk-lib.buildPackage {
|
||||
inherit buildInputs;
|
||||
pname = "tlaternet-webserver";
|
||||
root = pkgs.lib.cleanSource self;
|
||||
};
|
||||
default = tlaternet-webserver;
|
||||
};
|
||||
|
||||
# The rust build lib, set to use the toolchain
|
||||
naersk-lib = naersk.lib.${prev.system}.override {
|
||||
cargo = toolchain;
|
||||
rustc = toolchain;
|
||||
};
|
||||
|
||||
# pkg-config, needed to include many native libs
|
||||
nativeBuildInputs = [ prev.pkgconfig ];
|
||||
|
||||
# Native libs
|
||||
buildInputs = [ prev.openssl ];
|
||||
|
||||
in rec {
|
||||
# The packages provided by this flake
|
||||
packages = {
|
||||
webserver = prev.callPackage
|
||||
({ rustPlatform, openssl, pkgconfig, ... }:
|
||||
naersk-lib.buildPackage {
|
||||
inherit nativeBuildInputs buildInputs;
|
||||
|
||||
pname = "tlaternet-webserver";
|
||||
root = ./.;
|
||||
}) { };
|
||||
};
|
||||
defaultPackage = packages.webserver;
|
||||
|
||||
# A dev shell to hack manually; note this includes
|
||||
# additional toolchain components
|
||||
devShell = prev.mkShell {
|
||||
inherit buildInputs;
|
||||
nativeBuildInputs = nativeBuildInputs ++ [
|
||||
(toolchain.override {
|
||||
extensions =
|
||||
[ "rust-src" "rust-analysis" "rust-analyzer-preview" ];
|
||||
})
|
||||
];
|
||||
};
|
||||
};
|
||||
apps.${system} = {
|
||||
run-with-templates = let
|
||||
script = pkgs.writeShellScriptBin "run-with-templates" ''
|
||||
export ROCKET_TEMPLATE_DIR=${tlaternet-templates.packages.${system}.tlaternet-templates}
|
||||
${self.packages.${system}.tlaternet-webserver}/bin/tlaternet-webserver
|
||||
'';
|
||||
in {
|
||||
type = "app";
|
||||
program = "${script}/bin/run-with-templates";
|
||||
};
|
||||
};
|
||||
|
||||
devShells.${system} = {
|
||||
default = pkgs.mkShell {
|
||||
packages = builtins.concatLists [
|
||||
buildInputs
|
||||
[
|
||||
(rust-toolchain.override {
|
||||
extensions = ["rust-src" "rust-analysis" "rust-analyzer-preview"];
|
||||
})
|
||||
]
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue