feat: build nix configuration

This commit is contained in:
Patrick 2024-12-01 22:31:11 +01:00
parent 35b36222d3
commit ac55ccd2f5
Signed by: patrick
GPG key ID: 451F95EFB8BECD0F
4 changed files with 1419 additions and 13 deletions

1352
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,5 @@
[package] [package]
name = "nixp-meta" name = "nim"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
@ -8,6 +8,7 @@ clap = { version = "4.5.20", features = ["derive"] }
color-eyre = "0.6.3" color-eyre = "0.6.3"
regex = "1.11.1" regex = "1.11.1"
reqwest = "0.12.9" reqwest = "0.12.9"
russh = "0.46.0"
serde = { version = "1.0.214", features = ["derive"] } serde = { version = "1.0.214", features = ["derive"] }
serde_json = "1.0.132" serde_json = "1.0.132"
tokio = { version = "1.41.1", features = ["full"] } tokio = { version = "1.41.1", features = ["full"] }

View file

@ -89,7 +89,7 @@
path = ./.; path = ./.;
numtideDevshell = "default"; numtideDevshell = "default";
}; };
nci.crates.nixp-meta = rec { nci.crates.nim = rec {
depsDrvConfig = { depsDrvConfig = {
mkDerivation = { mkDerivation = {
nativeBuildInputs = [ pkgs.pkg-config ]; nativeBuildInputs = [ pkgs.pkg-config ];
@ -106,14 +106,6 @@
}; };
}; };
# devShells.default = config.nci.outputs.main.devShell.overrideAttrs (old: {
# nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.cargo-release ];
#
# shellHook = ''
# ${old.shellHook or ""}
# ${config.pre-commit.installationScript}
# '';
# });
}; };
}; };
} }

View file

@ -1,9 +1,12 @@
use std::{ use std::{
env, env,
fs::{self, read_dir}, fs::{self, read_dir},
io::Error,
path::PathBuf,
process::{Command, Stdio},
}; };
use clap::{Args, Parser, Subcommand}; use clap::{error::ErrorKind, Args, CommandFactory, Parser, Subcommand};
use color_eyre::eyre::{bail, Result}; use color_eyre::eyre::{bail, Result};
use pr::*; use pr::*;
use regex::Regex; use regex::Regex;
@ -25,6 +28,10 @@ enum CliCommands {
UpdatePrs(UpdatePRs), UpdatePrs(UpdatePRs),
/// Unconditionally add a new PR /// Unconditionally add a new PR
AddPr(AddPR), AddPr(AddPR),
/// Build a nixos system
Build(Deploy),
/// Deploy a nixos system
Deploy(Deploy),
} }
#[derive(Args, Debug, Default)] #[derive(Args, Debug, Default)]
@ -41,6 +48,11 @@ struct AddPR {
path: String, path: String,
} }
#[derive(Args, Debug, Default)]
struct Deploy {
systems: Vec<String>,
}
#[derive(Args, Debug, Default)] #[derive(Args, Debug, Default)]
struct Track { struct Track {
pr: String, pr: String,
@ -110,6 +122,59 @@ async fn main() -> Result<()> {
let pr = parse_pr(&opts.pr)?; let pr = parse_pr(&opts.pr)?;
get_diff(pr, &opts.path, &client).await?; get_diff(pr, &opts.path, &client).await?;
} }
CliCommands::Build(opts) => {
let dir = env::var("PRJ_ROOT")
.map(PathBuf::from)
.or_else(|_| env::current_dir())?;
if opts.systems.is_empty() {
let mut cmd = Cli::command();
cmd.error(
ErrorKind::MissingRequiredArgument,
"At least one system needed",
)
.exit()
}
let mut configs = Vec::new();
for s in &opts.systems {
configs.push(format!(
".#nixosConfigurations.{}.config.system.build.toplevel",
s
));
}
println!("{:?}", configs);
let mut cmd = Command::new("nom");
let mut cmd = if cmd
.arg("--version")
.current_dir(dir)
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
.is_err()
{
Command::new("nix")
} else {
Command::new("nom")
};
let cmd = cmd
.arg("build")
.arg("--print-out-paths")
.arg("--no-link")
.args(configs);
cmd.spawn()?.wait()?;
println!();
}
CliCommands::Deploy(opts) => {
if opts.systems.is_empty() {
let mut cmd = Cli::command();
cmd.error(
ErrorKind::MissingRequiredArgument,
"At least one system needed",
)
.exit()
}
}
}; };
Ok(()) Ok(())
} }