From 8547710b62dd19fbccac151de4f95381fb01c479 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 22 Jul 2025 00:11:07 +0300 Subject: [PATCH] nix: initial tooling --- .envrc | 2 ++ flake.lock | 27 +++++++++++++++++++++++++++ flake.nix | 24 ++++++++++++++++++++++++ nix/package.nix | 31 +++++++++++++++++++++++++++++++ nix/shell.nix | 19 +++++++++++++++++++ 5 files changed, 103 insertions(+) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 nix/package.nix create mode 100644 nix/shell.nix 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..8530de9 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1752950548, + "narHash": "sha256-NS6BLD0lxOrnCiEOcvQCDVPXafX1/ek1dfJHX1nUIzc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c87b95e25065c028d31a94f06a62927d18763fdf", + "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..18bd6fa --- /dev/null +++ b/flake.nix @@ -0,0 +1,24 @@ +{ + description = "Rust Project Template"; + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + outputs = { + self, + nixpkgs, + }: let + systems = ["x86_64-linux" "aarch64-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..7a91195 --- /dev/null +++ b/nix/package.nix @@ -0,0 +1,31 @@ +{ + lib, + rustPlatform, +}: +rustPlatform.buildRustPackage (finalAttrs: { + pname = "eh"; + version = (builtins.fromTOML (builtins.readFile ../Cargo.toml)).workspace.package.version; + + src = let + fs = lib.fileset; + s = ../.; + in + fs.toSource { + root = s; + fileset = fs.unions (map (dir: (s + /${dir})) [ + ".cargo" + "eh" + "xtask" + "Cargo.toml" + "Cargo.lock" + ]); + }; + + cargoLock.lockFile = "${finalAttrs.src}/Cargo.lock"; + enableParallelBuilding = true; + + meta = { + description = "Ergonomic Nix CLI helper"; + maintainers = with lib.licenses; [NotAShelf]; + }; +}) diff --git a/nix/shell.nix b/nix/shell.nix new file mode 100644 index 0000000..965a0eb --- /dev/null +++ b/nix/shell.nix @@ -0,0 +1,19 @@ +{ + mkShell, + rust-analyzer, + rustfmt, + clippy, + cargo, + rustPlatform, +}: +mkShell { + name = "rust"; + packages = [ + rust-analyzer + rustfmt + clippy + cargo + ]; + + RUST_SRC_PATH = "${rustPlatform.rustLibSrc}"; +}