From 0c8f136b143ab8f5a2241e85e7799f2e871cbd5a Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Tue, 14 Apr 2026 19:16:38 -0400 Subject: [PATCH] better ccli --- bin/skyg | 36 ++++++++++++++++++---------- modules/nixos/server/k3s/default.nix | 3 ++- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/bin/skyg b/bin/skyg index b4a01ae..4c92b08 100755 --- a/bin/skyg +++ b/bin/skyg @@ -5,14 +5,20 @@ const current_folder = path self | path dirname | path dirname cd $current_folder def valid_profiles [] { - nix flake show --json err> /dev/null | from json | - select nixosConfigurations | - flatten | transpose | - select column0 | rename name + nix eval .#nixosConfigurations --apply 'builtins.attrNames' --json err> /dev/null | + from json } -def is-valid-profile [name: string] { - (valid_profiles | where name == $name | length) == 1 +def valid_remote_profiles [] { + (valid_profiles) | where {|$it | str starts-with "hl" } +} + +def is-valid-profile [name: string, on_remote: bool = false] { + if $on_remote { + (valid_remote_profiles | where name == $name | length) == 1 + } else { + (valid_profiles | where name == $name | length) == 1 + } } def main [] { @@ -20,8 +26,12 @@ def main [] { help main } -def "main profiles" [] { - valid_profiles | print +def "main profiles" [only_remote: bool = false] { + if $only_remote { + valid_remote_profiles | print + } else { + valid_profiles | print + } } # Build configuration @@ -60,11 +70,11 @@ def "main update" [input_name:string = ""] { def "main remote" [cmd:string, target:string = ""] { mut target_host = $"root@($target).lab.internal" mut profile = $"hl-($target)" - # if not (is-valid-profile $profile) { - # print $"Invalid Profile ($profile), please select one of:" - # return valid_profiles - # } - $"Using [($profile)]" | print + if not (is-valid-profile $profile true) { + print $"Invalid Remote Profile '(ansi green_bold)($target)(ansi reset)', please select one of:" + return (valid_remote_profiles | each {|p| $p | str replace "hl-" ""}) + } + $"Using [(ansi green_bold)($profile)(ansi reset)]" | print const valid_cmds = [ "test" , "dry-activate" , "run" , "switch" , "build" ] diff --git a/modules/nixos/server/k3s/default.nix b/modules/nixos/server/k3s/default.nix index ec14e5b..d3c36b0 100644 --- a/modules/nixos/server/k3s/default.nix +++ b/modules/nixos/server/k3s/default.nix @@ -13,6 +13,7 @@ in }; envPath = lib.mkOption { type = lib.types.str; + default = ""; }; }; }; @@ -33,7 +34,7 @@ in lib.mkIf cfg.enable { services.k3s = { enable = true; - environmentFile = cfg.envPath; + environmentFile = lib.mkIf (cfg.envPath != "") cfg.envPath; role = cfg.role; extraFlags = [ "--disable servicelb"