Compare commits

...

7 Commits

Author SHA1 Message Date
Daylin Morgan 69ac3fa6a6
add some pointless defers 2024-04-11 15:22:49 -05:00
Daylin Morgan 7dfe185a9f
use seperate funtion to get forwarded args 2024-04-11 13:57:58 -05:00
Daylin Morgan a7302bd609
accept additional positional args to forward 2024-04-11 13:28:50 -05:00
Daylin Morgan bf192f478d
flake.lock: Update
Flake lock file updates:

• Updated input 'hyprland':
    'github:hyprwm/Hyprland/63e3668529f6c06478ec288723d0ba46374c4bc5?narHash=sha256-8/JkRxsXLhiGELcw7t5RBf1mk94mbHc/oJiBzoPYTv8%3D' (2024-04-08)
  → 'github:hyprwm/Hyprland/185a3b48814cc4a1afbf32a69792a6161c4038cd?narHash=sha256-m44SvLfwPc8qPpBQa5ObOtTe6RbVNfQLpn%2BbCdlHFxQ%3D' (2024-04-11)
• Updated input 'nixpkgs':
    'github:nixos/nixpkgs/0d28066770464d19d637f6e8e42e8688420b6ac6?narHash=sha256-xxon7WwNm4/EadMKg1eF40/5s0O78nXUy2ILZt6vT7E%3D' (2024-04-08)
  → 'github:nixos/nixpkgs/d6b3ddd253c578a7ab98f8011e59990f21dc3932?narHash=sha256-kR7C7Fqt3JP40h0mzmSZeWI5pk1iwqj4CSeGjnUbVHc%3D' (2024-04-10)
• Updated input 'nixpkgs-wayland':
    'github:nix-community/nixpkgs-wayland/2547cb5b49297ad22dee07f6847c7a99a99f7721?narHash=sha256-pyppS3qgeZagY/YZF0ug2rf97Z91%2BgaUwnS0McFuH1k%3D' (2024-04-08)
  → 'github:nix-community/nixpkgs-wayland/ed9ef02d368c00e69e8e67fa86d0226559df75aa?narHash=sha256-HByQWVHn0sG7BFj%2B7z9UhhMY9CcCqaWBPXX5H3QKRyQ%3D' (2024-04-11)
• Updated input 'stable':
    'github:nixos/nixpkgs/e38d7cb66ea4f7a0eb6681920615dfcc30fc2920?narHash=sha256-g0whLLwRvgO2FsyhY8fNk%2BTWenS3jg5UdlWL4uqgFeo%3D' (2024-04-06)
  → 'github:nixos/nixpkgs/b2cf36f43f9ef2ded5711b30b1f393ac423d8f72?narHash=sha256-bCs0%2BMSTra80oXAsnM6Oq62WsirOIaijQ/BbUY59tR4%3D' (2024-04-10)
• Updated input 'zig2nix':
    'github:Cloudef/zig2nix/53e12c1a03c34b0b35bcb0eb5b495ba90f62302f?narHash=sha256-TIcl3dKFqSymIFUj3vRN05Ahl2eAH/EqJRf/P5nCBtY%3D' (2024-04-08)
  → 'github:Cloudef/zig2nix/c5279639cbbb10df20a340f54dd95b562fafc552?narHash=sha256-eWGnAesSlXa7E2ugjwPT7g1HVs0uPPoLL2NT9sOzKCU%3D' (2024-04-11)
2024-04-11 09:58:06 -05:00
Daylin Morgan 7fc911b1a8
actually use stdout 2024-04-09 12:16:25 -05:00
Daylin Morgan a160e2eccc
note to self 2024-04-08 11:43:35 -05:00
Daylin Morgan 6bbc8aa28a
formatting 2024-04-08 11:42:48 -05:00
4 changed files with 74 additions and 26 deletions

View File

