build: nixos module
This commit is contained in:
parent
773be52f3e
commit
47df995ed1
112
flake.nix
112
flake.nix
@ -11,8 +11,117 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
outputs =
|
outputs =
|
||||||
{ basecamp, nixpkgs, ... }:
|
|
||||||
{
|
{
|
||||||
|
self,
|
||||||
|
basecamp,
|
||||||
|
nixpkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
{
|
||||||
|
basecamp-config = {
|
||||||
|
rust.enable = true;
|
||||||
|
rust.toolchain.targets = [ "wasm32-unknown-unknown" ];
|
||||||
|
};
|
||||||
|
|
||||||
|
packages."x86_64-linux".default =
|
||||||
|
let
|
||||||
|
cargoToml = builtins.fromTOML (builtins.readFile ./crates/ascend/Cargo.toml);
|
||||||
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||||
|
config =
|
||||||
|
(basecamp.eval.components {
|
||||||
|
inherit pkgs;
|
||||||
|
config = self.basecamp-config;
|
||||||
|
}).config;
|
||||||
|
rust-toolchain = config.rust.toolchain.package;
|
||||||
|
rustPlatform = pkgs.makeRustPlatform {
|
||||||
|
cargo = rust-toolchain;
|
||||||
|
rustc = rust-toolchain;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
rustPlatform.buildRustPackage {
|
||||||
|
pname = cargoToml.package.name;
|
||||||
|
version = cargoToml.package.version;
|
||||||
|
src = ./.;
|
||||||
|
cargoLock.lockFile = ./Cargo.lock;
|
||||||
|
|
||||||
|
nativeBuildInputs = [
|
||||||
|
pkgs.cargo-leptos
|
||||||
|
pkgs.dart-sass
|
||||||
|
pkgs.tailwindcss
|
||||||
|
|
||||||
|
# For optimizing wasm release builds
|
||||||
|
pkgs.binaryen
|
||||||
|
|
||||||
|
pkgs.makeWrapper
|
||||||
|
];
|
||||||
|
|
||||||
|
buildPhase = ''
|
||||||
|
cargo leptos build --release -vvv
|
||||||
|
'';
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
mkdir -p $out/bin
|
||||||
|
cp target/release/ascend $out/bin/
|
||||||
|
cp -r target/site $out/
|
||||||
|
wrapProgram $out/bin/ascend --set LEPTOS_SITE_ROOT $out/site
|
||||||
|
'';
|
||||||
|
|
||||||
|
doCheck = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
nixosModules.default =
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
pkgs,
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
cfg = config.services.ascend;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
services.ascend = {
|
||||||
|
enable = lib.mkEnableOption "Ascend service";
|
||||||
|
bindAddress = lib.mkOption {
|
||||||
|
description = "Bind address (LEPTOS_SITE_ADDR)";
|
||||||
|
type = lib.types.string;
|
||||||
|
default = "127.0.0.1:1337";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
users.users.ascend = {
|
||||||
|
isSystemUser = true;
|
||||||
|
home = "/home/ascend";
|
||||||
|
group = "ascend";
|
||||||
|
description = "Ascend service user";
|
||||||
|
};
|
||||||
|
users.groups.ascend = { };
|
||||||
|
systemd.services.ascend = {
|
||||||
|
enable = true;
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
after = [ "network.target" ];
|
||||||
|
description = "Start the Ascend service";
|
||||||
|
environment = {
|
||||||
|
RUST_LOG = "info";
|
||||||
|
LEPTOS_SITE_ADDR = cfg.bindAddress;
|
||||||
|
};
|
||||||
|
path = [ ];
|
||||||
|
serviceConfig = {
|
||||||
|
User = "ascend";
|
||||||
|
Group = "ascend";
|
||||||
|
Type = "simple";
|
||||||
|
Restart = "always";
|
||||||
|
ExecStart = ''
|
||||||
|
${self.packages."x86_64-linux".default}/bin/ascend serve
|
||||||
|
'';
|
||||||
|
WorkingDirectory = "/home/ascend";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
devShells."x86_64-linux".default =
|
devShells."x86_64-linux".default =
|
||||||
let
|
let
|
||||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||||
@ -20,7 +129,6 @@
|
|||||||
basecamp.mkShell pkgs {
|
basecamp.mkShell pkgs {
|
||||||
rust.enable = true;
|
rust.enable = true;
|
||||||
rust.toolchain.targets = [ "wasm32-unknown-unknown" ];
|
rust.toolchain.targets = [ "wasm32-unknown-unknown" ];
|
||||||
# rust.toolchain.channel = "nightly";
|
|
||||||
|
|
||||||
packages = [
|
packages = [
|
||||||
pkgs.cargo-leptos
|
pkgs.cargo-leptos
|
||||||
|
Loading…
x
Reference in New Issue
Block a user