From 32b2b27509685655197b3d2b3cee80358d2cd905 Mon Sep 17 00:00:00 2001 From: Nico Jensch Date: Wed, 27 Sep 2023 08:37:45 +0200 Subject: [PATCH 1/7] feat: add flake.nix to allow building NixOS packages --- flake.lock | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 51 +++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..2d1b886 --- /dev/null +++ b/flake.lock @@ -0,0 +1,94 @@ +{ + "nodes": { + "naersk": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1694081375, + "narHash": "sha256-vzJXOUnmkMCm3xw8yfPP5m8kypQ3BhAIRe4RRCWpzy8=", + "owner": "nix-community", + "repo": "naersk", + "rev": "3f976d822b7b37fc6fb8e6f157c2dd05e7e94e89", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "master", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1695318763, + "narHash": "sha256-FHVPDRP2AfvsxAdc+AsgFJevMz5VBmnZglFUMlxBkcY=", + "path": "/nix/store/p7iz0r8gs6ppkhj83zjmwyd21k8b7v3y-source", + "rev": "e12483116b3b51a185a33a272bf351e357ba9a99", + "type": "path" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1695318763, + "narHash": "sha256-FHVPDRP2AfvsxAdc+AsgFJevMz5VBmnZglFUMlxBkcY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e12483116b3b51a185a33a272bf351e357ba9a99", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "naersk": "naersk", + "nixpkgs": "nixpkgs_2", + "utils": "utils" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..d7fb5f9 --- /dev/null +++ b/flake.nix @@ -0,0 +1,51 @@ +{ + # Websurfx NixOS flake + inputs = { + naersk.url = "github:nix-community/naersk/master"; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + utils.url = "github:numtide/flake-utils"; + }; + + outputs = { + naersk, + nixpkgs, + self, + utils, + }: + # We do this for all systems - namely x86_64-linux, aarch64-linux, + # x86_64-darwin and aarch64-darwin + utils.lib.eachDefaultSystem (system: let + pkgs = import nixpkgs {inherit system;}; + naersk-lib = pkgs.callPackage naersk {}; + in rec { + # Build via nix build .#defaultPackage.x86_64-linux + defaultPackage = naersk-lib.buildPackage { + # The build dependencies + buildInputs = with pkgs; [pkg-config openssl]; + src = ./.; + }; + + # Enter devshell with all the tools via "nix develop" + # or "nix-shell" + devShell = with pkgs; + mkShell { + buildInputs = [ + actionlint + cargo + haskellPackages.hadolint + nodePackages_latest.cspell + nodePackages_latest.eslint + nodePackages_latest.markdownlint-cli2 + nodePackages_latest.stylelint + nodePackages_latest.stylelint + rustPackages.clippy + rustc + yamllint + ]; + RUST_SRC_PATH = rustPlatform.rustLibSrc; + }; + + # Build via "nix build .#websurfx.x86_64-linux" + websurfx = defaultPackage; + }); +} From ba4c3b061226e7d951eaa93f5c82c8535e086afc Mon Sep 17 00:00:00 2001 From: Nico Jensch Date: Wed, 27 Sep 2023 09:04:36 +0200 Subject: [PATCH 2/7] fix: pass nix flake check; ignore result --- .gitignore | 11 ++++++----- flake.nix | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 5889518..2ab2745 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ -/target -package.json -package-lock.json -dump.rdb .vscode -megalinter-reports/ +/target dhat-heap.json +dump.rdb +megalinter-reports/ +package-lock.json +package.json +result \ No newline at end of file diff --git a/flake.nix b/flake.nix index d7fb5f9..35bd6f1 100644 --- a/flake.nix +++ b/flake.nix @@ -19,7 +19,7 @@ naersk-lib = pkgs.callPackage naersk {}; in rec { # Build via nix build .#defaultPackage.x86_64-linux - defaultPackage = naersk-lib.buildPackage { + packages.default = naersk-lib.buildPackage { # The build dependencies buildInputs = with pkgs; [pkg-config openssl]; src = ./.; @@ -27,7 +27,7 @@ # Enter devshell with all the tools via "nix develop" # or "nix-shell" - devShell = with pkgs; + devShells.default = with pkgs; mkShell { buildInputs = [ actionlint @@ -46,6 +46,6 @@ }; # Build via "nix build .#websurfx.x86_64-linux" - websurfx = defaultPackage; + packages.websurfx = packages.default; }); } From 47bbbcd3c47c114b5b12f544f4bc1e347dfac0e3 Mon Sep 17 00:00:00 2001 From: Nico Jensch Date: Wed, 27 Sep 2023 09:07:33 +0200 Subject: [PATCH 3/7] docs: add NixOS installation --- docs/installation.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/docs/installation.md b/docs/installation.md index 9bd4ec0..3a48e38 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -162,4 +162,41 @@ cd websurfx git checkout stable ``` +## NixOS + +A flake.nix has been provided to allow installing `Websurfx` easily. It utilizes [nearsk](https://github.com/nix-community/naersk) to automatically generate a derivation based on `Cargo.toml` and `Cargo.lock`. + +The flake has several outputs, which may be consumed: + +~~~bash +nix build .#websurfx +nix run .#websurfx +~~~ + +You may include it in your own flake by adding this repo to its inputs and adding it to `environment.systemPackages` + +~~~nix +{ + description = "My configuration"; + + inputs = { + websurfx.url = "github:neon-mmd/websurfx"; + }; + + outputs = { nixpkgs, ... }@inputs: { + nixosConfigurations = { + hostname = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [{ + environment.systemPackages = [ + inputs.websurfx.websurfx + ]; + }]; + }; + }; + }; +} + +~~~ + [⬅️ Go back to Home](./README.md) From bf0a22ccde3ab98b0db973eae55b47a70a06dd78 Mon Sep 17 00:00:00 2001 From: Nico Jensch Date: Wed, 27 Sep 2023 14:22:55 +0200 Subject: [PATCH 4/7] docs: apply suggestion and move information next to Archlinux, provide working example --- docs/installation.md | 71 +++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 37 deletions(-) diff --git a/docs/installation.md b/docs/installation.md index 3a48e38..db79131 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -19,6 +19,40 @@ Once you have started the server, open your preferred web browser and navigate t If you want to change the port or the ip or any other configuration setting checkout the [configuration docs](./configuration.md). +## NixOS + +A `flake.nix` has been provided to allow installing `websurfx` easily. It utilizes [nearsk](https://github.com/nix-community/naersk) to automatically generate a derivation based on `Cargo.toml` and `Cargo.lock`. + +The flake has several outputs, which may be consumed: + +```bash +nix build .#websurfx +nix run .#websurfx +``` + +You may include it in your own flake by adding this repo to its inputs and adding it to `environment.systemPackages` as follows: + +```nix +{ + description = "My awesome configuration"; + + inputs = { + websurfx.url = "github:neon-mmd/websurfx"; + }; + + outputs = { nixpkgs, ... }@inputs: { + nixosConfigurations = { + hostname = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [{ + environment.systemPackages = [inputs.websurfx.packages.x86_64-linux.websurfx]; + }]; + }; + }; + }; +} +``` + ## Other Distros The package is currently not available on other Linux distros. With contribution and support it can be made available on other distros as well 🙂. @@ -162,41 +196,4 @@ cd websurfx git checkout stable ``` -## NixOS - -A flake.nix has been provided to allow installing `Websurfx` easily. It utilizes [nearsk](https://github.com/nix-community/naersk) to automatically generate a derivation based on `Cargo.toml` and `Cargo.lock`. - -The flake has several outputs, which may be consumed: - -~~~bash -nix build .#websurfx -nix run .#websurfx -~~~ - -You may include it in your own flake by adding this repo to its inputs and adding it to `environment.systemPackages` - -~~~nix -{ - description = "My configuration"; - - inputs = { - websurfx.url = "github:neon-mmd/websurfx"; - }; - - outputs = { nixpkgs, ... }@inputs: { - nixosConfigurations = { - hostname = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = [{ - environment.systemPackages = [ - inputs.websurfx.websurfx - ]; - }]; - }; - }; - }; -} - -~~~ - [⬅️ Go back to Home](./README.md) From 838d0fd76abd8d549a7888870f00c5c5a517cae2 Mon Sep 17 00:00:00 2001 From: Nico Jensch Date: Wed, 27 Sep 2023 14:23:27 +0200 Subject: [PATCH 5/7] feat: add redis to devshell, fix comments --- flake.nix | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 35bd6f1..6c30713 100644 --- a/flake.nix +++ b/flake.nix @@ -18,7 +18,7 @@ pkgs = import nixpkgs {inherit system;}; naersk-lib = pkgs.callPackage naersk {}; in rec { - # Build via nix build .#defaultPackage.x86_64-linux + # Build via "nix build .#default" packages.default = naersk-lib.buildPackage { # The build dependencies buildInputs = with pkgs; [pkg-config openssl]; @@ -37,7 +37,7 @@ nodePackages_latest.eslint nodePackages_latest.markdownlint-cli2 nodePackages_latest.stylelint - nodePackages_latest.stylelint + redis rustPackages.clippy rustc yamllint @@ -45,7 +45,8 @@ RUST_SRC_PATH = rustPlatform.rustLibSrc; }; - # Build via "nix build .#websurfx.x86_64-linux" + # Build via "nix build .#websurfx", which is basically just + # calls the build function packages.websurfx = packages.default; }); } From 3cc4d1784a574e698655df147c1a172c05e26897 Mon Sep 17 00:00:00 2001 From: Nico Jensch Date: Wed, 27 Sep 2023 14:25:05 +0200 Subject: [PATCH 6/7] version: 0.23.5 -> 0.23.6 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index d9f386e..f1b3934 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "websurfx" -version = "0.23.5" +version = "0.23.6" edition = "2021" description = "An open-source alternative to Searx that provides clean, ad-free, and organic results with incredible speed while keeping privacy and security in mind." repository = "https://github.com/neon-mmd/websurfx" From d900baddabd3fdfd2648cda852034b9c3f09ac7d Mon Sep 17 00:00:00 2001 From: Evan Yang Date: Wed, 27 Sep 2023 10:20:56 -0700 Subject: [PATCH 7/7] feat: olumes for docker deployment to make editing config files easier --- Dockerfile | 4 +--- docker-compose.yml | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index f779730..c1bdd63 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,8 +21,6 @@ RUN cargo install --path . # We do not need the Rust toolchain to run the binary! FROM gcr.io/distroless/cc-debian12 COPY --from=builder /app/public/ /opt/websurfx/public/ -COPY --from=builder /app/websurfx/config.lua /etc/xdg/websurfx/config.lua -COPY --from=builder /app/websurfx/allowlist.txt /etc/xdg/websurfx/allowlist.txt -COPY --from=builder /app/websurfx/blocklist.txt /etc/xdg/websurfx/blocklist.txt +VOLUME ["/etc/xdg/websurfx/"] COPY --from=builder /usr/local/cargo/bin/* /usr/local/bin/ CMD ["websurfx"] diff --git a/docker-compose.yml b/docker-compose.yml index aed741e..5cf7383 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,6 +10,9 @@ services: - redis links: - redis + volumes: + - ./websurfx/:/etc/xdg/websurfx/ + - ./public/:/opt/websurfx/public/ redis: image: redis:latest ports: