replaced askama with tera, reworked the whole website and added nixos module
This commit is contained in:
149
flake.nix
149
flake.nix
@@ -1,57 +1,114 @@
|
||||
{
|
||||
description = "My cool website";
|
||||
description = "Quick rust website template";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
rust-overlay.url = "github:oxalica/rust-overlay";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils, rust-overlay, ... }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
overlays = [ rust-overlay.overlays.default ];
|
||||
pkgs = import nixpkgs {
|
||||
inherit system overlays;
|
||||
};
|
||||
rust = pkgs.rust-bin.stable.latest.default;
|
||||
openssl = pkgs.openssl;
|
||||
in
|
||||
{
|
||||
packages.default = pkgs.rustPlatform.buildRustPackage {
|
||||
pname = "mycoolwebsite";
|
||||
version = "0.1.1";
|
||||
outputs =
|
||||
{ self, nixpkgs, ... }:
|
||||
let
|
||||
supportedSystems = [
|
||||
"x86_64-linux"
|
||||
# "aarch64-linux"
|
||||
# "x86_64-darwin"
|
||||
# "aarch64-darwin"
|
||||
];
|
||||
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
|
||||
in
|
||||
{
|
||||
packages = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
in
|
||||
{
|
||||
default = pkgs.rustPlatform.buildRustPackage {
|
||||
pname = "quick-rust-website";
|
||||
version = "0.1.0";
|
||||
|
||||
src = ./.;
|
||||
cargoLock = {
|
||||
lockFile = ./Cargo.lock;
|
||||
src = ./.;
|
||||
|
||||
cargoLock.lockFile = ./Cargo.lock;
|
||||
|
||||
nativeBuildInputs = [ pkgs.pkg-config ];
|
||||
|
||||
buildInputs = [
|
||||
pkgs.openssl
|
||||
# pkgs.sqlite
|
||||
];
|
||||
|
||||
PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";
|
||||
OPENSSL_LIB_DIR = "${pkgs.openssl.out}/lib";
|
||||
OPENSSL_INCLUDE_DIR = "${pkgs.openssl.dev}/include";
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
devShells = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
in
|
||||
{
|
||||
default = pkgs.mkShell {
|
||||
packages = [
|
||||
pkgs.rustc
|
||||
pkgs.cargo
|
||||
pkgs.rust-analyzer
|
||||
pkgs.pkg-config
|
||||
pkgs.openssl
|
||||
];
|
||||
|
||||
env = {
|
||||
PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";
|
||||
OPENSSL_DIR = "${pkgs.openssl.dev}";
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
nixosModules.default =
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.services.slimes-server;
|
||||
in
|
||||
{
|
||||
options.services.slimes-server = {
|
||||
enable = lib.mkEnableOption "Quick rust website template";
|
||||
port = lib.mkOption {
|
||||
type = lib.types.port;
|
||||
default = 9003;
|
||||
};
|
||||
# databasePath = lib.mkOption {
|
||||
# type = lib.types.str;
|
||||
# default = "/var/lib/quick-rust-website/database.db";
|
||||
# };
|
||||
};
|
||||
|
||||
nativeBuildInputs = [
|
||||
rust
|
||||
pkgs.pkg-config
|
||||
];
|
||||
|
||||
buildInputs = [
|
||||
openssl
|
||||
];
|
||||
|
||||
OPENSSL_LIB_DIR = "${openssl.out}/lib";
|
||||
OPENSSL_INCLUDE_DIR = "${openssl.dev}/include";
|
||||
PKG_CONFIG_PATH = "${openssl.dev}/lib/pkgconfig";
|
||||
config = lib.mkIf cfg.enable {
|
||||
systemd.services.slimes-server = {
|
||||
description = "Quick rust website template";
|
||||
after = [ "network.target" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
serviceConfig = {
|
||||
ExecStart = "${
|
||||
self.packages.${pkgs.system}.default
|
||||
}/bin/quick-rust-website --database-url ${cfg.databasePath} --port ${toString cfg.port}";
|
||||
Restart = "on-failure";
|
||||
StateDirectory = "quick-rust-website";
|
||||
DynamicUser = true;
|
||||
ProtectSystem = "strict";
|
||||
ProtectHome = true;
|
||||
NoNewPrivileges = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
devShells.default = pkgs.mkShell {
|
||||
packages = [
|
||||
rust
|
||||
pkgs.cargo
|
||||
pkgs.rust-analyzer
|
||||
pkgs.pkg-config
|
||||
openssl
|
||||
];
|
||||
OPENSSL_DIR = openssl.dev;
|
||||
PKG_CONFIG_PATH = "${openssl.dev}/lib/pkgconfig";
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user