From 3eeb585d0bfefba2011a5161162dd51df6503411 Mon Sep 17 00:00:00 2001 From: siddhantCodes Date: Thu, 19 Oct 2023 22:50:22 +0530 Subject: [PATCH 1/4] add nix support --- README.md | 28 ++++++++++++++ flake.lock | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 62 ++++++++++++++++++++++++++++++ 3 files changed, 201 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/README.md b/README.md index 2da68ea2b6..fac5850f5d 100644 --- a/README.md +++ b/README.md @@ -219,6 +219,34 @@ We also offer our own hosting solution for your static and dynamic sites. Using managed hosting solution, that a non programmers can use with ease. +## Usage with Nix + +```sh +nix run github:fastn-stack/fastn +``` + +In a `flake.nix` file: + +```Nix +{ + inputs = { + flake-utils.url = "github:numtide/flake-utils"; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + fastn.url = "github:fastn-stack/fastn"; + }; + + outputs = { self, flake-utils, nixpkgs, fastn }: + flake-utils.lib.eachDefaultSystem (system: + rec { + # nix develop + devShell = pkgs.mkShell { + nativeBuildInputs = [ fastn ]; + }; + } + ); +} +``` + ## Contributors diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000000..57de9e3c0f --- /dev/null +++ b/flake.lock @@ -0,0 +1,111 @@ +{ + "nodes": { + "flake-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" + } + }, + "naersk": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1697664192, + "narHash": "sha256-nRTG3rYEGFV2+putRiC96+kNXDyKaPJgT6K/1FWN7yo=", + "owner": "nix-community", + "repo": "naersk", + "rev": "636a9b5dd7f2ad7d7c3af929ecf95e4d4fab9e97", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1683236849, + "narHash": "sha256-Y7PNBVLOBvZrmrFmHgXUBUA1lM72tl6JGIn1trOeuyE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "374ffe54403c3c42d97a513ac7a14ce1b5b86e30", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs-mozilla": { + "flake": false, + "locked": { + "lastModified": 1695805681, + "narHash": "sha256-1ElPLD8eFfnuIk0G52HGGpRtQZ4QPCjChRlEOfkZ5ro=", + "owner": "mozilla", + "repo": "nixpkgs-mozilla", + "rev": "6eabade97bc28d707a8b9d82ad13ef143836736e", + "type": "github" + }, + "original": { + "owner": "mozilla", + "repo": "nixpkgs-mozilla", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1697660476, + "narHash": "sha256-w5/4HKG6/TPOFUki4rYUbME8zC6+suT6hSunyFD4BlI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "964a525d67348323be4fa100345d37b361ebd36e", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "naersk": "naersk", + "nixpkgs": "nixpkgs_2", + "nixpkgs-mozilla": "nixpkgs-mozilla" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000000..d6088e99b0 --- /dev/null +++ b/flake.nix @@ -0,0 +1,62 @@ +{ + inputs = { + flake-utils.url = "github:numtide/flake-utils"; + + naersk.url = "github:nix-community/naersk"; + + nixpkgs-mozilla = { + url = "github:mozilla/nixpkgs-mozilla"; + flake = false; + }; + + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + }; + + outputs = { self, flake-utils, nixpkgs, nixpkgs-mozilla, naersk }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = (import nixpkgs) { + inherit system; + + overlays = [ + (import nixpkgs-mozilla) + ]; + }; + + toolchain = (pkgs.rustChannelOf { + rustToolchain = ./rust-toolchain; + sha256 = "sha256-Q9UgzzvxLi4x9aWUJTn+/5EXekC98ODRU1TwhUs9RnY="; + }).rust; + + naersk' = pkgs.callPackage naersk { + cargo = toolchain; + rustc = toolchain; + }; + + fastnp = naersk'.buildPackage { + name = "fastn"; + version = "0.3.0"; + src = ./.; + + nativeBuildInputs = with pkgs; [ pkg-config openssl.dev ]; + }; + in + rec { + # For `nix build` & `nix run`: + defaultPackage = fastnp; + + packages = { + fastn = fastnp; + }; + + # nix develop + devShell = pkgs.mkShell { + nativeBuildInputs = [ toolchain pkgs.pkg-config pkgs.openssl.dev ]; + }; + + formatter = pkgs.nixpkgs-fmt; + } + ); +} + From 11af173f8de3dcce1dad591912742393fa1f5865 Mon Sep 17 00:00:00 2001 From: siddhantCodes Date: Thu, 19 Oct 2023 23:04:58 +0530 Subject: [PATCH 2/4] bump rust-toolchain in flake.nix to 1.73 --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index d6088e99b0..be326f2781 100644 --- a/flake.nix +++ b/flake.nix @@ -26,7 +26,7 @@ toolchain = (pkgs.rustChannelOf { rustToolchain = ./rust-toolchain; - sha256 = "sha256-Q9UgzzvxLi4x9aWUJTn+/5EXekC98ODRU1TwhUs9RnY="; + sha256 = "sha256-rLP8+fTxnPHoR96ZJiCa/5Ans1OojI7MLsmSqR2ip8o="; }).rust; naersk' = pkgs.callPackage naersk { From c4eb04a463c73112aeaadd86f9c193334b657c32 Mon Sep 17 00:00:00 2001 From: siddhantCodes Date: Sun, 22 Oct 2023 18:54:58 +0530 Subject: [PATCH 3/4] remove nixpkgs-mozilla in favour of rust-overlay and mac support - mac support requires testing! - use lib.cleanSource to stop unnecessary nix builds - rename `fastnp` to fastn --- .gitignore | 3 ++ flake.lock | 80 ++++++++++++++++++++++++++++++++++++++++++++---------- flake.nix | 34 +++++++++++------------ 3 files changed, 86 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index 215776a56c..a2e8d54929 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,9 @@ ftd/t/js/**.manual.html ftd/t/js/**.script.html +# nix symlink to the build output +result + # Rust stuff target **/*.rs.bk diff --git a/flake.lock b/flake.lock index 57de9e3c0f..49f5c88d53 100644 --- a/flake.lock +++ b/flake.lock @@ -18,6 +18,24 @@ "type": "github" } }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1681202837, + "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "naersk": { "inputs": { "nixpkgs": "nixpkgs" @@ -50,29 +68,29 @@ "type": "indirect" } }, - "nixpkgs-mozilla": { - "flake": false, + "nixpkgs_2": { "locked": { - "lastModified": 1695805681, - "narHash": "sha256-1ElPLD8eFfnuIk0G52HGGpRtQZ4QPCjChRlEOfkZ5ro=", - "owner": "mozilla", - "repo": "nixpkgs-mozilla", - "rev": "6eabade97bc28d707a8b9d82ad13ef143836736e", + "lastModified": 1697660476, + "narHash": "sha256-w5/4HKG6/TPOFUki4rYUbME8zC6+suT6hSunyFD4BlI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "964a525d67348323be4fa100345d37b361ebd36e", "type": "github" }, "original": { - "owner": "mozilla", - "repo": "nixpkgs-mozilla", + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", "type": "github" } }, - "nixpkgs_2": { + "nixpkgs_3": { "locked": { - "lastModified": 1697660476, - "narHash": "sha256-w5/4HKG6/TPOFUki4rYUbME8zC6+suT6hSunyFD4BlI=", + "lastModified": 1681358109, + "narHash": "sha256-eKyxW4OohHQx9Urxi7TQlFBTDWII+F+x2hklDOQPB50=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "964a525d67348323be4fa100345d37b361ebd36e", + "rev": "96ba1c52e54e74c3197f4d43026b3f3d92e83ff9", "type": "github" }, "original": { @@ -87,7 +105,26 @@ "flake-utils": "flake-utils", "naersk": "naersk", "nixpkgs": "nixpkgs_2", - "nixpkgs-mozilla": "nixpkgs-mozilla" + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1697854201, + "narHash": "sha256-H+0Wb20PQx/8N7X/OfwwAVPeN9TbfjcyG0sXbdgsh50=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "6e8e3332433847cd56186b1f6fc8c47603cf5b46", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" } }, "systems": { @@ -104,6 +141,21 @@ "repo": "default", "type": "github" } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index be326f2781..0d28434bf1 100644 --- a/flake.nix +++ b/flake.nix @@ -4,50 +4,50 @@ naersk.url = "github:nix-community/naersk"; - nixpkgs-mozilla = { - url = "github:mozilla/nixpkgs-mozilla"; - flake = false; - }; + rust-overlay.url = "github:oxalica/rust-overlay"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - }; - outputs = { self, flake-utils, nixpkgs, nixpkgs-mozilla, naersk }: + outputs = { self, flake-utils, nixpkgs, rust-overlay, naersk }: flake-utils.lib.eachDefaultSystem (system: let pkgs = (import nixpkgs) { inherit system; overlays = [ - (import nixpkgs-mozilla) + (import rust-overlay) ]; }; - toolchain = (pkgs.rustChannelOf { - rustToolchain = ./rust-toolchain; - sha256 = "sha256-rLP8+fTxnPHoR96ZJiCa/5Ans1OojI7MLsmSqR2ip8o="; - }).rust; + toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain; naersk' = pkgs.callPackage naersk { cargo = toolchain; rustc = toolchain; }; - fastnp = naersk'.buildPackage { + cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); + + fastn = naersk'.buildPackage { name = "fastn"; - version = "0.3.0"; - src = ./.; + version = cargoToml.workspace.package.version; + src = pkgs.lib.cleanSource ./.; + + nativeBuildInputs = with pkgs; [ + pkg-config + openssl.dev + ] ++ lib.optionals stdenv.isDarwin [ xcbuild ]; - nativeBuildInputs = with pkgs; [ pkg-config openssl.dev ]; + buildInput = with pkgs; lib.optionals stdenv.isDarwin [ darwin.Security ]; }; in rec { # For `nix build` & `nix run`: - defaultPackage = fastnp; + defaultPackage = fastn; packages = { - fastn = fastnp; + inherit fastn; }; # nix develop From f5cd94c8f58879e6d13524a61602a21ba661e42f Mon Sep 17 00:00:00 2001 From: siddhantCodes Date: Mon, 23 Oct 2023 16:58:33 +0530 Subject: [PATCH 4/4] fix for mac --- flake.nix | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 0d28434bf1..2889d81bf9 100644 --- a/flake.nix +++ b/flake.nix @@ -39,7 +39,9 @@ openssl.dev ] ++ lib.optionals stdenv.isDarwin [ xcbuild ]; - buildInput = with pkgs; lib.optionals stdenv.isDarwin [ darwin.Security ]; + buildInputs = with pkgs; lib.optionals stdenv.isDarwin [ + darwin.apple_sdk.frameworks.SystemConfiguration + ]; }; in rec { @@ -52,7 +54,12 @@ # nix develop devShell = pkgs.mkShell { + name = "fastn-shell"; nativeBuildInputs = [ toolchain pkgs.pkg-config pkgs.openssl.dev ]; + + shellHook = '' + export PATH="$PATH:$HOME/.cargo/bin" + ''; }; formatter = pkgs.nixpkgs-fmt;