add nix way
This commit is contained in:
@@ -3,3 +3,45 @@
|
|||||||
[](https://技術者倫理.com)
|
[](https://技術者倫理.com)
|
||||||
|
|
||||||
A client for SBI-compatible servers. This project is not intended for use with a real SBI server.
|
A client for SBI-compatible servers. This project is not intended for use with a real SBI server.
|
||||||
|
|
||||||
|
## cSBI SDK
|
||||||
|
|
||||||
|
## cSBIe
|
||||||
|
|
||||||
|
cSBIe is a web ui and server for managing SBI-compatible API.
|
||||||
|
|
||||||
|
### Install
|
||||||
|
|
||||||
|
Before running, setup .env, refering `.env.example`.
|
||||||
|
|
||||||
|
#### With docker
|
||||||
|
|
||||||
|
docker-compose.yml:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
csbie:
|
||||||
|
image: git.yutakobayashi.com/nakasyou/csbi:latest
|
||||||
|
ports:
|
||||||
|
- '18787:8787'
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
volumes:
|
||||||
|
- ./data:/app/data
|
||||||
|
```
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --rm -it --name csbie \
|
||||||
|
-p 18787:8787 \
|
||||||
|
--env-file .env \
|
||||||
|
-v "$PWD/data:/app/data" \
|
||||||
|
git.yutakobayashi.com/nakasyou/csbi:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
#### With Nix
|
||||||
|
|
||||||
|
```bash
|
||||||
|
nix run 'git+https://git.yutakobayashi.com/nakasyou/csbi.git#csbie'
|
||||||
|
```
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ services:
|
|||||||
csbie:
|
csbie:
|
||||||
image: git.yutakobayashi.com/nakasyou/csbi:latest
|
image: git.yutakobayashi.com/nakasyou/csbi:latest
|
||||||
ports:
|
ports:
|
||||||
- '18787:8787'
|
- '${CSBIE_HOST_PORT:-18787}:8787'
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
volumes:
|
volumes:
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
outputs =
|
outputs =
|
||||||
{ nixpkgs, ... }:
|
{ self, nixpkgs, ... }:
|
||||||
let
|
let
|
||||||
systems = [
|
systems = [
|
||||||
"aarch64-darwin"
|
"aarch64-darwin"
|
||||||
@@ -48,6 +48,38 @@
|
|||||||
exec docker-compose up "$@"
|
exec docker-compose up "$@"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
nativeRun = pkgs.writeShellApplication {
|
||||||
|
name = "csbi-native-run";
|
||||||
|
runtimeInputs = [
|
||||||
|
pkgs.bun
|
||||||
|
pkgs.coreutils
|
||||||
|
];
|
||||||
|
text = ''
|
||||||
|
env_file="''${CSBIE_ENV_FILE:-$PWD/.env}"
|
||||||
|
data_dir="''${CSBIE_DATA_DIR:-$PWD/data}"
|
||||||
|
|
||||||
|
if [ ! -f "$env_file" ]; then
|
||||||
|
echo "CSBIE_ENV_FILE does not exist: $env_file" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p "$data_dir"
|
||||||
|
|
||||||
|
work_dir="$(mktemp -d)"
|
||||||
|
trap 'rm -rf "$work_dir"' EXIT
|
||||||
|
|
||||||
|
source_dir="$work_dir/source"
|
||||||
|
mkdir -p "$source_dir"
|
||||||
|
cp -R --no-preserve=mode,ownership "${self}/." "$source_dir"
|
||||||
|
|
||||||
|
cd "$source_dir"
|
||||||
|
bun install --frozen-lockfile --linker hoisted
|
||||||
|
bun --filter @repo/csbie build
|
||||||
|
|
||||||
|
export CSBIE_DATABASE_PATH="''${CSBIE_DATABASE_PATH:-$data_dir/csbie.sqlite}"
|
||||||
|
exec bun --env-file="$env_file" apps/csbie/dist/index.js "$@"
|
||||||
|
'';
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
default = {
|
default = {
|
||||||
@@ -61,6 +93,13 @@
|
|||||||
program = "${composeUp}/bin/csbi-compose-up";
|
program = "${composeUp}/bin/csbi-compose-up";
|
||||||
meta.description = "Run cSBI with docker-compose";
|
meta.description = "Run cSBI with docker-compose";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
csbie = {
|
||||||
|
type = "app";
|
||||||
|
program = "${nativeRun}/bin/csbi-native-run";
|
||||||
|
meta.description = "Build and run cSBI directly with Bun";
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -68,19 +107,61 @@
|
|||||||
{
|
{
|
||||||
config,
|
config,
|
||||||
lib,
|
lib,
|
||||||
|
pkgs,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
cfg = config.services.csbie;
|
cfg = config.services.csbie;
|
||||||
|
nativeRun = pkgs.writeShellApplication {
|
||||||
|
name = "csbi-native-run";
|
||||||
|
runtimeInputs = [
|
||||||
|
pkgs.bun
|
||||||
|
pkgs.coreutils
|
||||||
|
];
|
||||||
|
text = ''
|
||||||
|
env_file="''${CSBIE_ENV_FILE:-$PWD/.env}"
|
||||||
|
data_dir="''${CSBIE_DATA_DIR:-$PWD/data}"
|
||||||
|
|
||||||
|
if [ ! -f "$env_file" ]; then
|
||||||
|
echo "CSBIE_ENV_FILE does not exist: $env_file" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p "$data_dir"
|
||||||
|
|
||||||
|
work_dir="$(mktemp -d)"
|
||||||
|
trap 'rm -rf "$work_dir"' EXIT
|
||||||
|
|
||||||
|
source_dir="$work_dir/source"
|
||||||
|
mkdir -p "$source_dir"
|
||||||
|
cp -R --no-preserve=mode,ownership "${self}/." "$source_dir"
|
||||||
|
|
||||||
|
cd "$source_dir"
|
||||||
|
bun install --frozen-lockfile --linker hoisted
|
||||||
|
bun --filter @repo/csbie build
|
||||||
|
|
||||||
|
export CSBIE_DATABASE_PATH="''${CSBIE_DATABASE_PATH:-$data_dir/csbie.sqlite}"
|
||||||
|
exec bun --env-file="$env_file" apps/csbie/dist/index.js "$@"
|
||||||
|
'';
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.services.csbie = {
|
options.services.csbie = {
|
||||||
enable = lib.mkEnableOption "cSBI";
|
enable = lib.mkEnableOption "cSBI";
|
||||||
|
|
||||||
|
runtime = lib.mkOption {
|
||||||
|
type = lib.types.enum [
|
||||||
|
"docker"
|
||||||
|
"native"
|
||||||
|
];
|
||||||
|
default = "docker";
|
||||||
|
description = "Runtime backend.";
|
||||||
|
};
|
||||||
|
|
||||||
image = lib.mkOption {
|
image = lib.mkOption {
|
||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
default = "git.yutakobayashi.com/nakasyou/csbi:latest";
|
default = "git.yutakobayashi.com/nakasyou/csbi:latest";
|
||||||
description = "Container image to run.";
|
description = "Container image to run when runtime is docker.";
|
||||||
};
|
};
|
||||||
|
|
||||||
envFile = lib.mkOption {
|
envFile = lib.mkOption {
|
||||||
@@ -101,26 +182,57 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable (lib.mkMerge [
|
||||||
virtualisation.oci-containers.backend = lib.mkDefault "docker";
|
{
|
||||||
|
systemd.tmpfiles.rules = [
|
||||||
|
"d ${cfg.dataDir} 0750 root root -"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
systemd.tmpfiles.rules = [
|
(lib.mkIf (cfg.runtime == "docker") {
|
||||||
"d ${cfg.dataDir} 0750 root root -"
|
virtualisation.oci-containers.backend = lib.mkDefault "docker";
|
||||||
];
|
virtualisation.oci-containers.containers.csbie = {
|
||||||
|
image = cfg.image;
|
||||||
|
ports = [
|
||||||
|
"${toString cfg.port}:8787"
|
||||||
|
];
|
||||||
|
environmentFiles = [
|
||||||
|
cfg.envFile
|
||||||
|
];
|
||||||
|
volumes = [
|
||||||
|
"${cfg.dataDir}:/app/data"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
})
|
||||||
|
|
||||||
virtualisation.oci-containers.containers.csbie = {
|
(lib.mkIf (cfg.runtime == "native") {
|
||||||
image = cfg.image;
|
systemd.services.csbie = {
|
||||||
ports = [
|
description = "cSBI";
|
||||||
"${toString cfg.port}:8787"
|
wantedBy = [
|
||||||
];
|
"multi-user.target"
|
||||||
environmentFiles = [
|
];
|
||||||
cfg.envFile
|
after = [
|
||||||
];
|
"network-online.target"
|
||||||
volumes = [
|
];
|
||||||
"${cfg.dataDir}:/app/data"
|
wants = [
|
||||||
];
|
"network-online.target"
|
||||||
};
|
];
|
||||||
};
|
environment = {
|
||||||
|
CSBIE_ENV_FILE = toString cfg.envFile;
|
||||||
|
CSBIE_DATA_DIR = cfg.dataDir;
|
||||||
|
PORT = toString cfg.port;
|
||||||
|
};
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "simple";
|
||||||
|
Restart = "on-failure";
|
||||||
|
RestartSec = "5s";
|
||||||
|
};
|
||||||
|
script = ''
|
||||||
|
exec ${nativeRun}/bin/csbi-native-run
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
})
|
||||||
|
]);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user