-
-
Notifications
You must be signed in to change notification settings - Fork 282
build: Add Nix/NixOS support #823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,3 +80,7 @@ web-src/geckodriver.log | |
| venv/ | ||
| /venv2/ | ||
| e2e_venv/ | ||
|
|
||
| # Nix / NixOS | ||
| /result | ||
| /*.qcow2 | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| { | ||
| 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; } { | ||
| systems = [ | ||
| "x86_64-linux" | ||
| "aarch64-linux" | ||
| "aarch64-darwin" | ||
| ]; | ||
| perSystem = | ||
| { pkgs, ... }: | ||
| { | ||
| packages = { | ||
| script-server = pkgs.python3Packages.callPackage ./nix/package.nix { }; | ||
|
|
||
| script-server-web = pkgs.callPackage ./nix/package-web.nix { }; | ||
|
|
||
| demo = self.nixosConfigurations.demo.config.system.build.vm; | ||
| }; | ||
|
|
||
| formatter = pkgs.nixfmt-tree; | ||
| }; | ||
| } | ||
| // { | ||
| overlays.default = final: prev: { | ||
| script-server = final.python3Packages.callPackage ./nix/package.nix { }; | ||
|
|
||
| script-server-web = final.callPackage ./nix/package-web.nix { }; | ||
| }; | ||
|
|
||
| nixosModules.default = import ./nix/module.nix; | ||
|
|
||
| nixosConfigurations.demo = nixpkgs.lib.nixosSystem { | ||
| modules = [ | ||
| self.nixosModules.default | ||
| { | ||
| nixpkgs = { | ||
| overlays = [ self.overlays.default ]; | ||
| hostPlatform = "x86_64-linux"; | ||
| }; | ||
|
|
||
| users.users.root.password = "changeit"; | ||
|
|
||
| services = { | ||
| script-server = { | ||
| enable = true; | ||
| }; | ||
| }; | ||
|
|
||
| system.stateVersion = "26.05"; | ||
| } | ||
| ]; | ||
| }; | ||
| }; | ||
| } |
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Defines how the script-server would be configured in NixOS. With Example: services.script-server = {
enable = true;
# Optional
settings = { }; # JSON config in Nix syntax
# Optional
configuration = "..."; # Path to `conf` / `database` folder; Default: "/var/lib/script-server/conf"
}; |
| 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-web = lib.mkOption { | ||
| type = lib.types.package; | ||
| default = pkgs.script-server-web; | ||
| description = "Script-server-web 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 = | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Settings" could be put under |
||
| 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. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From my understanding: When Instead, we call (I think this is not specific to NixOS. Packaging for e.g. Ubuntu would raise the same questions?)
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But working dir is used not only for web, is it? All other folders from the release are expected to be there |
||
| WorkingDirectory = "${cfg.package-web}"; | ||
| StateDirectory = "script-server"; | ||
| LogsDirectory = "script-server"; | ||
|
|
||
| DynamicUser = true; | ||
| PrivateTmp = true; | ||
| }; | ||
| }; | ||
| }; | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This builds/bundles the frontend. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { lib, buildNpmPackage }: | ||
| buildNpmPackage { | ||
| pname = "script-server-web"; | ||
| version = "1.18.0"; | ||
|
|
||
| src = ../web-src; | ||
|
|
||
| npmDepsHash = "sha256-aBZDh2NcDU4OpsdTS8JqwGMa8WeIoyW9I6bUwTXfllU="; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can it be automatically calculated as a result of some build tool?
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually it would be the same for "version"
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The hash ensures that we always downloaded the exact same npm dependencies. We could adapt the hash in CI when updating the deps, though, to make our life easier. But I would suggest to tackle this later. If you don't mind, I'll take care about the maintenance of the Nix support. Ideally, the files can eventually be moved into Since you seem fine with the direction, I'll try to finalize the PR soon(tm) and write a short NixOS Wiki entry.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. soon = "probably next week"; |
||
|
|
||
| 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" | ||
| cp -r ../web "$out" | ||
| ''; | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This builds the backend. |
| 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 | ||
| ]; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resultis for Nix build artifacts. There is also a qemu demo startable vianix run .#demo. Since the demo will instantiate a VM, we ignore the.qcow2hard drive, too.