mirror of
https://github.com/daylinmorgan/oizys.git
synced 2024-12-28 06:40:44 -06:00
Compare commits
4 commits
e46eaa3bf8
...
2e630e6d6c
Author | SHA1 | Date | |
---|---|---|---|
2e630e6d6c | |||
461c7c393a | |||
5c0e1cb3ac | |||
2c278b0501 |
15 changed files with 336 additions and 18 deletions
81
flake.lock
81
flake.lock
|
@ -55,6 +55,24 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"flake-utils_2": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems_4"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1705309234,
|
||||||
|
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"hyprcursor": {
|
"hyprcursor": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"hyprlang": "hyprlang",
|
"hyprlang": "hyprlang",
|
||||||
|
@ -94,11 +112,11 @@
|
||||||
"xdph": "xdph"
|
"xdph": "xdph"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1711985879,
|
"lastModified": 1712248444,
|
||||||
"narHash": "sha256-Gv0GD7NqsO6M4WeORRTK+LCfNjZD7LGhAZTapoZortw=",
|
"narHash": "sha256-ayxuwrzpow3cRoKtCYj3v7GGrDHTbKVDDUxb8wd1cL8=",
|
||||||
"owner": "hyprwm",
|
"owner": "hyprwm",
|
||||||
"repo": "Hyprland",
|
"repo": "Hyprland",
|
||||||
"rev": "db1506130b507f92e0daf3a36495fb985e242bbc",
|
"rev": "c4b660a33930a0e60e853b6796c1fd76914b1719",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -285,11 +303,11 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1711715736,
|
"lastModified": 1712192574,
|
||||||
"narHash": "sha256-9slQ609YqT9bT/MNX9+5k5jltL9zgpn36DpFB7TkttM=",
|
"narHash": "sha256-LbbVOliJKTF4Zl2b9salumvdMXuQBr2kuKP5+ZwbYq4=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "807c549feabce7eddbf259dbdcec9e0600a0660d",
|
"rev": "f480f9d09e4b4cf87ee6151eba068197125714de",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -324,11 +342,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1711889114,
|
"lastModified": 1712237761,
|
||||||
"narHash": "sha256-e3gegueJAWQVrE4SXYh13Uu6tOCjpnagqHiKOQ7B31c=",
|
"narHash": "sha256-NoMBBCADTms3yx5BL+sbc7vfDivNiYULO6t9GBAsPt0=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "nixpkgs-wayland",
|
"repo": "nixpkgs-wayland",
|
||||||
"rev": "8c4df2153c615554b516ba698f5f7bd64f7bf520",
|
"rev": "9b77653338f52da4b498abdf4835efb6ff6e453e",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -382,16 +400,17 @@
|
||||||
"nixpkgs-wayland": "nixpkgs-wayland",
|
"nixpkgs-wayland": "nixpkgs-wayland",
|
||||||
"pinix": "pinix",
|
"pinix": "pinix",
|
||||||
"stable": "stable",
|
"stable": "stable",
|
||||||
"tsm": "tsm"
|
"tsm": "tsm",
|
||||||
|
"zig2nix": "zig2nix"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"stable": {
|
"stable": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1711668574,
|
"lastModified": 1712168706,
|
||||||
"narHash": "sha256-u1dfs0ASQIEr1icTVrsKwg2xToIpn7ZXxW3RHfHxshg=",
|
"narHash": "sha256-XP24tOobf6GGElMd0ux90FEBalUtw6NkBSVh/RlA6ik=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "219951b495fc2eac67b1456824cc1ec1fd2ee659",
|
"rev": "1487bdea619e4a7a53a4590c475deabb5a9d1bfb",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -446,6 +465,21 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"systems_4": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"treefmt-nix": {
|
"treefmt-nix": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": [
|
"nixpkgs": [
|
||||||
|
@ -541,6 +575,27 @@
|
||||||
"repo": "xdg-desktop-portal-hyprland",
|
"repo": "xdg-desktop-portal-hyprland",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"zig2nix": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils_2",
|
||||||
|
"nixpkgs": [
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1712193674,
|
||||||
|
"narHash": "sha256-VNFjRCfTYvWP2UvjA9r/44qrTXZ+JGOVnYSTDSajdeM=",
|
||||||
|
"owner": "Cloudef",
|
||||||
|
"repo": "zig2nix",
|
||||||
|
"rev": "31122d9accecf7d281229bb9e12dedddef120a1f",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "Cloudef",
|
||||||
|
"repo": "zig2nix",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": "root",
|
"root": "root",
|
||||||
|
|
|
@ -22,6 +22,9 @@
|
||||||
|
|
||||||
nix-index-database.url = "github:nix-community/nix-index-database";
|
nix-index-database.url = "github:nix-community/nix-index-database";
|
||||||
nix-index-database.inputs.nixpkgs.follows = "nixpkgs";
|
nix-index-database.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
|
||||||
|
zig2nix.url = "github:Cloudef/zig2nix";
|
||||||
|
zig2nix.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
|
|
||||||
nixConfig = {
|
nixConfig = {
|
||||||
|
|
|
@ -10,7 +10,7 @@ inputs: let
|
||||||
#supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"];
|
#supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"];
|
||||||
supportedSystems = ["x86_64-linux"];
|
supportedSystems = ["x86_64-linux"];
|
||||||
in rec {
|
in rec {
|
||||||
forAllSystems = f: genAttrs supportedSystems (system: f nixpkgs.legacyPackages.${system});
|
forAllSystems = f: genAttrs supportedSystems (system: f (import nixpkgs {inherit system;}));
|
||||||
|
|
||||||
nixosModules = listToAttrs (findModulesList ../modules);
|
nixosModules = listToAttrs (findModulesList ../modules);
|
||||||
|
|
||||||
|
@ -32,9 +32,10 @@ in rec {
|
||||||
oizysHosts = mapAttrs (name: _: mkSystem name) (readDir ../hosts);
|
oizysHosts = mapAttrs (name: _: mkSystem name) (readDir ../hosts);
|
||||||
oizysPkg = forAllSystems (
|
oizysPkg = forAllSystems (
|
||||||
pkgs: rec {
|
pkgs: rec {
|
||||||
|
oizys-zig = pkgs.callPackage ../pkgs/oizys/oizys-zig { zig2nix = inputs.zig2nix;};
|
||||||
oizys-nim = pkgs.callPackage ../pkgs/oizys/oizys-nim {};
|
oizys-nim = pkgs.callPackage ../pkgs/oizys/oizys-nim {};
|
||||||
oizys = pkgs.callPackage ../pkgs/oizys/oizys-rs {};
|
oizys-rs = pkgs.callPackage ../pkgs/oizys/oizys-rs {};
|
||||||
default = oizys;
|
default = oizys-zig;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
devShells = forAllSystems (
|
devShells = forAllSystems (
|
||||||
|
|
|
@ -20,6 +20,11 @@ in {
|
||||||
|
|
||||||
libreoffice-qt
|
libreoffice-qt
|
||||||
hunspell # spell check for libreoffice
|
hunspell # spell check for libreoffice
|
||||||
|
|
||||||
|
(catppuccin-gtk.override {
|
||||||
|
accents = ["rosewater"];
|
||||||
|
variant = "mocha";
|
||||||
|
})
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
{
|
{
|
||||||
|
inputs,
|
||||||
config,
|
config,
|
||||||
lib,
|
lib,
|
||||||
pkgs,
|
pkgs,
|
||||||
|
@ -6,11 +7,12 @@
|
||||||
}: let
|
}: let
|
||||||
inherit (lib) mkIfIn;
|
inherit (lib) mkIfIn;
|
||||||
cfg = config.oizys.languages;
|
cfg = config.oizys.languages;
|
||||||
|
zig = inputs.zig2nix.outputs.packages.${pkgs.system}.zig.master.bin;
|
||||||
in {
|
in {
|
||||||
config = mkIfIn "misc" cfg {
|
config = mkIfIn "misc" cfg {
|
||||||
environment.systemPackages = with pkgs; [
|
environment.systemPackages = with pkgs; [
|
||||||
go
|
go
|
||||||
rustup
|
rustup
|
||||||
];
|
] ++ [ zig ];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
nil
|
nil
|
||||||
alejandra
|
alejandra
|
||||||
|
|
||||||
self.packages.${pkgs.system}.oizys
|
self.packages.${pkgs.system}.default
|
||||||
inputs.pinix.packages.${pkgs.system}.default
|
inputs.pinix.packages.${pkgs.system}.default
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
installShellFiles,
|
installShellFiles,
|
||||||
rustPlatform,
|
rustPlatform,
|
||||||
|
nix-output-monitor,
|
||||||
}:
|
}:
|
||||||
rustPlatform.buildRustPackage {
|
rustPlatform.buildRustPackage {
|
||||||
pname = "oizys";
|
pname = "oizys";
|
||||||
|
@ -11,6 +12,7 @@ rustPlatform.buildRustPackage {
|
||||||
};
|
};
|
||||||
|
|
||||||
nativeBuildInputs = [installShellFiles];
|
nativeBuildInputs = [installShellFiles];
|
||||||
|
buildInputs = [nix-output-monitor];
|
||||||
|
|
||||||
postInstall = ''
|
postInstall = ''
|
||||||
installShellCompletion --cmd oizys \
|
installShellCompletion --cmd oizys \
|
||||||
|
|
13
pkgs/oizys/oizys-zig/.gitignore
vendored
Normal file
13
pkgs/oizys/oizys-zig/.gitignore
vendored
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# Created by https://www.toptal.com/developers/gitignore/api/zig
|
||||||
|
# Edit at https://www.toptal.com/developers/gitignore?templates=zig
|
||||||
|
|
||||||
|
### zig ###
|
||||||
|
# Zig programming language
|
||||||
|
|
||||||
|
zig-cache/
|
||||||
|
zig-out/
|
||||||
|
build/
|
||||||
|
build-*/
|
||||||
|
docgen_tmp/
|
||||||
|
|
||||||
|
# End of https://www.toptal.com/developers/gitignore/api/zig
|
36
pkgs/oizys/oizys-zig/build.zig
Normal file
36
pkgs/oizys/oizys-zig/build.zig
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
pub fn build(b: *std.Build) void {
|
||||||
|
b.release_mode = .safe;
|
||||||
|
const target = b.standardTargetOptions(.{});
|
||||||
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
|
||||||
|
const exe = b.addExecutable(.{
|
||||||
|
.name = "oizys",
|
||||||
|
.root_source_file = .{ .path = "src/main.zig" },
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
});
|
||||||
|
exe.root_module.addImport("yazap", b.dependency("yazap", .{ .target = target }).module("yazap"));
|
||||||
|
b.installArtifact(exe);
|
||||||
|
|
||||||
|
const run_cmd = b.addRunArtifact(exe);
|
||||||
|
run_cmd.step.dependOn(b.getInstallStep());
|
||||||
|
if (b.args) |args| {
|
||||||
|
run_cmd.addArgs(args);
|
||||||
|
}
|
||||||
|
const run_step = b.step("run", "Run the app");
|
||||||
|
run_step.dependOn(&run_cmd.step);
|
||||||
|
|
||||||
|
// I haven't written any...
|
||||||
|
// const exe_unit_tests = b.addTest(.{
|
||||||
|
// .root_source_file = .{ .path = "src/main.zig" },
|
||||||
|
// .target = target,
|
||||||
|
// .optimize = optimize,
|
||||||
|
// });
|
||||||
|
//
|
||||||
|
// const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
|
||||||
|
// const test_step = b.step("test", "Run unit tests");
|
||||||
|
// test_step.dependOn(&run_exe_unit_tests.step);
|
||||||
|
//
|
||||||
|
}
|
11
pkgs/oizys/oizys-zig/build.zig.zon
Normal file
11
pkgs/oizys/oizys-zig/build.zig.zon
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
.{
|
||||||
|
.name = "oizys-zig",
|
||||||
|
.version = "0.0.0",
|
||||||
|
.dependencies = .{
|
||||||
|
.yazap = .{
|
||||||
|
.url = "git+https://github.com/cdmistman/yazap.git#1ae1a5b562f5c66caf8e87e04313094f16e327fc",
|
||||||
|
.hash = "1220fa71798c994044a987cbde6e73af76bfc402117a61971ccf48f4af4b7154e8d3",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.paths = .{""},
|
||||||
|
}
|
7
pkgs/oizys/oizys-zig/build.zig.zon2json-lock
Normal file
7
pkgs/oizys/oizys-zig/build.zig.zon2json-lock
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"1220fa71798c994044a987cbde6e73af76bfc402117a61971ccf48f4af4b7154e8d3": {
|
||||||
|
"name": "yazap",
|
||||||
|
"url": "git+https://github.com/cdmistman/yazap.git#1ae1a5b562f5c66caf8e87e04313094f16e327fc",
|
||||||
|
"hash": "sha256-nNhFpay+xk0Ix3GAT1fZ2q/bD9AAx7Xkl4X7QxlzK0M="
|
||||||
|
}
|
||||||
|
}
|
12
pkgs/oizys/oizys-zig/default.nix
Normal file
12
pkgs/oizys/oizys-zig/default.nix
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
pkgs,
|
||||||
|
zig2nix,
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
(zig2nix.outputs.zig-env.${pkgs.system} {
|
||||||
|
zig = zig2nix.outputs.packages.${pkgs.system}.zig.master.bin;
|
||||||
|
}).package {
|
||||||
|
name = "oizys";
|
||||||
|
src = lib.cleanSource ./.;
|
||||||
|
}
|
35
pkgs/oizys/oizys-zig/src/Cli.zig
Normal file
35
pkgs/oizys/oizys-zig/src/Cli.zig
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
const Cli = @This();
|
||||||
|
const std = @import("std");
|
||||||
|
const yazap = @import("yazap");
|
||||||
|
const App = yazap.App;
|
||||||
|
const Arg = yazap.Arg;
|
||||||
|
|
||||||
|
const Allocator = std.mem.Allocator;
|
||||||
|
app: App,
|
||||||
|
|
||||||
|
pub fn init(allocator: Allocator) !Cli {
|
||||||
|
var app = App.init(allocator, "oizys", "nix begat oizys");
|
||||||
|
|
||||||
|
const oizys = app.rootCommand();
|
||||||
|
var cmd_dry = app.createCommand("dry", "poor man's nix flake check");
|
||||||
|
var cmd_build = app.createCommand("build", "build nixos (w/nix build)");
|
||||||
|
var cmd_cache = app.createCommand("cache", "build and push to cachix");
|
||||||
|
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| {
|
||||||
|
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 };
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn deinit(self: *Cli) void {
|
||||||
|
self.app.deinit();
|
||||||
|
}
|
114
pkgs/oizys/oizys-zig/src/Oizys.zig
Normal file
114
pkgs/oizys/oizys-zig/src/Oizys.zig
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
const Oizys = @This();
|
||||||
|
const std = @import("std");
|
||||||
|
const ArgMatches = @import("yazap").ArgMatches;
|
||||||
|
const Allocator = std.mem.Allocator;
|
||||||
|
|
||||||
|
allocator: Allocator,
|
||||||
|
flake: []const u8,
|
||||||
|
host: []const u8,
|
||||||
|
cache_name: []const u8,
|
||||||
|
output: []const u8,
|
||||||
|
cmd: OizysCmd,
|
||||||
|
debug: bool = false,
|
||||||
|
no_pinix: bool = false,
|
||||||
|
|
||||||
|
pub const OizysCmd = enum {
|
||||||
|
dry,
|
||||||
|
@"switch",
|
||||||
|
boot,
|
||||||
|
cache,
|
||||||
|
output,
|
||||||
|
build,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn init(allocator: std.mem.Allocator, matches: *const ArgMatches) !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 cache_name = flags.getSingleValue("cache") orelse "daylin";
|
||||||
|
|
||||||
|
return Oizys{
|
||||||
|
.allocator = allocator,
|
||||||
|
.host = host,
|
||||||
|
.flake = flake,
|
||||||
|
.output = try std.fmt.allocPrint(allocator, "{s}#nixosConfigurations.{s}.config.system.build.toplevel", .{ flake, host }),
|
||||||
|
.cmd = std.meta.stringToEnum(OizysCmd, cmd).?,
|
||||||
|
.cache_name = cache_name,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn deinit(self: *Oizys) void {
|
||||||
|
self.allocator.free(self.flake);
|
||||||
|
self.allocator.free(self.host);
|
||||||
|
self.allocator.free(self.output);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn nix(self: *Oizys) []const u8 {
|
||||||
|
return if (self.no_pinix) "nix" else "pix";
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn nixos_rebuild(self: *Oizys) []const u8 {
|
||||||
|
return if (self.no_pinix) "nixos-rebuild" else "pixos-rebuild";
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn getDefaultHostName(allocator: Allocator) ![]const u8 {
|
||||||
|
var name_buffer: [std.posix.HOST_NAME_MAX]u8 = undefined;
|
||||||
|
const hostname = try std.posix.gethostname(&name_buffer);
|
||||||
|
return std.fmt.allocPrint(allocator, "{s}", .{hostname});
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn getDefaultFlake(allocator: Allocator) ![]const u8 {
|
||||||
|
return std.process.getEnvVarOwned(allocator, "OIZYS_DIR") catch {
|
||||||
|
const homedir = try std.process.getEnvVarOwned(allocator, "HOME");
|
||||||
|
defer allocator.free(homedir);
|
||||||
|
return try std.fmt.allocPrint(allocator, "{s}/oizys", .{homedir});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn getOutputPath(self: *Oizys) ![]const u8 {
|
||||||
|
return std.fmt.allocPrint(self.allocator, "{s}#nixosConfigurations.{s}.config.system.build.toplevel", .{ self.flake, self.host });
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const NixCmd = enum { Nix, NixosRebuild };
|
||||||
|
|
||||||
|
pub fn runNixCmd(self: *Oizys, cmd: NixCmd, argv: []const []const u8) !void {
|
||||||
|
var args = std.ArrayList([]const u8).init(self.allocator);
|
||||||
|
defer args.deinit();
|
||||||
|
|
||||||
|
switch (cmd) {
|
||||||
|
NixCmd.Nix => try args.append(self.nix()),
|
||||||
|
NixCmd.NixosRebuild => try args.appendSlice(&.{ "sudo", self.nixos_rebuild() }),
|
||||||
|
}
|
||||||
|
try args.appendSlice(argv);
|
||||||
|
var p = std.ChildProcess.init(args.items, self.allocator);
|
||||||
|
_ = try p.spawnAndWait();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn cache(self: *Oizys) !void {
|
||||||
|
var p = std.ChildProcess.init(&.{ "cachix", "watch-exec", self.cache_name,"--verbose" ,"--", "nix", "build", self.flake, "--print-build-logs", "--accept-flake-config" }, self.allocator);
|
||||||
|
_ = try p.spawnAndWait();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run(self: *Oizys) !void {
|
||||||
|
switch (self.cmd) {
|
||||||
|
.@"switch" => {
|
||||||
|
try self.runNixCmd(NixCmd.NixosRebuild, &.{ "switch", "--flake", self.flake });
|
||||||
|
},
|
||||||
|
.boot => {
|
||||||
|
try self.runNixCmd(NixCmd.NixosRebuild, &.{ "boot", "--flake", self.flake });
|
||||||
|
},
|
||||||
|
.dry => {
|
||||||
|
try self.runNixCmd(NixCmd.Nix, &.{ "build", self.output, "--dry-run" });
|
||||||
|
},
|
||||||
|
.build => {
|
||||||
|
try self.runNixCmd(NixCmd.Nix, &.{ "build", self.output });
|
||||||
|
},
|
||||||
|
.output => {
|
||||||
|
std.debug.print("{s}", .{self.output});
|
||||||
|
},
|
||||||
|
.cache => {
|
||||||
|
try self.cache();
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
22
pkgs/oizys/oizys-zig/src/main.zig
Normal file
22
pkgs/oizys/oizys-zig/src/main.zig
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
const std = @import("std");
|
||||||
|
const Oizys = @import("Oizys.zig");
|
||||||
|
const Cli = @import("Cli.zig");
|
||||||
|
|
||||||
|
pub fn main() !void {
|
||||||
|
// memory management isn't hard :P
|
||||||
|
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
||||||
|
defer arena.deinit();
|
||||||
|
const allocator = arena.allocator();
|
||||||
|
|
||||||
|
var cli = try Cli.init(allocator);
|
||||||
|
const matches = try cli.app.parseProcess();
|
||||||
|
|
||||||
|
if (!matches.containsArgs()) {
|
||||||
|
try cli.app.displayHelp();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var oizys = try Oizys.init(allocator, matches);
|
||||||
|
try oizys.run();
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue