115 lines
4.0 KiB
Nix
115 lines
4.0 KiB
Nix
{
|
|
description = "Quick rust website template";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
};
|
|
|
|
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;
|
|
|
|
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.quick-rust-website;
|
|
in
|
|
{
|
|
options.services.quick-rust-website = {
|
|
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";
|
|
# };
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
systemd.services.quick-rust-website = {
|
|
description = "Quick rust website template";
|
|
after = [ "network.target" ];
|
|
wantedBy = [ "multi-user.target" ];
|
|
serviceConfig = {
|
|
ExecStart = "${
|
|
self.packages.${pkgs.system}.default
|
|
}/bin/quick-rust-website --port ${toString cfg.port} --host";
|
|
Restart = "on-failure";
|
|
StateDirectory = "quick-rust-website";
|
|
DynamicUser = true;
|
|
ProtectSystem = "strict";
|
|
ProtectHome = true;
|
|
NoNewPrivileges = true;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
}
|