-
Notifications
You must be signed in to change notification settings - Fork 2
Add Nix support #3
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
Open
rogierknoester
wants to merge
1
commit into
crosspoint-reader:main
Choose a base branch
from
rogierknoester:nix-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| { | ||
| description = "crosspoint-sync flake"; | ||
|
|
||
| inputs = { | ||
| nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; | ||
| flake-utils.url = "github:numtide/flake-utils"; | ||
| }; | ||
|
|
||
| outputs = | ||
| { | ||
| nixpkgs, | ||
| flake-utils, | ||
| ... | ||
| }: | ||
| { | ||
| nixosModules = { | ||
| crosspoint-sync = import ./nix/module.nix; | ||
| }; | ||
| } | ||
| // flake-utils.lib.eachDefaultSystem ( | ||
| system: | ||
| let | ||
| pkgs = import nixpkgs { inherit system; }; | ||
| crosspoint-sync = pkgs.callPackage ./nix/package.nix { }; | ||
| in | ||
| { | ||
| packages = { | ||
| inherit crosspoint-sync; | ||
| default = crosspoint-sync; | ||
| }; | ||
| } | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| { | ||
| pkgs, | ||
| lib, | ||
| config, | ||
| ... | ||
| }: | ||
|
|
||
| let | ||
|
|
||
| inherit (lib) | ||
| mkOption | ||
| mkEnableOption | ||
| mkIf | ||
| types | ||
| ; | ||
| cfg = config.services.crosspoint-sync; | ||
| crosspoint-sync = pkgs.callPackage ./package.nix { }; | ||
|
|
||
| filename = | ||
| types.addCheck types.str (v: v != "" && !(lib.hasInfix "/" v) && v != "." && v != "..") | ||
| // { | ||
| description = "a filename; cannot traverse directories or be an absolute path"; | ||
| }; | ||
| in | ||
| { | ||
|
|
||
| options.services.crosspoint-sync = { | ||
| enable = mkEnableOption "Enable crosspoint-sync server"; | ||
|
|
||
| port = mkOption { | ||
| type = types.port; | ||
| description = "Port to run crosspoint-sync server on"; | ||
| default = 8080; | ||
| }; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| databaseFile = mkOption { | ||
| type = filename; | ||
| description = "Filename of the SQLite database in the state directory; "; | ||
| default = "crosspoint.db"; | ||
| }; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| registration = mkOption { | ||
| type = types.bool; | ||
| description = "Have registration enabled or not"; | ||
| default = true; | ||
| }; | ||
|
|
||
| tokenEncryptionKeyFile = mkOption { | ||
| type = types.nullOr types.str; | ||
| description = "Path to the secret that contains the encryption key"; | ||
| }; | ||
|
|
||
| authRateLimit = mkOption { | ||
| type = types.int; | ||
| description = "Per-IP limit on registrations"; | ||
| default = 30; | ||
| }; | ||
|
|
||
| user = mkOption { | ||
| type = types.str; | ||
| description = "User to run crosspoint-sync with"; | ||
| default = "crosspoint-sync"; | ||
| }; | ||
|
|
||
| group = mkOption { | ||
| type = types.str; | ||
| description = "Group to run crosspoint-sync with"; | ||
| default = "crosspoint-sync"; | ||
| }; | ||
|
|
||
| }; | ||
|
|
||
| config = mkIf cfg.enable { | ||
| systemd.services.crosspoint-sync = { | ||
| description = "crosspoint-sync server"; | ||
| wantedBy = [ "multi-user.target" ]; | ||
|
|
||
| serviceConfig = { | ||
| Type = "simple"; | ||
| ExecStart = | ||
| if (cfg.tokenEncryptionKeyFile != null) then | ||
| pkgs.writeShellScript "crosspoint-sync-credential-loader" '' | ||
| export TOKEN_ENC_KEY="$(cat "$CREDENTIALS_DIRECTORY/TOKEN_ENC_KEY_FILE")" | ||
| exec ${lib.getExe crosspoint-sync} | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| '' | ||
| else | ||
| "${lib.getExe crosspoint-sync}"; | ||
| Restart = "on-failure"; | ||
|
|
||
| User = cfg.user; | ||
| Group = cfg.group; | ||
| LoadCredential = mkIf ( | ||
| cfg.tokenEncryptionKeyFile != null | ||
| ) "TOKEN_ENC_KEY_FILE:${cfg.tokenEncryptionKeyFile}"; | ||
| StateDirectory = "crosspoint-sync"; | ||
| ProtectSystem = "strict"; | ||
| ProtectHome = true; | ||
| NoNewPrivileges = true; | ||
| PrivateDevices = true; | ||
| PrivateTmp = true; | ||
| PrivateUsers = !(cfg.port < 1024); | ||
| ProtectKernelTunables = true; | ||
| ProtectKernelModules = true; | ||
| ProtectKernelLogs = true; | ||
| ProtectControlGroups = true; | ||
| ProtectClock = true; | ||
| ProtectHostname = true; | ||
| ProtectProc = "invisible"; | ||
| ProcSubset = "pid"; | ||
| RestrictNamespaces = true; | ||
| RestrictSUIDSGID = true; | ||
| LockPersonality = true; | ||
| UMask = "0077"; | ||
| RemoveIPC = true; | ||
| AmbientCapabilities = if (cfg.port < 1024) then "CAP_NET_BIND_SERVICE" else lib.mkForce ""; | ||
| CapabilityBoundingSet = if (cfg.port < 1024) then "CAP_NET_BIND_SERVICE" else lib.mkForce ""; | ||
| RestrictAddressFamilies = [ | ||
| "AF_INET" | ||
| "AF_INET6" | ||
| ]; | ||
| SystemCallFilter = [ "@system-service" ]; | ||
| SystemCallErrorNumber = "EPERM"; | ||
| RestrictRealtime = true; | ||
|
|
||
| }; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| environment = { | ||
| PORT = builtins.toString cfg.port; | ||
| DATABASE_PATH = "/var/lib/crosspoint-sync/${cfg.databaseFile}"; | ||
| REGISTRATION_DISABLED = if !cfg.registration then "true" else "false"; | ||
| AUTH_RATE_LIMIT_PER_MINUTE = builtins.toString cfg.authRateLimit; | ||
| }; | ||
|
|
||
| }; | ||
|
|
||
| networking.firewall.allowedTCPPorts = [ cfg.port ]; | ||
|
|
||
| users = { | ||
| users.crosspoint-sync = mkIf (cfg.user == "crosspoint-sync") { | ||
| description = "crosspoint-sync service user"; | ||
| isSystemUser = true; | ||
| group = cfg.group; | ||
| }; | ||
|
|
||
| groups.crosspoint-sync = mkIf (cfg.group == "crosspoint-sync") { }; | ||
| }; | ||
|
|
||
| }; | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| { pkgs, lib }: | ||
|
|
||
| with pkgs; | ||
| buildNpmPackage { | ||
| pname = "crosspoint-sync"; | ||
| version = "git"; | ||
| src = ../.; | ||
|
|
||
| npmDeps = importNpmLock { | ||
| npmRoot = ../.; | ||
| }; | ||
|
|
||
| npmConfigHook = importNpmLock.npmConfigHook; | ||
|
|
||
| buildPhase = '' | ||
| npm run build | ||
| ''; | ||
|
|
||
| installPhase = '' | ||
| runHook preInstall | ||
| mkdir -p $out/lib $out/bin | ||
| cp -r package.json dist node_modules assets migrations $out/lib/ | ||
| makeWrapper ${lib.getExe nodejs} $out/bin/crosspoint-sync \ | ||
| --add-flags "$out/lib/dist/index.js" | ||
| runHook postInstall | ||
| ''; | ||
|
|
||
| nativeBuildInputs = [ pkgs.makeWrapper ]; | ||
|
|
||
| meta = { | ||
| description = "Lightweight KoSync Server for Syncing Crosspoint/CrossInk stats & progress"; | ||
| homepage = "https://github.com/crosspoint-reader/crosspoint-sync"; | ||
| mainProgram = "crosspoint-sync"; | ||
| }; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.