From 965c5428a0ac58d72f80ee7f071e854daf271d7e Mon Sep 17 00:00:00 2001 From: Finn Behrens Date: Wed, 22 Sep 2021 19:15:57 +0200 Subject: [PATCH 1/6] add nix flake Signed-off-by: Finn Behrens --- .gitignore | 1 + flake.lock | 25 +++++++++++++++++++++++++ flake.nix | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitignore b/.gitignore index 3a0388c..81a689c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ kalk/Cargo.lock cli/Cargo.lock cli/test .vscode/ +result* diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..4fb93ff --- /dev/null +++ b/flake.lock @@ -0,0 +1,25 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1632255010, + "narHash": "sha256-p/BYR6qhbCtDpOfw9uMYwjwyhuCVKgiSUpKZaV/63UE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "bfc38d3d0d22c528e8abc46c5dd5f3f50fc4554b", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..58b60c2 --- /dev/null +++ b/flake.nix @@ -0,0 +1,55 @@ +{ + description = "A very basic flake"; + + outputs = { self, nixpkgs }: + let + systems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + #"aarch64-darwin" # currently not building due to gmp + ]; + + forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f system); + + nixpkgsFor = forAllSystems (system: + import nixpkgs { + inherit system; + overlays = [ self.overlay ]; + }); + in { + overlay = final: prev: { + kalker = final.rustPlatform.buildRustPackage { + pname = "kalker"; + version = "unstable"; + + src = self; + + nativeBuildInputs = with final; [ m4 ]; + + outputs = [ "out" "lib" ]; + + postInstall = '' + moveToOutput "lib" "$lib" + ''; + + cargoLock = { lockFile = self + "/Cargo.lock"; }; + + } + # FIXME: fix aarch64-darwin builds + /* // (if (final.stdenv.isDarwin && final.stdenv.isAarch64) then { + CARGO_FEATURE_USE_SYSTEM_LIBS = "1"; + RUST_BACKTRACE = "1"; + buildInputs = with final; [ gmp mpfr libmpc ]; + } else + { }) + */ + ; + }; + + packages = forAllSystems (system: nixpkgsFor.${system}); + + defaultPackage = forAllSystems (system: self.packages.${system}.kalker); + + }; +} From 9cda37ce536f326eabc31d3aea1ff14ed4060777 Mon Sep 17 00:00:00 2001 From: Finn Behrens Date: Wed, 22 Sep 2021 21:19:47 +0200 Subject: [PATCH 2/6] fix aarch64-darwin flake Signed-off-by: Finn Behrens --- flake.nix | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/flake.nix b/flake.nix index 58b60c2..0c8cc36 100644 --- a/flake.nix +++ b/flake.nix @@ -1,14 +1,10 @@ { - description = "A very basic flake"; + description = "A calculator program/website"; outputs = { self, nixpkgs }: let - systems = [ - "x86_64-linux" - "aarch64-linux" - "x86_64-darwin" - #"aarch64-darwin" # currently not building due to gmp - ]; + systems = + [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f system); @@ -25,7 +21,7 @@ src = self; - nativeBuildInputs = with final; [ m4 ]; + nativeBuildInputs = with final; [ gcc ]; outputs = [ "out" "lib" ]; @@ -35,21 +31,14 @@ cargoLock = { lockFile = self + "/Cargo.lock"; }; - } - # FIXME: fix aarch64-darwin builds - /* // (if (final.stdenv.isDarwin && final.stdenv.isAarch64) then { - CARGO_FEATURE_USE_SYSTEM_LIBS = "1"; - RUST_BACKTRACE = "1"; - buildInputs = with final; [ gmp mpfr libmpc ]; - } else - { }) - */ - ; + buildInputs = with final; [ gmp mpfr libmpc ]; + + CARGO_FEATURE_USE_SYSTEM_LIBS = "1"; + }; }; packages = forAllSystems (system: nixpkgsFor.${system}); defaultPackage = forAllSystems (system: self.packages.${system}.kalker); - }; } From 03bc223b644ea39711542dfdecb5894688081e90 Mon Sep 17 00:00:00 2001 From: Finn Behrens Date: Wed, 22 Sep 2021 21:22:21 +0200 Subject: [PATCH 3/6] add nix flake app Signed-off-by: Finn Behrens --- flake.nix | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/flake.nix b/flake.nix index 0c8cc36..6180d28 100644 --- a/flake.nix +++ b/flake.nix @@ -40,5 +40,14 @@ packages = forAllSystems (system: nixpkgsFor.${system}); defaultPackage = forAllSystems (system: self.packages.${system}.kalker); + + apps = forAllSystems (system: { + kalker = { + type = "app"; + program = "${self.packages.${system}.kalker}/bin/kalker"; + }; + }); + + defaultApp = forAllSystems (system: self.apps.${system}.kalker); }; } From 967b9f372b8967d1184e0796562b31d42ec0ddaf Mon Sep 17 00:00:00 2001 From: PaddiM8 Date: Wed, 22 Sep 2021 23:37:46 +0200 Subject: [PATCH 4/6] Fixed broken link in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 382882a..0ce4ec6 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Kalker (or "kalk") is a calculator program/website that supports user-defined va * Operators: `+`, `-`, `*`, `/`, `!` * Groups: `()`, `⌈ceil⌉`, `⌊floor⌋`, `[iverson]` -* [Pre-defined functions and constants](https://github.com/PaddiM8/kalker/blob/master/kalk/src/prelude.rs) +* [Pre-defined functions and constants](https://github.com/PaddiM8/kalker/blob/master/kalk/src/prelude/mod.rs) * User-defined functions and variables. `f(x, y) = xy`, `x = 5` * Derivative of functions (derivatives of noisy functions or of higher order can be a bit inaccurate). `f'(2)`, `sin'(-pi)` * Integration. `∫(0, pi, sin(x) dx)` or `∫(0, π, sin(x) dx)`, maybe sometimes be slightly off From df22878060370ca81917c0e34f21c1060c22eeb4 Mon Sep 17 00:00:00 2001 From: Finn Behrens Date: Thu, 23 Sep 2021 12:37:08 +0200 Subject: [PATCH 5/6] fix flake packages attribute --- flake.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 6180d28..c28ccc3 100644 --- a/flake.nix +++ b/flake.nix @@ -37,7 +37,8 @@ }; }; - packages = forAllSystems (system: nixpkgsFor.${system}); + packages = + forAllSystems (system: { inherit (nixpkgsFor.${system}) kalker; }); defaultPackage = forAllSystems (system: self.packages.${system}.kalker); From 4c7066299227025efefb696ccb54589792464bbb Mon Sep 17 00:00:00 2001 From: Finn Behrens Date: Thu, 23 Sep 2021 12:45:25 +0200 Subject: [PATCH 6/6] update gmp-mpfr-sys to fix non gcc builds --- Cargo.lock | 5 ++--- Cargo.toml | 3 +++ flake.nix | 10 +++++++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 49401c9..603173c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -152,9 +152,8 @@ dependencies = [ [[package]] name = "gmp-mpfr-sys" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a57fdb339d49833021b1fded600ed240ae907e33909d5511a61dff884df7f16e" +version = "1.4.7" +source = "git+https://gitlab.com/tspiteri/gmp-mpfr-sys.git#21966f4bfb56c87d407eb14c72e92ef4e55856aa" dependencies = [ "libc", "winapi", diff --git a/Cargo.toml b/Cargo.toml index ed4a5eb..3b2e286 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,6 @@ +[patch.crates-io] +gmp-mpfr-sys = { git = "https://gitlab.com/tspiteri/gmp-mpfr-sys.git" } + [workspace] members = ["kalk", "cli"] diff --git a/flake.nix b/flake.nix index 6180d28..14f98ec 100644 --- a/flake.nix +++ b/flake.nix @@ -21,15 +21,19 @@ src = self; - nativeBuildInputs = with final; [ gcc ]; - outputs = [ "out" "lib" ]; postInstall = '' moveToOutput "lib" "$lib" ''; - cargoLock = { lockFile = self + "/Cargo.lock"; }; + cargoLock = { + lockFile = self + "/Cargo.lock"; + outputHashes = { + "gmp-mpfr-sys-1.4.7" = + "sha256-zHpGbEgh3MgAUVdlWrXq4Clj1boybi6DMOcsjgZbAh0="; + }; + }; buildInputs = with final; [ gmp mpfr libmpc ];