@ -205,11 +205,11 @@
"xdph": "xdph"
},
"locked": {
"lastModified": 1712586782,
"narHash": "sha256-8/JkRxsXLhiGELcw7t5RBf1mk94mbHc/oJiBzoPYTv8=",
"lastModified": 1712835979,
"narHash": "sha256-m44SvLfwPc8qPpBQa5ObOtTe6RbVNfQLpn+bCdlHFxQ=",
"owner": "hyprwm",
"repo": "Hyprland",
"rev": "63e3668529f6c06478ec288723d0ba46374c4bc5",
"rev": "185a3b48814cc4a1afbf32a69792a6161c4038cd",
"type": "github"
},
"original": {
@ -385,11 +385,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1712573573,
"narHash": "sha256-xxon7WwNm4/EadMKg1eF40/5s0O78nXUy2ILZt6vT7E=",
"lastModified": 1712757991,
"narHash": "sha256-kR7C7Fqt3JP40h0mzmSZeWI5pk1iwqj4CSeGjnUbVHc=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "0d28066770464d19d637f6e8e42e8688420b6ac6",
"rev": "d6b3ddd253c578a7ab98f8011e59990f21dc3932",
"type": "github"
},
"original": {
@ -424,11 +424,11 @@
]
},
"locked": {
"lastModified": 1712589286,
"narHash": "sha256-pyppS3qgeZagY/YZF0ug2rf97Z91+gaUwnS0McFuH1k=",
"lastModified": 1712844911,
"narHash": "sha256-HByQWVHn0sG7BFj+7z9UhhMY9CcCqaWBPXX5H3QKRyQ=",
"owner": "nix-community",
"repo": "nixpkgs-wayland",
"rev": "2547cb5b49297ad22dee07f6847c7a99a99f7721",
"rev": "ed9ef02d368c00e69e8e67fa86d0226559df75aa",
"type": "github"
},
"original": {
@ -490,11 +490,11 @@
},
"stable": {
"locked": {
"lastModified": 1712437997,
"narHash": "sha256-g0whLLwRvgO2FsyhY8fNk+TWenS3jg5UdlWL4uqgFeo=",
"lastModified": 1712741485,
"narHash": "sha256-bCs0+MSTra80oXAsnM6Oq62WsirOIaijQ/BbUY59tR4=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "e38d7cb66ea4f7a0eb6681920615dfcc30fc2920",
"rev": "b2cf36f43f9ef2ded5711b30b1f393ac423d8f72",
"type": "github"
},
"original": {
@ -691,11 +691,11 @@
]
},
"locked": {
"lastModified": 1712539287,
"narHash": "sha256-TIcl3dKFqSymIFUj3vRN05Ahl2eAH/EqJRf/P5nCBtY=",
"lastModified": 1712798505,
"narHash": "sha256-eWGnAesSlXa7E2ugjwPT7g1HVs0uPPoLL2NT9sOzKCU=",
"owner": "Cloudef",
"repo": "zig2nix",
"rev": "53e12c1a03c34b0b35bcb0eb5b495ba90f62302f",
"rev": "c5279639cbbb10df20a340f54dd95b562fafc552",
"type": "github"
},
"original": {

View File

@ -3,9 +3,13 @@ const std = @import("std");
const yazap = @import("yazap");
const App = yazap.App;
const Arg = yazap.Arg;
const Allocator = std.mem.Allocator;
allocator: Allocator,
app: App,
matches: *const yazap.ArgMatches = undefined,
forward: ?[][]const u8 = null,
process_args: ?[]const [:0]u8 = null,
pub fn init(allocator: Allocator) !Cli {
var app = App.init(allocator, "oizys", "nix begat oizys");
@ -17,19 +21,55 @@ pub fn init(allocator: Allocator) !Cli {
var cmd_output = app.createCommand("output", "show system flake output path");
var cmd_boot = app.createCommand("boot", "nixos rebuild boot");
var cmd_switch = app.createCommand("switch", "nixos rebuild switch");
const commands = .{ &cmd_dry, &cmd_build, &cmd_cache, &cmd_output, &cmd_switch, &cmd_boot };
try cmd_cache.addArg(Arg.singleValueOption("name", 'n', "name of cachix cache"));
inline for (commands) |subcmd| {
inline for (.{
&cmd_dry,
&cmd_build,
&cmd_cache,
&cmd_output,
&cmd_switch,
&cmd_boot,
}) |subcmd| {
try subcmd.addArg(Arg.positional("forward", null, null));
try subcmd.addArg(Arg.singleValueOption("flake", 'f', "path to flake"));
try subcmd.addArg(Arg.singleValueOption("host", null, "hostname (default: current host)"));
try subcmd.addArg(Arg.booleanOption("no-pinix", null, "don't use pinix"));
try oizys.addSubcommand(subcmd.*);
}
return Cli{ .app = app };
return Cli{
.allocator = allocator,
.app = app,
};
}
fn get_forward_args(self: *Cli, args: []const [:0]u8) !usize {
var forward = std.ArrayList([]const u8).init(self.allocator);
const delim_idx: usize = delim_lookup: for (args, 0..) |arg, i| {
if (std.mem.eql(u8, "--", arg)) break :delim_lookup i;
} else args.len;
if (args.len > delim_idx)
for (args[delim_idx + 1 ..]) |fwd|
try forward.append(fwd);
self.forward = try forward.toOwnedSlice();
return delim_idx;
}
pub fn parse(self: *Cli) !void {
self.process_args = try std.process.argsAlloc(self.allocator);
const delim_idx = try self.get_forward_args(self.process_args.?);
self.matches = try self.app.parseFrom(self.process_args.?[1..delim_idx]);
}
pub fn deinit(self: *Cli) void {
std.process.argsFree(self.allocator, self.process_args.?);
if (self.forward) |fwd| {
for (fwd) |arg| self.allocator.free(arg);
self.allocator.free(fwd);
}
self.app.deinit();
}

View File

@ -11,6 +11,7 @@ output: []const u8,
cmd: OizysCmd,
no_pinix: bool,
debug: bool = false,
forward: ?[][]const u8,
pub const OizysCmd = enum {
dry,
@ -21,11 +22,13 @@ pub const OizysCmd = enum {
build,
};
pub fn init(allocator: std.mem.Allocator, matches: *const ArgMatches) !Oizys {
pub fn init(allocator: std.mem.Allocator, matches: *const ArgMatches, forward: ?[][]const u8) !Oizys {
const cmd = matches.subcommand.?.name;
const flags = matches.subcommandMatches(cmd).?;
const host = flags.getSingleValue("host") orelse try Oizys.getDefaultHostName(allocator);
const flake = flags.getSingleValue("flake") orelse try Oizys.getDefaultFlake(allocator);
const host = flags.getSingleValue("host") orelse
try Oizys.getDefaultHostName(allocator);
const flake = flags.getSingleValue("flake") orelse
try Oizys.getDefaultFlake(allocator);
return Oizys{
.allocator = allocator,
@ -39,6 +42,7 @@ pub fn init(allocator: std.mem.Allocator, matches: *const ArgMatches) !Oizys {
.cmd = std.meta.stringToEnum(OizysCmd, cmd).?,
.cache_name = flags.getSingleValue("cache") orelse "daylin",
.no_pinix = flags.containsArg("no-pinix"),
.forward = forward,
};
}
@ -89,6 +93,7 @@ pub fn runNixCmd(self: *Oizys, cmd: NixCmd, argv: []const []const u8) !void {
NixCmd.NixosRebuild => try args.appendSlice(&.{ "sudo", self.nixos_rebuild() }),
}
try args.appendSlice(argv);
if (self.forward) |fwd| try args.appendSlice(fwd);
var p = std.ChildProcess.init(args.items, self.allocator);
_ = try p.spawnAndWait();
}
@ -127,7 +132,8 @@ pub fn run(self: *Oizys) !void {
try self.runNixCmd(NixCmd.Nix, &.{ "build", self.output });
},
.output => {
std.debug.print("{s}", .{self.output});
const stdout = std.io.getStdOut().writer();
try stdout.print("{s}\n", .{self.output});
},
.cache => {
try self.cache();

View File

@ -9,14 +9,16 @@ pub fn main() !void {
const allocator = arena.allocator();
var cli = try Cli.init(allocator);
const matches = try cli.app.parseProcess();
try cli.parse();
defer cli.deinit();
if (!matches.containsArgs()) {
if (!cli.matches.containsArgs()) {
try cli.app.displayHelp();
return;
}
var oizys = try Oizys.init(allocator, matches);
var oizys = try Oizys.init(allocator, cli.matches, cli.forward);
defer oizys.deinit();
try oizys.run();
}