From 38041bfeca2c73c05b3ac6c32f52cce2b2f25a84 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Tue, 19 Apr 2022 12:12:22 -0500 Subject: [PATCH] flakify & other amenities closes: #2 --- .envrc | 17 +++++ .gitignore | 3 + Cargo.lock | 7 +++ Cargo.toml | 5 +- default.nix | 21 ++++--- flake.lock | 44 +++++++++++++ flake.nix | 134 ++++++++++++++++++++++++++++++++++++++++ recordaccess/Cargo.toml | 2 +- rustfmt.toml | 18 ++++++ shell.nix | 11 ++++ treefmt.toml | 19 ++++++ 11 files changed, 267 insertions(+), 14 deletions(-) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 rustfmt.toml create mode 100644 shell.nix create mode 100644 treefmt.toml diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..507d8da --- /dev/null +++ b/.envrc @@ -0,0 +1,17 @@ +#! /bin/sh + +# reload when these files change +watch_file flake.nix +watch_file flake.lock + +{ + # shell gc root dir + mkdir -p "$(direnv_layout_dir)" + eval "$( + nix print-dev-env . \ + --no-update-lock-file \ + --no-write-lock-file \ + --profile $(direnv_layout_dir)/flake-profile + )" +} || use nix + diff --git a/.gitignore b/.gitignore index 6f79051..6743c2c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ # nix-build symlinks /result + +# direnv +.direnv diff --git a/Cargo.lock b/Cargo.lock index 82895a5..8fd0fd6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -99,6 +99,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + [[package]] name = "libc" version = "0.2.122" @@ -133,6 +139,7 @@ version = "0.1.0" dependencies = [ "blake2", "hex", + "lazy_static", "nix", "tempfile", ] diff --git a/Cargo.toml b/Cargo.toml index 3d66d2c..0f80a97 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,9 +4,7 @@ version = "0.1.0" edition = "2021" [workspace] -exclude = [ - "recordaccess", -] +exclude = ["recordaccess"] [[bin]] name = "nix-eval-cache" @@ -17,3 +15,4 @@ tempfile = "3.3.0" nix = "0.23.1" blake2 = "0.10.4" hex = "0.4.3" +lazy_static = "1.4.0" diff --git a/default.nix b/default.nix index 274c11f..ca2d53d 100644 --- a/default.nix +++ b/default.nix @@ -1,10 +1,11 @@ -with import {}; -mkShell { - nativeBuildInputs = [ - bashInteractive - rustc - cargo - cargo-watch - rust-analyzer - ]; -} +let + lockData = builtins.readFile ./flake.lock; + lock = builtins.fromJSON lockData; + flakeCompat = lock.nodes.flakeCompat.locked; + flakeCompatSrc = builtins.fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${flakeCompat.rev}.tar.gz"; + sha256 = flakeCompat.narHash; + }; + flake = import flakeCompatSrc {src = ./.;}; +in + flake.defaultNix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..2c87c4a --- /dev/null +++ b/flake.lock @@ -0,0 +1,44 @@ +{ + "nodes": { + "flakeCompat": { + "flake": false, + "locked": { + "lastModified": 1650374568, + "narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "b4a34015c698c7793d592d66adbab377907a2be8", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1650194139, + "narHash": "sha256-kurZsqeOw5fpqA/Ig+8tHvbjwzs5P9AE6WUKOX1m6qM=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "bd4dffcdb7c577d74745bd1eff6230172bd176d5", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flakeCompat": "flakeCompat", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..b51da07 --- /dev/null +++ b/flake.nix @@ -0,0 +1,134 @@ +{ + description = "The More Aggressive Nix Eval Cache"; + + inputs = { + flakeCompat.url = github:edolstra/flake-compat; + flakeCompat.flake = false; + + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + }; + + outputs = inputs: let + commit = inputs.self.shortRev or "dirty"; + date = inputs.self.lastModifiedDate or inputs.self.lastModified or "19700101"; + version = "1.2.0+${builtins.substring 0 8 date}.${commit}"; + + nixpkgsForHost = host: + import inputs.nixpkgs { + overlays = [ + (self: super: { + nix-eval-cache = self.rustPlatform.buildRustPackage { + pname = "nix-eval-cache"; + inherit version; + src = ./.; + cargoLock.lockFile = ./Cargo.lock; + + passthru.tests = { + version = self.testVersion {package = super.nix-eval-cache;}; + }; + + meta = { + description = "The More Aggressive Nix Eval Cache."; + homepage = "https://github.com/numtide/nix-eval-cache"; + license = self.lib.licenses.mit; + maintainers = [self.lib.maintainers.mic92]; + platforms = self.lib.systems.doubles.all; + }; + }; + }) + ]; + system = host; + }; + + # nixpkgs."aarch64-darwin" = nixpkgsForHost "aarch64-darwin"; + nixpkgs."aarch64-linux" = nixpkgsForHost "aarch64-linux"; + nixpkgs."i686-linux" = nixpkgsForHost "i686-linux"; + # nixpkgs."x86_64-darwin" = nixpkgsForHost "x86_64-darwin"; + nixpkgs."x86_64-linux" = nixpkgsForHost "x86_64-linux"; + + buildBinariesForHost = host: pkgs: let + binaries = builtins.listToAttrs ( + builtins.map (pkg: { + name = "nix-eval-cache-${pkg.stdenv.targetPlatform.config}"; + value = pkg; + }) + pkgs + ); + in + binaries + // { + "nix-eval-cache-binaries" = nixpkgs.${host}.linkFarm "nix-eval-cache-binaries" ( + nixpkgs.${host}.lib.mapAttrsToList + (name: binary: { + inherit name; + path = "${binary}/bin/nix-eval-cache"; + }) + binaries + ); + "default" = builtins.elemAt pkgs 0; + }; + in rec { + # checks."aarch64-darwin" = packages."aarch64-darwin"; + checks."aarch64-linux" = packages."aarch64-linux"; + checks."i686-linux" = packages."i686-linux"; + # checks."x86_64-darwin" = packages."x86_64-darwin"; + checks."x86_64-linux" = packages."x86_64-linux"; + + # defaultPackage."aarch64-darwin" = packages."aarch64-darwin"."nix-eval-cache-aarch64-apple-darwin"; + defaultPackage."aarch64-linux" = packages."aarch64-linux"."nix-eval-cache-aarch64-unknown-linux-gnu"; + defaultPackage."i686-linux" = packages."i686-linux"."nix-eval-cache-i686-unknown-linux-gnu"; + # defaultPackage."x86_64-darwin" = packages."x86_64-darwin"."nix-eval-cache-x86_64-apple-darwin"; + defaultPackage."x86_64-linux" = packages."x86_64-linux"."nix-eval-cache-x86_64-unknown-linux-gnu"; + + devShell."x86_64-linux" = with nixpkgs."x86_64-linux"; + mkShell { + name = "nix-eval-cache"; + packages = [ + cargo + cargo-bloat + cargo-license + cargo-tarpaulin + cargo-watch + rust-analyzer + clippy + alejandra + nodejs + nodePackages.prettier + nodePackages.prettier-plugin-toml + rustc + shfmt + treefmt + ]; + }; + + # packages."aarch64-darwin" = with nixpkgs."aarch64-darwin"; + # buildBinariesForHost "aarch64-darwin" [ + # nix-eval-cache + # ]; + packages."aarch64-linux" = with nixpkgs."aarch64-linux"; + buildBinariesForHost "aarch64-linux" [ + nix-eval-cache + pkgsStatic.nix-eval-cache + ]; + packages."i686-linux" = with nixpkgs."i686-linux"; + buildBinariesForHost "i686-linux" [ + nix-eval-cache + ]; + # packages."x86_64-darwin" = with nixpkgs."x86_64-darwin"; + # buildBinariesForHost "x86_64-darwin" [ + # nix-eval-cache + # ]; + packages."x86_64-linux" = with nixpkgs."x86_64-linux"; (buildBinariesForHost "x86_64-linux" [ + nix-eval-cache + pkgsStatic.nix-eval-cache + + pkgsCross.aarch64-multiplatform.pkgsStatic.nix-eval-cache + + pkgsCross.armv7l-hf-multiplatform.pkgsStatic.nix-eval-cache + + pkgsCross.gnu32.pkgsStatic.nix-eval-cache + + pkgsCross.raspberryPi.pkgsStatic.nix-eval-cache + ]); + }; +} diff --git a/recordaccess/Cargo.toml b/recordaccess/Cargo.toml index 3bcc460..46b1389 100644 --- a/recordaccess/Cargo.toml +++ b/recordaccess/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "recordaccess" version = "0.0.1" -authors = [ "Jörg Thalheim " ] +authors = ["Jörg Thalheim "] edition = "2021" [lib] diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..7a70519 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,18 @@ +edition = "2021" +enum_discrim_align_threshold = 999 +format_code_in_doc_comments = true +format_generated_files = true +format_macro_bodies = true +format_macro_matchers = true +format_strings = true +hex_literal_case = "Lower" +imports_granularity = "Item" +imports_layout = "Vertical" +max_width = 80 +normalize_comments = true +normalize_doc_attributes = true +reorder_impl_items = true +struct_field_align_threshold = 999 +unstable_features = true +use_small_heuristics = "Max" +version = "Two" diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..7c443bf --- /dev/null +++ b/shell.nix @@ -0,0 +1,11 @@ +let + lockData = builtins.readFile ./flake.lock; + lock = builtins.fromJSON lockData; + flakeCompat = lock.nodes.flakeCompat.locked; + flakeCompatSrc = builtins.fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${flakeCompat.rev}.tar.gz"; + sha256 = flakeCompat.narHash; + }; + flake = import flakeCompatSrc {src = ./.;}; +in + flake.shellNix diff --git a/treefmt.toml b/treefmt.toml new file mode 100644 index 0000000..c287a94 --- /dev/null +++ b/treefmt.toml @@ -0,0 +1,19 @@ +[formatter] + +[formatter.nix] +command = "alejandra" +includes = ["*.nix"] + +[formatter.prettier] +command = "prettier" +includes = ["*.html", "*.js", "*.json", "*.md", "*.toml", "*.yaml"] +options = ["--plugin", "prettier-plugin-toml", "--write"] + +[formatter.rust] +command = "rustfmt" +includes = ["*.rs"] + +[formatter.shell] +command = "shfmt" +includes = ["*.sh"] +options = ["-bn", "-ci", "-sr", "-i", "2", "-s", "-w"]