-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
61 lines (52 loc) · 1.93 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# hashmash flake
#
# Considerable inspiration taken from
# https://hoverbear.org/blog/a-flake-for-your-crate/
{
description = "Find and randomize cryptographic hashes in text files";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};
outputs = { self, nixpkgs }:
let
# Admin
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
name = cargoToml.package.name;
systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
forAllSystems = f: nixpkgs.lib.genAttrs systems (system:
let pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlay ];
}; in f pkgs);
in
{
# Overlay
overlay = final: prev: { "${name}" = final.callPackage ./. { }; };
# Packages (built by `nix build .#<name>`)
packages = forAllSystems (pkgs: { "${name}" = pkgs."${name}"; });
# Default Package (built by `nix build .`)
defaultPackage = forAllSystems (pkgs: pkgs."${name}");
# Development environment
devShell = forAllSystems (pkgs: import ./shell.nix { inherit pkgs; });
# Basic CI checks
checks = forAllSystems (pkgs: {
"${name}" = pkgs."${name}";
# Source code formatting.
format = pkgs.runCommand "check-format"
{ buildInputs = [ pkgs.cargo pkgs.rustfmt pkgs.nixpkgs-fmt ]; }
''
${pkgs.cargo}/bin/cargo fmt --manifest-path ${./.}/Cargo.toml -- --check
${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt --check ${./.}
touch $out # success
'';
# Doesn't work yet, and is also slow (re-downloads crates.io)
#
# clippy = pkgs.runCommand "clippy"
# { buildInputs = [ pkgs.cargo pkgs.clippy ]; }
# ''
# CARGO_HOME=. ${pkgs.cargo}/bin/cargo clippy --manifest-path ${./.}/Cargo.toml -- -D warnings
# touch $out # success
# '';
});
};
}