diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..71497fb --- /dev/null +++ b/default.nix @@ -0,0 +1,39 @@ +{ lib, darwin, stdenv, openssl, pkg-config, rustPlatform, }: +let cargoFile = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).package; +in rustPlatform.buildRustPackage { + + pname = cargoFile.name; # The name of the package + version = cargoFile.version; # The version of the package + + # You can use lib here to make a more accurate source + # this can be nice to reduce the amount of rebuilds + # but thats out of scope for this post + src = ./.; # The source of the package + + # The lock file of the package, this can be done in other ways + # like cargoHash, we are not doing it in this case because this + # is much simpler, especially if we have access to the lock file + # in our source tree + cargoLock.lockFile = ./Cargo.lock; + + # The runtime dependencies of the package + buildInputs = [ openssl ] ++ lib.optionals stdenv.isDarwin + (with darwin.apple_sdk.frameworks; [ + Security + CoreFoundation + SystemConfiguration + ]); + + # programs and libraries used at build-time that, if they are a compiler or + # similar tool, produce code to run at run-time—i.e. tools used to build the new derivation + nativeBuildInputs = [ pkg-config ]; + + cargoLock.outputHashes = { + "mcp-core-1.0.7" = "sha256-I2lxsv71i/LLZN3r/7mwNc6nZRd1xtQNVUm/g08nhn0="; + }; + + meta = { + license = lib.licenses.mit; + mainProgram = cargoFile.name; + }; +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..4c81142 --- /dev/null +++ b/flake.lock @@ -0,0 +1,62 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1743315132, + "narHash": "sha256-6hl6L/tRnwubHcA4pfUUtk542wn2Om+D4UnDhlDW9BE=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "52faf482a3889b7619003c0daec593a1912fddc1", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1736320768, + "narHash": "sha256-nIYdTAiKIGnFNugbomgBJR+Xv5F1ZQU+HfaBqJKroC0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "4bc9c909d9ac828a039f288cf872d16d38185db8", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1743475035, + "narHash": "sha256-uLjVsb4Rxnp1zmFdPCDmdODd4RY6ETOeRj0IkC0ij/4=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "bee11c51c2cda3ac57c9e0149d94b86cc1b00d13", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..3624143 --- /dev/null +++ b/flake.nix @@ -0,0 +1,39 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + rust-overlay.url = "github:oxalica/rust-overlay"; + }; + outputs = { self, nixpkgs, rust-overlay, ... }: + let + namespace = "hello"; + overlays = [ rust-overlay.overlays.default ]; + forEachSystem = systems: f: nixpkgs.lib.genAttrs systems f; + forAllSystems = function: + nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed + (system: function (import nixpkgs { inherit system overlays; })); + in { + packages = + forAllSystems (pkgs: (self.overlays.default pkgs pkgs).${namespace}); + cross = forAllSystems (pkgs: + (forEachSystem (nixpkgs.lib.filter (sys: sys != pkgs.system) + nixpkgs.lib.systems.flakeExposed) (crossSystem: + let + crossPkgs = import nixpkgs { + localSystem = pkgs.system; + inherit crossSystem; + }; + in (self.overlays.default crossPkgs crossPkgs).${namespace}))); + devShells = + forAllSystems (pkgs: (self.overlays.default pkgs pkgs).devShells); + formatter = forAllSystems (pkgs: pkgs.nixpkgs-fmt); + overlays.default = final: prev: + let pkgs = final; + in { + devShells.default = pkgs.callPackage ./shell.nix { }; + ${namespace} = { + hello = pkgs.callPackage ./default.nix { }; + default = pkgs.callPackage ./default.nix { }; + }; + }; + }; +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..2b88450 --- /dev/null +++ b/shell.nix @@ -0,0 +1,11 @@ +{ clippy, rustfmt, callPackage, rust-analyzer, }: +let mainPkg = callPackage ./default.nix { }; +in mainPkg.overrideAttrs (prev: { + nativeBuildInputs = [ + # Additional Rust tooling + clippy + rustfmt + rust-analyzer + ] ++ (prev.nativeBuildInputs or [ ]); +}) +