diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..e3fecb3 --- /dev/null +++ b/.envrc @@ -0,0 +1,2 @@ +use flake + diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..6f6bfa6 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1769461804, + "narHash": "sha256-msG8SU5WsBUfVVa/9RPLaymvi5bI8edTavbIq3vRlhI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "bfc1b8a4574108ceef22f02bafcf6611380c100d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..25f663b --- /dev/null +++ b/flake.nix @@ -0,0 +1,22 @@ +{ + inputs.nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable"; + + outputs = { + self, + nixpkgs, + }: let + systems = ["x86_64-linux"]; + forEachSystem = nixpkgs.lib.genAttrs systems; + pkgsForEach = nixpkgs.legacyPackages; + in { + packages = forEachSystem (system: { + default = pkgsForEach.${system}.callPackage ./nix/package.nix {}; + }); + + devShells = forEachSystem (system: { + default = pkgsForEach.${system}.callPackage ./nix/shell.nix {}; + }); + + hydraJobs = self.packages; + }; +} diff --git a/nix/package.nix b/nix/package.nix new file mode 100644 index 0000000..0966fb5 --- /dev/null +++ b/nix/package.nix @@ -0,0 +1,29 @@ +{ + lib, + rustPlatform, +}: +rustPlatform.buildRustPackage (finalAttrs: { + pname = "sample-rust"; + version = "0.1.0"; + + src = let + fs = lib.fileset; + s = ../.; + in + fs.toSource { + root = s; + fileset = fs.unions [ + (fs.fileFilter (file: builtins.any file.hasExt ["rs"]) (s + /src)) + (s + /Cargo.lock) + (s + /Cargo.toml) + ]; + }; + + cargoLock.lockFile = "${finalAttrs.src}/Cargo.lock"; + enableParallelBuilding = true; + + meta = { + description = "Sample Rust project"; + maintainers = with lib.maintainers; [NotAShelf]; + }; +}) diff --git a/nix/shell.nix b/nix/shell.nix new file mode 100644 index 0000000..d1b5644 --- /dev/null +++ b/nix/shell.nix @@ -0,0 +1,45 @@ +{ + mkShell, + rustc, + cargo, + lld, + rust-analyzer-unwrapped, + rustfmt, + clippy, + taplo, + cargo-nextest, + rustPlatform, + # Build deps + openssl, + pkg-config, +}: +mkShell { + name = "rust"; + + strictDeps = true; + packages = [ + rustc + cargo + lld + + # Tools + (rustfmt.override {asNightly = true;}) + clippy + cargo + taplo + rust-analyzer-unwrapped + + # Additional Cargo tooling + cargo-nextest + ]; + + buildInputs = [ + openssl + ]; + + nativeBuildInputs = [ + pkg-config + ]; + + env.RUST_SRC_PATH = "${rustPlatform.rustLibSrc}"; +}