-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathflake.nix
More file actions
143 lines (131 loc) · 4.08 KB
/
flake.nix
File metadata and controls
143 lines (131 loc) · 4.08 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
{
description = "Switches between different versions of commands based on your current directory";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
crane.url = "github:ipetkov/crane";
};
outputs = {
self,
nixpkgs,
flake-utils,
crane,
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {inherit system;};
inherit (pkgs) lib;
craneLib = crane.mkLib pkgs;
rustSrc = lib.cleanSourceWith {
src = ./.;
filter = craneLib.filterCargoSources;
};
src = with lib.fileset;
toSource {
root = ./.;
fileset = unions [
(fromSource rustSrc)
./README.md
./etc
];
};
commonArgs = {
inherit src;
strictDeps = true;
buildInputs = lib.optionals pkgs.stdenv.isDarwin [pkgs.libiconv];
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
alt = craneLib.buildPackage (commonArgs
// {
inherit cargoArtifacts;
doCheck = false; # runs through `nix flake check`
postInstall = ''
# shell hooks
install -D etc/profile.d/alt.sh $out/etc/profile.d/alt.sh
install -D \
etc/fish/conf.d/alt.fish \
$out/share/fish/vendor_conf.d/alt.fish
# docs / man pages
install -D README.md $out/share/doc/alt/README.md
install -D target/release/man/*.1 -t $out/share/man/man1
# completion
install -D \
target/release/completion/alt.bash \
$out/share/bash-completion/completions/alt.bash
install -D \
target/release/completion/alt.fish \
$out/share/fish/vendor_completions.d/alt.fish
install -D \
target/release/completion/_alt \
$out/share/zsh/site-functions/_alt
'';
});
in {
packages.default = alt;
apps.default = flake-utils.lib.mkApp {drv = alt;};
formatter = pkgs.writeShellScriptBin "fmt" ''
${pkgs.alejandra}/bin/alejandra .
'';
checks = {
inherit alt;
clippy = craneLib.cargoClippy (commonArgs // {inherit cargoArtifacts;});
test = craneLib.cargoTest (commonArgs
// {
inherit cargoArtifacts;
src = with lib.fileset;
toSource {
root = ./.;
fileset = unions [
(fromSource rustSrc)
./tests/snapshots
];
};
});
rustfmt = craneLib.cargoFmt {inherit src;};
alejandra =
pkgs.runCommand "alejandra" {
buildInputs = [pkgs.alejandra];
} ''
alejandra -c ${./.}
mkdir $out
'';
shellcheck =
pkgs.runCommand "shellcheck" {
buildInputs = [pkgs.fd pkgs.shellcheck];
} ''
fd . ${./.} -e .sh -e .bash -e .zsh -X shellcheck '{}'
mkdir $out
'';
black =
pkgs.runCommand "black" {
buildInputs = [pkgs.python311Packages.black];
} ''
black --check ${./.}
mkdir $out
'';
flake8 =
pkgs.runCommand "flake8" {
buildInputs = [pkgs.python311Packages.flake8];
} ''
flake8 --config ${./.}/setup.cfg ${./.}
mkdir $out
'';
};
devShells.default = craneLib.devShell {
checks = self.checks.${system};
packages = [
pkgs.cargo-insta
pkgs.rust-analyzer
# Various supported shells for testing integrations
pkgs.bash
pkgs.fish
pkgs.zsh
# Packaging tooling (in `ci/`)
pkgs.python311
pkgs.cargo-cross
pkgs.cargo-deb
];
# Ensure `rust-analyzer` has access to the rust source code.
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
};
});
}