-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
default.nix
188 lines (171 loc) · 5.44 KB
/
default.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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
let
sources = import ./npins;
in
{
system ? builtins.currentSystem,
nixpkgs ? sources.nixpkgs,
treefmt-nix ? sources.treefmt-nix,
}:
let
pkgs = import nixpkgs {
inherit system;
config = { };
overlays = [ ];
};
inherit (pkgs) lib;
runtimeExprPath = ./src/eval.nix;
testNixpkgsPath = ./tests/mock-nixpkgs.nix;
nixpkgsLibPath = nixpkgs + "/lib";
# Needed to make Nix evaluation work inside nix builds
initNix = ''
export TEST_ROOT=$(pwd)/test-tmp
export NIX_CONF_DIR=$TEST_ROOT/etc
export NIX_LOCALSTATE_DIR=$TEST_ROOT/var
export NIX_LOG_DIR=$TEST_ROOT/var/log/nix
export NIX_STATE_DIR=$TEST_ROOT/var/nix
export NIX_STORE_DIR=$TEST_ROOT/store
# Ensure that even if tests run in parallel, we don't get an error
# We'd run into https://github.com/NixOS/nix/issues/2706 unless the store is initialised first
nix-store --init
'';
# Determine version from Cargo.toml
version = (lib.importTOML ./Cargo.toml).package.version;
treefmtEval = (import treefmt-nix).evalModule pkgs {
# Used to find the project root
projectRootFile = ".git/config";
programs.rustfmt.enable = true;
programs.nixfmt-rfc-style.enable = true;
programs.shfmt.enable = true;
settings.formatter.shfmt.options = [ "--space-redirects" ];
};
packages = {
build = pkgs.callPackage ./package.nix {
inherit
nixpkgsLibPath
initNix
runtimeExprPath
testNixpkgsPath
version
;
};
shell = pkgs.mkShell {
env.NIX_CHECK_BY_NAME_EXPR_PATH = toString runtimeExprPath;
env.NIX_PATH = "test-nixpkgs=${toString testNixpkgsPath}:test-nixpkgs/lib=${toString nixpkgsLibPath}";
env.RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}";
inputsFrom = [ packages.build ];
nativeBuildInputs = with pkgs; [
cargo-audit
cargo-edit
cargo-outdated
npins
rust-analyzer
treefmtEval.config.build.wrapper
];
};
# This checks that all Git-tracked files are formatted appropriately
treefmt = treefmtEval.config.build.check (
lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.gitTracked ./.;
}
);
# Run regularly by CI and turned into a PR
autoPrUpdate =
let
updateScripts = {
npins = pkgs.writeShellApplication {
name = "update-npins";
runtimeInputs = with pkgs; [ npins ];
text = ''
echo "<details><summary>npins changes</summary>"
# Needed because GitHub's rendering of the first body line breaks down otherwise
echo ""
echo '```'
npins update --directory "$1/npins" 2>&1
echo '```'
echo "</details>"
'';
};
# These steps have to be in the same script because order matters.
# `carge upgrade` should happen before `cargo update` and then check
# `cargo outdated` and `cargo audit` after that.
cargo = pkgs.writeShellApplication {
name = "cargo";
runtimeInputs = with pkgs; [
cargo
cargo-audit
cargo-edit # provides `cargo upgrade`
cargo-outdated
];
text = ''
echo "<details><summary>cargo changes</summary>"
echo ""
echo "### cargo upgrade"
printf "\n\`\`\`\n"
# --incompatible allows jumping to the next major version.
cargo upgrade --incompatible --manifest-path "$1/Cargo.toml" 2>&1
printf "\n\`\`\`\n"
echo "### cargo update"
printf "\n\`\`\`\n"
cargo update --manifest-path "$1/Cargo.toml" 2>&1
printf "\n\`\`\`\n"
echo "### cargo outdated"
printf "\n\`\`\`\n"
cargo outdated --manifest-path "$1/Cargo.toml" 2>&1
printf "\n\`\`\`\n"
echo "### cargo audit"
printf "\n\`\`\`\n"
cargo audit --file "$1/Cargo.lock" 2>&1
printf "\n\`\`\`\n"
echo "</details>"
'';
};
githubActions = pkgs.writeShellApplication {
name = "update-github-actions";
runtimeInputs = with pkgs; [
dependabot-cli
jq
github-cli
coreutils
];
text = builtins.readFile ./scripts/update-github-actions.sh;
};
};
in
pkgs.writeShellApplication {
name = "auto-pr-update";
text = ''
# Prevent impurities
unset PATH
${lib.concatMapStringsSep "\n" (script: ''
echo >&2 "Running ${script}"
${lib.getExe script} "$1"
'') (lib.attrValues updateScripts)}
'';
};
# Tests the tool on the pinned Nixpkgs tree, this is a good sanity check
nixpkgsCheck =
pkgs.runCommand "test-nixpkgs-check-by-name"
{
nativeBuildInputs = [
packages.build
pkgs.nix
];
nixpkgsPath = nixpkgs;
}
''
${initNix}
nixpkgs-check-by-name --base "$nixpkgsPath" "$nixpkgsPath"
touch $out
'';
};
in
packages
// {
# Good for debugging
inherit pkgs;
# Built by CI
ci = pkgs.linkFarm "ci" packages;
# Used by CI to determine whether a new version should be released
inherit version;
}