Prod at CI with a stick

Signed-off-by: Ana Hobden <operator@hoverbear.org>
This commit is contained in:
Ana Hobden 2022-09-09 12:26:53 -07:00
parent 3a3a7af3f3
commit 82523e43a6
6 changed files with 41 additions and 34 deletions

View file

@ -39,17 +39,6 @@ jobs:
- name: Check nixpkgs-fmt formatting - name: Check nixpkgs-fmt formatting
run: nix develop --command ci-check-nixpkgs-fmt run: nix develop --command ci-check-nixpkgs-fmt
RegistryFormatting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v17
with:
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- name: Check registry.json formatting
run: nix develop --command ci-check-registry-format
EditorConfig: EditorConfig:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:

2
Cargo.lock generated
View file

@ -606,7 +606,7 @@ dependencies = [
[[package]] [[package]]
name = "harmonic" name = "harmonic"
version = "0.0.1" version = "0.0.0-unreleased"
dependencies = [ dependencies = [
"async-tar", "async-tar",
"async-trait", "async-trait",

View file

@ -1,7 +1,7 @@
[package] [package]
name = "harmonic" name = "harmonic"
description = "A `nix` installer" description = "A `nix` installer"
version = "0.0.1" version = "0.0.0-unreleased"
edition = "2021" edition = "2021"
resolver = "2" resolver = "2"

View file

@ -24,11 +24,6 @@ in
git ls-files '*.nix' | xargs | nixpkgs-fmt --check git ls-files '*.nix' | xargs | nixpkgs-fmt --check
'') '')
# RegistryFormatting
(writeScriptBin "ci-check-registry-format" ''
./registry/format.sh && git diff --exit-code
'')
# EditorConfig # EditorConfig
(writeScriptBin "ci-check-editorconfig" '' (writeScriptBin "ci-check-editorconfig" ''
eclint eclint
@ -39,7 +34,6 @@ in
ci-test-rust ci-test-rust
ci-check-spelling ci-check-spelling
ci-check-nixpkgs-fmt ci-check-nixpkgs-fmt
ci-check-registry-format
ci-check-editorconfig ci-check-editorconfig
'') '')
] ]

View file

@ -8,13 +8,7 @@ use valuable::Valuable;
#[derive(clap::Args, Debug, Valuable)] #[derive(clap::Args, Debug, Valuable)]
pub struct Instrumentation { pub struct Instrumentation {
/// Enable debug logs, -vv for trace /// Enable debug logs, -vv for trace
#[clap( #[clap(short = 'v', long, parse(from_occurrences), global = true)]
short = 'v',
long,
parse(from_occurrences),
global = true,
group = "verbosity"
)]
pub(crate) verbose: usize, pub(crate) verbose: usize,
} }

View file

