-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
94 lines (81 loc) · 2.44 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# with help from https://hoverbear.org/blog/a-flake-for-your-crate/
{
description = "Create dictionaries by scraping webpages or crawling local files.";
inputs = {
nixpkgs = {
url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};
naersk = {
url = "github:nmattia/naersk";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{ self
, nixpkgs
, naersk
, ...
}:
let
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
# https://ayats.org/blog/no-flake-utils/
forSystems = func:
nixpkgs.lib.genAttrs [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
]
(system: func (import nixpkgs {
inherit system;
config.allowUnfree = true;
overlays = [
self.overlays.default
];
}));
in
{
overlays = {
default = final: prev: {
"${cargoToml.package.name}" = final.callPackage ./. { inherit naersk; };
};
};
packages = forSystems (pkgs: {
default = pkgs."${cargoToml.package.name}";
"${cargoToml.package.name}" = pkgs."${cargoToml.package.name}";
});
apps = forSystems (pkgs: {
default = {
type = "app";
program = "${pkgs."${cargoToml.package.name}"}/bin/${cargoToml.package.name}";
};
});
devShells = forSystems (pkgs: {
default = pkgs.mkShell {
inputsFrom = [ pkgs."${cargoToml.package.name}" ];
buildInputs = with pkgs; [ rustfmt nixpkgs-fmt ];
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
};
});
checks = forSystems (pkgs: {
format = pkgs.runCommand "check-format"
{
buildInputs = with pkgs; [ rustfmt cargo nixpkgs-fmt shellcheck ];
}
''
shopt -s globstar nullglob
pushd "${./.}"
for file in ./**/Cargo.toml; do
${pkgs.rustfmt}/bin/cargo-fmt fmt --manifest-path "''${file}" -- --check
done
${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt --check .
for file in ./scripts/*.sh; do
${pkgs.shellcheck}/bin/shellcheck --severity=info "''${file}"
done
popd
touch $out # it worked!
'';
"${cargoToml.package.name}" = pkgs."${cargoToml.package.name}";
});
};
}