1use super::{runners, steps, steps::named, vars};
2use gh_workflow::*;
3use indexmap::IndexMap;
4use indoc::indoc;
5
6/// Generates the nix.yml workflow
7pub fn nix_build() -> Workflow {
8 let env: IndexMap<_, _> = [
9 ("ZED_CLIENT_CHECKSUM_SEED", vars::ZED_CLIENT_CHECKSUM_SEED),
10 ("ZED_MINIDUMP_ENDPOINT", vars::ZED_SENTRY_MINIDUMP_ENDPOINT),
11 (
12 "ZED_CLOUD_PROVIDER_ADDITIONAL_MODELS_JSON",
13 vars::ZED_CLOUD_PROVIDER_ADDITIONAL_MODELS_JSON,
14 ),
15 ("GIT_LFS_SKIP_SMUDGE", "1"), // breaks the livekit rust sdk examples which we don't actually depend on
16 ]
17 .into_iter()
18 .map(|(key, value)| (key.into(), value.into()))
19 .collect();
20
21 // todo(ci) instead of having these as optional YAML inputs,
22 // should we just generate two copies of the job (one for release-nightly
23 // and one for CI?)
24 let (input_flake_output, flake_output) = vars::input(
25 "flake-output",
26 WorkflowCallInput {
27 input_type: "string".into(),
28 default: Some("default".into()),
29 ..Default::default()
30 },
31 );
32 let (input_cachix_filter, cachix_filter) = vars::input(
33 "cachix-filter",
34 WorkflowCallInput {
35 input_type: "string".into(),
36 ..Default::default()
37 },
38 );
39
40 named::workflow()
41 .on(Event::default().workflow_call(
42 WorkflowCall::default()
43 .add_input(flake_output.0, flake_output.1)
44 .add_input(cachix_filter.0, cachix_filter.1),
45 ))
46 .add_job(
47 "nix-build-linux-x86",
48 Job::default()
49 .timeout_minutes(60u32)
50 .continue_on_error(true)
51 .cond(Expression::new(
52 "github.repository_owner == 'zed-industries'",
53 ))
54 .runs_on(runners::LINUX_DEFAULT)
55 .envs(env.clone())
56 .add_step(steps::checkout_repo().add_with(("clean", "false")))
57 .add_step(install_nix())
58 .add_step(cachix_action(&input_cachix_filter))
59 .add_step(build(&input_flake_output)),
60 )
61 .add_job(
62 "nix-build-mac-arm",
63 Job::default()
64 .timeout_minutes(60u32)
65 .continue_on_error(true)
66 .cond(Expression::new(
67 "github.repository_owner == 'zed-industries'",
68 ))
69 .runs_on(runners::MAC_DEFAULT)
70 .envs(env)
71 .add_step(steps::checkout_repo().add_with(("clean", "false")))
72 .add_step(set_path())
73 .add_step(cachix_action(&input_cachix_filter))
74 .add_step(build(&input_flake_output))
75 .add_step(limit_store()),
76 )
77}
78// on our macs we manually install nix. for some reason the cachix action is running
79// under a non-login /bin/bash shell which doesn't source the proper script to add the
80// nix profile to PATH, so we manually add them here
81pub fn set_path() -> Step<Run> {
82 named::bash(indoc! {r#"
83 echo "/nix/var/nix/profiles/default/bin" >> "$GITHUB_PATH"
84 echo "/Users/administrator/.nix-profile/bin" >> "$GITHUB_PATH"
85 "#})
86}
87
88pub fn install_nix() -> Step<Use> {
89 named::uses(
90 "cachix",
91 "install-nix-action",
92 "02a151ada4993995686f9ed4f1be7cfbb229e56f", // v31
93 )
94 .add_with(("github_access_token", vars::GITHUB_TOKEN))
95}
96
97pub fn cachix_action(cachix_filter: &str) -> Step<Use> {
98 named::uses(
99 "cachix",
100 "cachix-action",
101 "0fc020193b5a1fa3ac4575aa3a7d3aa6a35435ad", // v16
102 )
103 .add_with(("name", "zed"))
104 .add_with(("authToken", vars::CACHIX_AUTH_TOKEN))
105 .add_with(("pushFilter", cachix_filter))
106 .add_with(("cachixArgs", "-v"))
107}
108
109pub fn build(flake_output: &str) -> Step<Run> {
110 named::bash(&format!(
111 "nix build .#{} -L --accept-flake-config",
112 flake_output
113 ))
114}
115
116pub fn limit_store() -> Step<Run> {
117 named::bash(indoc! {r#"
118 if [ "$(du -sm /nix/store | cut -f1)" -gt 50000 ]; then
119 nix-collect-garbage -d || true
120 fi"#
121 })
122}