Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flakify & other amenities #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -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

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

# nix-build symlinks
/result

# direnv
.direnv
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ version = "0.1.0"
edition = "2021"

[workspace]
exclude = [
"recordaccess",
]
exclude = ["recordaccess"]

[[bin]]
name = "nix-eval-cache"
Expand All @@ -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"
21 changes: 11 additions & 10 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
with import <nixpkgs> {};
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
44 changes: 44 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

134 changes: 134 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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 = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this overlay used anywhere? I would avoid an overlay to not having to re-import nixpkgs for better eval performance: https://zimbatm.com/notes/1000-instances-of-nixpkgs

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Iirc, the reason is to get the cross compile machinery. I was having similar concerns but the cross machinery is not well exposed in upstream nixpkgs.

Definitely something to look for, though.

(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
]);
};
}
2 changes: 1 addition & 1 deletion recordaccess/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "recordaccess"
version = "0.0.1"
authors = [ "Jörg Thalheim <[email protected]>" ]
authors = ["Jörg Thalheim <[email protected]>"]
edition = "2021"

[lib]
Expand Down
18 changes: 18 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -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"
11 changes: 11 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions treefmt.toml
Original file line number Diff line number Diff line change
@@ -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"]