Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,7 @@ web-src/geckodriver.log
venv/
/venv2/
e2e_venv/

# Nix / NixOS
Comment thread
duesee marked this conversation as resolved.
/result
/*.qcow2
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
description = "Script-server";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/26.05";

flake-parts.url = "github:hercules-ci/flake-parts";
};

outputs =
inputs@{
self,
nixpkgs,
flake-parts,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } {
flake = {
overlays.default = final: prev: {
script-server = final.python3Packages.callPackage ./nix/package.nix { };

script-server-dist = final.callPackage ./nix/package-dist.nix { };
};

nixosModules.default = import ./nix/module.nix;
};

systems = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
];

perSystem =
{ pkgs, ... }:
{
packages = {
script-server = pkgs.python3Packages.callPackage ./nix/package.nix { };

script-server-dist = pkgs.callPackage ./nix/package-dist.nix { };
};

formatter = pkgs.nixfmt-tree;
};
};
}
75 changes: 75 additions & 0 deletions nix/module.nix
Comment thread
duesee marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
config,
pkgs,
lib,
...
}:
let
cfg = config.services.script-server;
json = pkgs.formats.json { };
in
{
options.services.script-server = {
enable = lib.mkEnableOption "Whether to enable script-server.";

package = lib.mkOption {
type = lib.types.package;
default = pkgs.script-server;
description = "Script-server package to use.";
};

package-dist = lib.mkOption {
type = lib.types.package;
default = pkgs.script-server-dist;
description = "Script-server-dist package to use.";
};

settings = lib.mkOption {
type = json.type;
default = { };
description = "Server configuration, see <https://github.com/bugy/script-server/wiki/Server-configuration>.";
};

configuration = lib.mkOption {
type = lib.types.str;
default = "/var/lib/script-server/conf";
description = "Script configuration, see <https://github.com/bugy/script-server/wiki/Script-config>.";
};
};

config = lib.mkIf cfg.enable {
environment.systemPackages = [ cfg.package ];

environment.etc."script-server/conf.json".source =
Comment thread
duesee marked this conversation as resolved.
json.generate "script-server-config" cfg.settings;

# See <https://github.com/bugy/script-server/wiki/Running-as-a-linux-service#systemd>
systemd.services.script-server = {
enable = true;

description = "Script Server";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];

serviceConfig = {
Restart = "always";
RestartSec = "1s";
ExecStart = ''
${cfg.package}/bin/script-server \
--config-file /etc/script-server/conf.json \
--config-dir ${cfg.configuration} \
--log-folder /var/log/script-server \
--tmp-folder /tmp
'';

# `main.py` expects `web` to be in working directory.
Comment thread
duesee marked this conversation as resolved.
WorkingDirectory = "${cfg.package-dist}";
StateDirectory = "script-server";
LogsDirectory = "script-server";

DynamicUser = true;
PrivateTmp = true;
};
};
};
}
23 changes: 23 additions & 0 deletions nix/package-dist.nix
Comment thread
duesee marked this conversation as resolved.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed script-server-web to script-server-dist and it now auto-generates the version.txt. This way, the version is also showed correctly.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{ lib, buildNpmPackage }:
let
version = "1.18.0";
in
buildNpmPackage {
pname = "script-server-dist";
inherit version;

src = ../web-src;

npmDepsHash = "sha256-aBZDh2NcDU4OpsdTS8JqwGMa8WeIoyW9I6bUwTXfllU=";
Comment thread
duesee marked this conversation as resolved.

makeCacheWritable = true;

# See <https://stackoverflow.com/questions/75959563/node-js-err-ossl-evp-unsupported-error-when-running-npm-run-start>
NODE_OPTIONS = "--openssl-legacy-provider";

installPhase = ''
mkdir "$out"
echo '${version}' > "$out/version.txt"
cp -r ../web "$out"
'';
}
30 changes: 30 additions & 0 deletions nix/package.nix
Comment thread
duesee marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
let
toml = builtins.fromTOML (builtins.readFile ./../pyproject.toml);
in
{
lib,
buildPythonPackage,
tornado,
setuptools,
}:
buildPythonPackage {
pname = toml.project.name;
version = toml.project.version;
pyproject = true;

src = lib.fileset.toSource {
root = ./..;
fileset = lib.fileset.unions [
./../pyproject.toml
./../src
];
};

build-system = [
setuptools
];

dependencies = [
tornado
];
}