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..361099a --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1748026106, + "narHash": "sha256-6m1Y3/4pVw1RWTsrkAK2VMYSzG4MMIj7sqUy7o8th1o=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "063f43f2dbdef86376cc29ad646c45c46e93234c", + "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..8149dcd --- /dev/null +++ b/nix/package.nix @@ -0,0 +1,28 @@ +{ + lib, + rustPlatform, +}: let + fs = lib.fileset; +in + rustPlatform.buildRustPackage (finalAttrs: { + pname = "nff"; + version = "0.1.0"; + + src = fs.toSource { + root = ../.; + fileset = fs.unions [ + (fs.fileFilter (file: builtins.any file.hasExt ["rs"]) ../src) + ../Cargo.lock + ../Cargo.toml + ]; + }; + + cargoLock.lockFile = "${finalAttrs.src}/Cargo.lock"; + useFetchCargoVendor = true; + enableParallelBuilding = true; + + meta = { + description = "Experimental nftables ruleset formatter and prettier"; + mainProgram = "nff"; + }; + }) 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}"; +}