@ -11,22 +11,34 @@ pub(crate) trait CommandExecute {
async fn execute(self) -> eyre::Result<ExitCode>; async fn execute(self) -> eyre::Result<ExitCode>;
} }
/// An opinionated, experimental Nix installer
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
#[clap(version)] #[clap(version)]
pub(crate) struct HarmonicCli { pub(crate) struct HarmonicCli {
#[clap(long, action(ArgAction::SetTrue), default_value = "false")] // Don't actually install, just log expected actions
#[clap(
long,
action(ArgAction::SetTrue),
default_value = "false",
global = true
)]
pub(crate) dry_run: bool, pub(crate) dry_run: bool,
#[clap(flatten)] #[clap(flatten)]
pub(crate) instrumentation: arg::Instrumentation, pub(crate) instrumentation: arg::Instrumentation,
/// Channel(s) to add by default, pass multiple times for multiple channels
#[clap( #[clap(
long, long,
value_parser, value_parser,
action = clap::ArgAction::Append,
env = "HARMONIC_CHANNEL",
default_value = "nixpkgs=https://nixos.org/channels/nixpkgs-unstable" default_value = "nixpkgs=https://nixos.org/channels/nixpkgs-unstable"
)] )]
pub(crate) channels: Vec<arg::ChannelValue>, pub(crate) channel: Vec<arg::ChannelValue>,
/// Don't modify the user profile to automatically load nix
#[clap(long)] #[clap(long)]
pub(crate) no_modify_profile: bool, pub(crate) no_modify_profile: bool,
#[clap(long, default_value = "32")] /// Number of build users to create
#[clap(long, default_value = "32", env = "HARMONIC_NIX_DAEMON_USER_COUNT")]
pub(crate) daemon_user_count: usize, pub(crate) daemon_user_count: usize,
#[clap(subcommand)] #[clap(subcommand)]
subcommand: Option<subcommand::Subcommand>, subcommand: Option<subcommand::Subcommand>,
@ -35,7 +47,7 @@ pub(crate) struct HarmonicCli {
#[async_trait::async_trait] #[async_trait::async_trait]
impl CommandExecute for HarmonicCli { impl CommandExecute for HarmonicCli {
#[tracing::instrument(skip_all, fields( #[tracing::instrument(skip_all, fields(
channels = %self.channels.iter().map(|ChannelValue(name, url)| format!("{name} {url}")).collect::<Vec<_>>().join(", "), channels = %self.channel.iter().map(|ChannelValue(name, url)| format!("{name} {url}")).collect::<Vec<_>>().join(", "),
daemon_user_count = %self.daemon_user_count, daemon_user_count = %self.daemon_user_count,
no_modify_profile = %self.no_modify_profile, no_modify_profile = %self.no_modify_profile,
dry_run = %self.dry_run, dry_run = %self.dry_run,
@ -45,12 +57,13 @@ impl CommandExecute for HarmonicCli {
dry_run, dry_run,
instrumentation: _, instrumentation: _,
daemon_user_count, daemon_user_count,
channels, channel,
no_modify_profile, no_modify_profile,
subcommand, subcommand,
} = self; } = self;
match subcommand { match subcommand {
#[cfg(target_os = "linux")]
Some(subcommand::Subcommand::NixOs(nixos)) => return nixos.execute().await, Some(subcommand::Subcommand::NixOs(nixos)) => return nixos.execute().await,
None => (), None => (),
} }
@ -60,13 +73,31 @@ impl CommandExecute for HarmonicCli {
harmonic.dry_run(dry_run); harmonic.dry_run(dry_run);
harmonic.daemon_user_count(daemon_user_count); harmonic.daemon_user_count(daemon_user_count);
harmonic.channels( harmonic.channels(
channels channel
.into_iter() .into_iter()
.map(|ChannelValue(name, url)| (name, url)), .map(|ChannelValue(name, url)| (name, url)),
); );
harmonic.modify_profile(!no_modify_profile); harmonic.modify_profile(!no_modify_profile);
if !interaction::confirm("Are you ready to continue?").await? { // TODO(@Hoverbear): Make this smarter
if !interaction::confirm(
"\
Ready to install nix?\n\
\n\
This installer will:\n\
\n\
* Create a `nixbld` group\n\
* Create several `nixbld*` users\n\
* Create several Nix related directories\n\
* Place channel configurations\n\
* Fetch a copy of Nix and unpack it\n\
* Configure the shell profiles of various shells\n\
* Place a Nix configuration\n\
* Configure the Nix daemon to work with your init\
",
)
.await?
{
interaction::clean_exit_with_message("Okay, didn't do anything! Bye!").await; interaction::clean_exit_with_message("Okay, didn't do anything! Bye!").await;
} }
@ -78,7 +109,6 @@ impl CommandExecute for HarmonicCli {
harmonic.configure_shell_profile().await?; harmonic.configure_shell_profile().await?;
harmonic.setup_default_profile().await?; harmonic.setup_default_profile().await?;
harmonic.place_nix_configuration().await?; harmonic.place_nix_configuration().await?;
harmonic.configure_nix_daemon_service().await?; harmonic.configure_nix_daemon_service().await?;
Ok(ExitCode::SUCCESS) Ok(ExitCode::SUCCESS)