Compare commits

..

No commits in common. "1df7c557a3ea3261c74f55f53b9f89116c1d7869" and "933f7e1ae0a3f0f82bb92bf9951c66d349274b23" have entirely different histories.

6 changed files with 24 additions and 76 deletions

View file

@ -1,7 +1,7 @@
{ {
description = "nix begat oizys"; description = "nix begat oizys";
outputs = inputs: (import ./lib inputs).oizysFlake; outputs = inputs:(import ./lib inputs).oizysFlake;
inputs = { inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";

View file

@ -42,12 +42,8 @@ in {
networking.hostName = "othalan"; networking.hostName = "othalan";
time.timeZone = "US/Central"; time.timeZone = "US/Central";
boot.loader = { boot.loader = {
systemd-boot = systemd-boot ={ enable = true; consoleMode = "max";};
enabled
// {
consoleMode = "max";
};
efi.canTouchEfiVariables = true; efi.canTouchEfiVariables = true;
}; };

View file

@ -130,15 +130,6 @@ dependencies = [
"strsim", "strsim",
] ]
[[package]]
name = "clap_complete"
version = "4.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "885e4d7d5af40bfb99ae6f9433e292feac98d452dcb3ec3d25dfe7552b77da8c"
dependencies = [
"clap",
]
[[package]] [[package]]
name = "clap_derive" name = "clap_derive"
version = "4.5.4" version = "4.5.4"
@ -381,7 +372,6 @@ name = "oizys"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"clap", "clap",
"clap_complete",
"homedir", "homedir",
"hostname", "hostname",
] ]

View file

@ -7,6 +7,5 @@ edition = "2021"
[dependencies] [dependencies]
clap = { version = "4.5.4", features = ["derive"] } clap = { version = "4.5.4", features = ["derive"] }
clap_complete = "4.5.1"
homedir = "0.2.1" homedir = "0.2.1"
hostname = "0.3.1" hostname = "0.3.1"

View file

@ -1,7 +1,4 @@
{ {rustPlatform}:
installShellFiles,
rustPlatform,
}:
rustPlatform.buildRustPackage { rustPlatform.buildRustPackage {
pname = "oizys"; pname = "oizys";
version = "unstable"; version = "unstable";
@ -9,11 +6,4 @@ rustPlatform.buildRustPackage {
cargoLock = { cargoLock = {
lockFile = ./Cargo.lock; lockFile = ./Cargo.lock;
}; };
nativeBuildInputs = [installShellFiles];
postInstall = ''
installShellCompletion --cmd oizys \
--zsh <($out/bin/oizys --completions zsh)
'';
} }

View file

@ -1,6 +1,5 @@
use clap::{CommandFactory, Parser, Subcommand}; use clap::{Parser, Subcommand};
use clap_complete::{generate, Generator, Shell}; use std::{env, path::PathBuf, process::Command};
use std::{env, io, path::PathBuf, process::Command};
#[derive(Parser)] #[derive(Parser)]
#[command(version, about, long_about = None)] #[command(version, about, long_about = None)]
@ -21,12 +20,8 @@ struct Cli {
#[arg(long, global=true, action = clap::ArgAction::SetTrue)] #[arg(long, global=true, action = clap::ArgAction::SetTrue)]
no_pinix: bool, no_pinix: bool,
/// generate shell completion
#[arg(long, value_enum)]
completions: Option<Shell>,
#[command(subcommand)] #[command(subcommand)]
command: Option<Commands>, command: Commands,
} }
#[derive(Debug, Subcommand)] #[derive(Debug, Subcommand)]
@ -51,11 +46,7 @@ enum Commands {
Build {}, Build {},
/// print nix flake output /// print nix flake output
Output {}, Path {},
}
fn print_completions<G: Generator>(gen: G, cmd: &mut clap::Command) {
generate(gen, cmd, cmd.get_name().to_string(), &mut io::stdout());
} }
#[derive(Debug)] #[derive(Debug)]
@ -67,24 +58,19 @@ struct Oizys {
} }
impl Oizys { impl Oizys {
fn from(cli: &Cli) -> Oizys { fn new(host: Option<String>, flake: Option<PathBuf>, no_pinix: bool, verbose: u8) -> Oizys {
let host = cli let hostname = hostname::get().unwrap().to_string_lossy().to_string();
.host let flake_path = env::var("OIZYS_DIR").map_or(
.clone()
.unwrap_or(hostname::get().unwrap().to_string_lossy().to_string());
let flake = cli.flake.clone().unwrap_or(env::var("OIZYS_DIR").map_or(
homedir::get_my_home().unwrap().unwrap().join("oizys"), homedir::get_my_home().unwrap().unwrap().join("oizys"),
PathBuf::from, PathBuf::from,
)); );
Oizys { Oizys {
host, host: host.unwrap_or(hostname),
flake, flake: flake.unwrap_or(flake_path),
no_pinix: cli.no_pinix, no_pinix,
verbose: cli.verbose, verbose,
} }
} }
fn output(self: &Oizys) -> String { fn output(self: &Oizys) -> String {
format!( format!(
"{}#nixosConfigurations.{}.config.system.build.toplevel", "{}#nixosConfigurations.{}.config.system.build.toplevel",
@ -160,14 +146,7 @@ impl Oizys {
fn main() { fn main() {
let cli = Cli::parse(); let cli = Cli::parse();
let oizys = Oizys::from(&cli); let oizys = Oizys::new(cli.host, cli.flake, cli.no_pinix, cli.verbose);
if let Some(completions) = cli.completions {
let mut cmd = Cli::command();
eprintln!("Generating completion for {completions:?}");
print_completions(completions, &mut cmd);
std::process::exit(0);
}
if oizys.verbose > 2 { if oizys.verbose > 2 {
println!("-vv is max verbosity") println!("-vv is max verbosity")
@ -176,18 +155,12 @@ fn main() {
println!("{:?}", oizys) println!("{:?}", oizys)
} }
if let Some(command) = &cli.command { match &cli.command {
match command { Commands::Dry {} => oizys.build(true),
Commands::Dry {} => oizys.build(true), Commands::Build {} => oizys.build(false),
Commands::Build {} => oizys.build(false), Commands::Path {} => println!("{}", oizys.output()),
Commands::Output {} => println!("{}", oizys.output()), Commands::Boot {} => oizys.nixos_rebuild("boot"),
Commands::Boot {} => oizys.nixos_rebuild("boot"), Commands::Switch {} => oizys.nixos_rebuild("switch"),
Commands::Switch {} => oizys.nixos_rebuild("switch"), Commands::Cache { name } => oizys.cache(name),
Commands::Cache { name } => oizys.cache(name),
}
} else {
eprintln!("No subcommand provided..");
let mut cmd = Cli::command();
cmd.print_help().unwrap();
} }
} }