| 
 | 1 | +{  | 
 | 2 | +  description = "ADO.net and JDBC Connection String Parser.";  | 
 | 3 | + | 
 | 4 | +  inputs = {  | 
 | 5 | +    flake-utils.url = "github:numtide/flake-utils";  | 
 | 6 | +    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";  | 
 | 7 | +    rust-overlay = {  | 
 | 8 | +      url = "github:oxalica/rust-overlay";  | 
 | 9 | +      inputs.nixpkgs.follows = "nixpkgs";  | 
 | 10 | +      inputs.flake-utils.follows = "flake-utils";  | 
 | 11 | +    };  | 
 | 12 | +  };  | 
 | 13 | + | 
 | 14 | +  outputs = { self, nixpkgs, flake-utils, rust-overlay }:  | 
 | 15 | +    flake-utils.lib.eachDefaultSystem (system: let  | 
 | 16 | +      overlays = [ (import rust-overlay) ];  | 
 | 17 | +      pkgs = import nixpkgs { inherit system overlays; };  | 
 | 18 | +      rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;  | 
 | 19 | +      inherit (pkgs) wasm-bindgen-cli rustPlatform nodejs;  | 
 | 20 | +    in {  | 
 | 21 | +      defaultPackage = rustPlatform.buildRustPackage {  | 
 | 22 | +        name = "connection-string";  | 
 | 23 | +        src = builtins.path { path = ./.; name = "connection-string"; };  | 
 | 24 | + | 
 | 25 | +        cargoLock = {  | 
 | 26 | +          lockFile = ./Cargo.lock;  | 
 | 27 | +        };  | 
 | 28 | + | 
 | 29 | +        nativeBuildInputs = [ rust wasm-bindgen-cli nodejs ];  | 
 | 30 | + | 
 | 31 | +        buildPhase = ''  | 
 | 32 | +          RUST_BACKTRACE=1  | 
 | 33 | +          cargo build --release --target=wasm32-unknown-unknown  | 
 | 34 | +          echo 'Creating out dir...'  | 
 | 35 | +          mkdir -p $out/src;  | 
 | 36 | +          echo 'Copying package.json...'  | 
 | 37 | +          cp ./package.json $out/;  | 
 | 38 | +          echo 'Copying README.md...'  | 
 | 39 | +          cp README.md $out/;  | 
 | 40 | +          echo 'Generating node module...'  | 
 | 41 | +          wasm-bindgen \  | 
 | 42 | +            --target nodejs \  | 
 | 43 | +            --out-dir $out/src \  | 
 | 44 | +            target/wasm32-unknown-unknown/release/connection_string.wasm;  | 
 | 45 | +        '';  | 
 | 46 | +        checkPhase = "echo 'Check phase: skipped'";  | 
 | 47 | +        installPhase = "echo 'Install phase: skipped'";  | 
 | 48 | +      };  | 
 | 49 | + | 
 | 50 | +      packages = {  | 
 | 51 | +        cargo = {  | 
 | 52 | +          type = "app";  | 
 | 53 | +          program = "${rust}/bin/cargo";  | 
 | 54 | +        };  | 
 | 55 | + | 
 | 56 | +        # Takes the new package version as first and only argument, and updates package.json  | 
 | 57 | +        updatePackageVersion = pkgs.writeShellScriptBin "updateNpmPackageVersion" ''  | 
 | 58 | +          ${pkgs.jq}/bin/jq ".version = \"$1\"" package.json > /tmp/package.json  | 
 | 59 | +          rm package.json  | 
 | 60 | +          cp /tmp/package.json package.json  | 
 | 61 | +          sed -i "s/^version\ =.*$/version = \"$1\"/" Cargo.toml  | 
 | 62 | +        '';  | 
 | 63 | +        publishRust = pkgs.writeShellScriptBin "publishRust" ''  | 
 | 64 | +          ${rust}/bin/cargo publish  | 
 | 65 | +        '';  | 
 | 66 | +        publishJavascript = pkgs.writeShellScriptBin "publishRust" ''  | 
 | 67 | +          ${nodejs}/bin/npm publish ./result --access public --tag latest  | 
 | 68 | +        '';  | 
 | 69 | +        npm = {  | 
 | 70 | +          type = "app";  | 
 | 71 | +          program = "${nodejs}/bin/npm";  | 
 | 72 | +        };  | 
 | 73 | +        wasm-bindgen = {  | 
 | 74 | +          type = "app";  | 
 | 75 | +          program = "${wasm-bindgen-cli}/bin/wasm-bindgen";  | 
 | 76 | +        };  | 
 | 77 | +        syncWasmBindgenVersions = pkgs.writeShellScriptBin "updateWasmBindgenVersion" ''  | 
 | 78 | +          echo 'Syncing wasm-bindgen version in crate with that of the installed CLI...'  | 
 | 79 | +          sed -i "s/^wasm-bindgen\ =.*$/wasm-bindgen = \"=${wasm-bindgen-cli.version}\"/" Cargo.toml  | 
 | 80 | +        '';  | 
 | 81 | +      };  | 
 | 82 | +      devShell = pkgs.mkShell {  | 
 | 83 | +        nativeBuildInputs = [ pkgs.bashInteractive ];  | 
 | 84 | +        buildInputs = with pkgs; [  | 
 | 85 | +          nodePackages.prisma  | 
 | 86 | +          nodePackages.npm  | 
 | 87 | +          nodejs-slim  | 
 | 88 | +        ];  | 
 | 89 | +      };  | 
 | 90 | +    });  | 
 | 91 | +}  | 
0 commit comments