From 7270f1c7a3b2c85b4e6edb1e0818003d0990b08b Mon Sep 17 00:00:00 2001 From: anirudhb Date: Sat, 11 Sep 2021 16:53:49 -0700 Subject: [PATCH 1/2] Use rust2nix Build crates separately :) --- flake.lock | 62 +++++++++++++++++++++++------------------------ flake.nix | 70 +++++++++++++----------------------------------------- 2 files changed, 47 insertions(+), 85 deletions(-) diff --git a/flake.lock b/flake.lock index 72e1f88..5ec32ed 100644 --- a/flake.lock +++ b/flake.lock @@ -8,11 +8,11 @@ "rust-analyzer-src": "rust-analyzer-src" }, "locked": { - "lastModified": 1630722530, - "narHash": "sha256-E+t8tCzwa59DNUWZuDRxIwgDrGCC3Ju0LoU1Sx5TUrM=", + "lastModified": 1631327238, + "narHash": "sha256-ZUvHDxlIBTfp/058duvkXklEnLTpT1cBKH6VlqmKfDY=", "owner": "nix-community", "repo": "fenix", - "rev": "4ec3af9ff5455d2973308522c0e60459ea6bb675", + "rev": "7ffdfe27c597daa0a255a2ecdd867d0b5c3582fd", "type": "github" }, "original": { @@ -36,33 +36,13 @@ "type": "github" } }, - "naersk": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1629707199, - "narHash": "sha256-sGxlmfp5eXL5sAMNqHSb04Zq6gPl+JeltIZ226OYN0w=", - "owner": "nmattia", - "repo": "naersk", - "rev": "df71f5e4babda41cd919a8684b72218e2e809fa9", - "type": "github" - }, - "original": { - "owner": "nmattia", - "repo": "naersk", - "type": "github" - } - }, "nixpkgs": { "locked": { - "lastModified": 1630140382, - "narHash": "sha256-ntXepAHFlAEtaYIU5EzckRUODeeMgpu1u2Yug+4LFNc=", + "lastModified": 1631315520, + "narHash": "sha256-Y8j0JYtZMifrHaWdTfTp1mYVXZ2PLJO/P0XZxMvo7KU=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "08ef0f28e3a41424b92ba1d203de64257a9fca6a", + "rev": "b72ad04a8a324697d3fb92e19cd840379a902813", "type": "github" }, "original": { @@ -76,18 +56,18 @@ "inputs": { "fenix": "fenix", "flake-utils": "flake-utils", - "naersk": "naersk", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "rust2nix": "rust2nix" } }, "rust-analyzer-src": { "flake": false, "locked": { - "lastModified": 1630692232, - "narHash": "sha256-YX64rwkyLzMTg87rtM2p5VRdv3SS+/W5jvwG1sPScJY=", + "lastModified": 1631283242, + "narHash": "sha256-Sec9mf2nwsz1fv88mS6lY2PQCxb+4COHIFOSl9+jeRQ=", "owner": "rust-analyzer", "repo": "rust-analyzer", - "rev": "5506e0dfaffb548a0bcd20584d74c33229d7c186", + "rev": "07fb5db3dcc3814656d02e80b5451a4532f08a56", "type": "github" }, "original": { @@ -96,6 +76,26 @@ "repo": "rust-analyzer", "type": "github" } + }, + "rust2nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1631402377, + "narHash": "sha256-It644SN1E5T4zWmfNaWZ4lGCwjaIAmef1/2/cRbAVho=", + "owner": "anirudhb", + "repo": "rust2nix", + "rev": "2fbefd6577ed8ea166a035294c35ee92126bea6f", + "type": "github" + }, + "original": { + "owner": "anirudhb", + "repo": "rust2nix", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index b72a5af..f772444 100644 --- a/flake.nix +++ b/flake.nix @@ -1,11 +1,11 @@ { - description = "A very basic flake with a shell"; + description = "A very basic flake"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; flake-utils.url = "github:numtide/flake-utils"; - naersk = { - url = "github:nmattia/naersk"; + rust2nix = { + url = "github:anirudhb/rust2nix"; inputs.nixpkgs.follows = "nixpkgs"; }; fenix = { @@ -14,67 +14,27 @@ }; }; - outputs = { self, nixpkgs, flake-utils, fenix, naersk }: flake-utils.lib.eachDefaultSystem (system: + outputs = { self, nixpkgs, flake-utils, fenix, rust2nix }: flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; - lib = nixpkgs.lib; fenixPkgs = fenix.packages.${system}; - # FIXME: once nmattie/naersk#191 is merged rust = fenixPkgs.combine [ fenixPkgs.latest.rustc fenixPkgs.latest.cargo ]; - naerskLib = naersk.lib."${system}".override { + rust2nixLib = rust2nix.lib.${system}; + in rec { + packages.haas-api = rust2nixLib.mkRustApp { + pname = "haas_api"; + src = ./.; cargo = rust; rustc = rust; + #buildInputs = [ + # pkgs.darwin.apple_sdk.frameworks.Security + #]; + #LDFLAGS = "-F ${pkgs.darwin.apple_sdk.frameworks.Security}/Library/Frameworks"; + #NIX_DEBUG = "1"; }; - haas-api-spec = { - pname = "haas_api"; - root = ./.; - buildInputs = with pkgs; [ - postgresql - ] ++ lib.optionals (lib.hasSuffix system "linux") (with pkgs; [ - pkg-config - openssl.dev - ]); - }; - in rec { - packages.haas-api = naerskLib.buildPackage haas-api-spec; - # FIXME: compile on non-macOS - packages.haas-api-docker = - let - pkgsCross = pkgs.pkgsCross.musl64; - target = "x86_64-unknown-linux-musl"; - toolchain = with fenixPkgs; combine [ - latest.rustc - latest.cargo - targets.${target}.latest.rust-std - ]; - cc-naerskLib = naersk.lib."${system}".override { - cargo = toolchain; - rustc = toolchain; - }; - cc-haas-api = cc-naerskLib.buildPackage { - pname = "haas_api"; - root = ./.; - buildInputs = with pkgsCross; [ - postgresql - pkg-config - openssl.dev - ]; - CARGO_BUILD_TARGET = target; - CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER = "${pkgsCross.stdenv.cc}/bin/${target}-gcc"; - #OPENSSL_STATIC = "1"; - #OPENSSL_LIB_DIR = "${pkgsCross.openssl.dev}/lib"; - #OPENSSL_INCLUDE_DIR = "${pkgsCross.openssl.dev}/lib"; - }; - in - pkgs.dockerTools.buildImage { - name = "haas-api"; - config = { - Cmd = [ "${cc-haas-api}/bin/haas_api" ]; - }; - }; defaultPackage = packages.haas-api; apps.haas-api = flake-utils.lib.mkApp { @@ -86,6 +46,8 @@ nativeBuildInputs = with pkgs; [ fenixPkgs.stable.defaultToolchain fenixPkgs.rust-analyzer + jq + libiconv ]; }; }); From d42fef0526fe65dffc5450da4e4b1f574dfc206a Mon Sep 17 00:00:00 2001 From: anirudhb Date: Wed, 15 Sep 2021 20:49:42 -0700 Subject: [PATCH 2/2] last broken nix commit, switch to crate2nix soon --- flake.lock | 30 ++++++++--------- flake.nix | 1 + flake.nix.old | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 15 deletions(-) create mode 100644 flake.nix.old diff --git a/flake.lock b/flake.lock index 5ec32ed..4da19fb 100644 --- a/flake.lock +++ b/flake.lock @@ -8,11 +8,11 @@ "rust-analyzer-src": "rust-analyzer-src" }, "locked": { - "lastModified": 1631327238, - "narHash": "sha256-ZUvHDxlIBTfp/058duvkXklEnLTpT1cBKH6VlqmKfDY=", + "lastModified": 1631672792, + "narHash": "sha256-mKOrm7Dvvpi/bNPl196SwDSTpGWs6CGB8jsMT1/MLu0=", "owner": "nix-community", "repo": "fenix", - "rev": "7ffdfe27c597daa0a255a2ecdd867d0b5c3582fd", + "rev": "e917dae2552d6d50797a718bffba34102af082bf", "type": "github" }, "original": { @@ -23,11 +23,11 @@ }, "flake-utils": { "locked": { - "lastModified": 1629481132, - "narHash": "sha256-JHgasjPR0/J1J3DRm4KxM4zTyAj4IOJY8vIl75v/kPI=", + "lastModified": 1631561581, + "narHash": "sha256-3VQMV5zvxaVLvqqUrNz3iJelLw30mIVSfZmAaauM3dA=", "owner": "numtide", "repo": "flake-utils", - "rev": "997f7efcb746a9c140ce1f13c72263189225f482", + "rev": "7e5bf3925f6fbdfaf50a2a7ca0be2879c4261d19", "type": "github" }, "original": { @@ -38,11 +38,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1631315520, - "narHash": "sha256-Y8j0JYtZMifrHaWdTfTp1mYVXZ2PLJO/P0XZxMvo7KU=", + "lastModified": 1631614142, + "narHash": "sha256-4B/qkXHPWe/1NL4enq6Qp8eNvTGtvoes1ZpnGbmlRwM=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "b72ad04a8a324697d3fb92e19cd840379a902813", + "rev": "071317d543205ee5f5611d391a37582f9b282240", "type": "github" }, "original": { @@ -63,11 +63,11 @@ "rust-analyzer-src": { "flake": false, "locked": { - "lastModified": 1631283242, - "narHash": "sha256-Sec9mf2nwsz1fv88mS6lY2PQCxb+4COHIFOSl9+jeRQ=", + "lastModified": 1631644319, + "narHash": "sha256-Q/d+KLvVURRuz7pFv+TZ+3QCL+s4VmGub8XCdOUkr0M=", "owner": "rust-analyzer", "repo": "rust-analyzer", - "rev": "07fb5db3dcc3814656d02e80b5451a4532f08a56", + "rev": "726a2aa211974a6bb1a612fe8824df7baf59faf6", "type": "github" }, "original": { @@ -84,11 +84,11 @@ ] }, "locked": { - "lastModified": 1631402377, - "narHash": "sha256-It644SN1E5T4zWmfNaWZ4lGCwjaIAmef1/2/cRbAVho=", + "lastModified": 1631666951, + "narHash": "sha256-ccf3PUldAfDgo5RAUkJ9JTgcZur2Lx4FtRxnTN37DD4=", "owner": "anirudhb", "repo": "rust2nix", - "rev": "2fbefd6577ed8ea166a035294c35ee92126bea6f", + "rev": "aa2bfbb70e4fcabbf925d393851792b65f76b41b", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index f772444..e4f7fc4 100644 --- a/flake.nix +++ b/flake.nix @@ -6,6 +6,7 @@ flake-utils.url = "github:numtide/flake-utils"; rust2nix = { url = "github:anirudhb/rust2nix"; + #url = "path:../../rust2nix"; inputs.nixpkgs.follows = "nixpkgs"; }; fenix = { diff --git a/flake.nix.old b/flake.nix.old new file mode 100644 index 0000000..b72a5af --- /dev/null +++ b/flake.nix.old @@ -0,0 +1,92 @@ +{ + description = "A very basic flake with a shell"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + naersk = { + url = "github:nmattia/naersk"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, flake-utils, fenix, naersk }: flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + lib = nixpkgs.lib; + fenixPkgs = fenix.packages.${system}; + # FIXME: once nmattie/naersk#191 is merged + rust = fenixPkgs.combine [ + fenixPkgs.latest.rustc + fenixPkgs.latest.cargo + ]; + naerskLib = naersk.lib."${system}".override { + cargo = rust; + rustc = rust; + }; + haas-api-spec = { + pname = "haas_api"; + root = ./.; + buildInputs = with pkgs; [ + postgresql + ] ++ lib.optionals (lib.hasSuffix system "linux") (with pkgs; [ + pkg-config + openssl.dev + ]); + }; + in rec { + packages.haas-api = naerskLib.buildPackage haas-api-spec; + # FIXME: compile on non-macOS + packages.haas-api-docker = + let + pkgsCross = pkgs.pkgsCross.musl64; + target = "x86_64-unknown-linux-musl"; + toolchain = with fenixPkgs; combine [ + latest.rustc + latest.cargo + targets.${target}.latest.rust-std + ]; + cc-naerskLib = naersk.lib."${system}".override { + cargo = toolchain; + rustc = toolchain; + }; + cc-haas-api = cc-naerskLib.buildPackage { + pname = "haas_api"; + root = ./.; + buildInputs = with pkgsCross; [ + postgresql + pkg-config + openssl.dev + ]; + CARGO_BUILD_TARGET = target; + CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER = "${pkgsCross.stdenv.cc}/bin/${target}-gcc"; + #OPENSSL_STATIC = "1"; + #OPENSSL_LIB_DIR = "${pkgsCross.openssl.dev}/lib"; + #OPENSSL_INCLUDE_DIR = "${pkgsCross.openssl.dev}/lib"; + }; + in + pkgs.dockerTools.buildImage { + name = "haas-api"; + config = { + Cmd = [ "${cc-haas-api}/bin/haas_api" ]; + }; + }; + defaultPackage = packages.haas-api; + + apps.haas-api = flake-utils.lib.mkApp { + drv = packages.haas-api; + }; + defaultApp = apps.haas-api; + + devShell = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ + fenixPkgs.stable.defaultToolchain + fenixPkgs.rust-analyzer + ]; + }; + }); +}