feat: build nix configuration
This commit is contained in:
parent
35b36222d3
commit
ac55ccd2f5
1352
Cargo.lock
generated
1352
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "nixp-meta"
|
||||
name = "nim"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
|
@ -8,6 +8,7 @@ clap = { version = "4.5.20", features = ["derive"] }
|
|||
color-eyre = "0.6.3"
|
||||
regex = "1.11.1"
|
||||
reqwest = "0.12.9"
|
||||
russh = "0.46.0"
|
||||
serde = { version = "1.0.214", features = ["derive"] }
|
||||
serde_json = "1.0.132"
|
||||
tokio = { version = "1.41.1", features = ["full"] }
|
||||
|
|
10
flake.nix
10
flake.nix
|
@ -89,7 +89,7 @@
|
|||
path = ./.;
|
||||
numtideDevshell = "default";
|
||||
};
|
||||
nci.crates.nixp-meta = rec {
|
||||
nci.crates.nim = rec {
|
||||
depsDrvConfig = {
|
||||
mkDerivation = {
|
||||
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}
|
||||
# '';
|
||||
# });
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
67
src/main.rs
67
src/main.rs
|
@ -1,9 +1,12 @@
|
|||
use std::{
|
||||
env,
|
||||
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 pr::*;
|
||||
use regex::Regex;
|
||||
|
@ -25,6 +28,10 @@ enum CliCommands {
|
|||
UpdatePrs(UpdatePRs),
|
||||
/// Unconditionally add a new PR
|
||||
AddPr(AddPR),
|
||||
/// Build a nixos system
|
||||
Build(Deploy),
|
||||
/// Deploy a nixos system
|
||||
Deploy(Deploy),
|
||||
}
|
||||
|
||||
#[derive(Args, Debug, Default)]
|
||||
|
@ -41,6 +48,11 @@ struct AddPR {
|
|||
path: String,
|
||||
}
|
||||
|
||||
#[derive(Args, Debug, Default)]
|
||||
struct Deploy {
|
||||
systems: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Args, Debug, Default)]
|
||||
struct Track {
|
||||
pr: String,
|
||||
|
@ -110,6 +122,59 @@ async fn main() -> Result<()> {
|
|||
let pr = parse_pr(&opts.pr)?;
|
||||
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(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue