aboutsummaryrefslogtreecommitdiff
path: root/pkgs
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/yo.nix121
1 files changed, 58 insertions, 63 deletions
diff --git a/pkgs/yo.nix b/pkgs/yo.nix
index 11bab17..8a71e51 100644
--- a/pkgs/yo.nix
+++ b/pkgs/yo.nix
@@ -13,83 +13,78 @@
local SUDO = "sudo"
if conf.sudo then
SUDO = conf.sudo
- end
- if os.getenv("SUDO") then
+ elseif os.getenv("SUDO") then
SUDO = os.getenv("SUDO")
end
- local function collectArgs(start)
- local start = start or 2
+ local TARGET = "/home/collin/nixos"
- local flags = {}
- if arg[start] ~= nil then
- for i = start, #arg do
- table.insert(flags, arg[i])
- end
- end
- return flags
+ local function getHostname()
+ local f = io.popen("hostname")
+ local h = f:read("*l")
+ f:close()
+ return h
end
- local function nixosRebuild(args)
- local sudo = (args.sudo or false) == true
- local verb = args.verb or "switch"
- local flake = args.flake or "/home/collin/nixos"
- local extraArgs = table.concat(args.extraArgs or {}, " ")
-
- cmd = ("${pkgs.nixos-rebuild-ng}/bin/nixos-rebuild %s --flake %s %s --log-format internal-json |& ${pkgs.nix-output-monitor}/bin/nom --json"):format(verb, flake, extraArgs)
- if sudo then
- local sudo_cmd = ("%s su -c '%s'"):format(SUDO, cmd)
- print("+ "..sudo_cmd)
- os.execute(sudo_cmd)
- else
- print("+ "..cmd)
- os.execute(cmd)
- end
+ local function buildConfiguration(args)
+ local flake_path = args.flakePath
+ local hostname = args.hostname
+ local extra_args = table.concat(args.extraArgs or {}, " ")
+ local build_cmd = ('nix build %s#nixosConfigurations."%s".config.system.build.toplevel --log-format internal-json %s |& ${pkgs.nix-output-monitor}/bin/nom --json'):format(flake_path, hostname, extra_args)
+ print("+ "..build_cmd)
+ os.execute(build_cmd)
end
- if arg[1] == "deploy" or arg[1] == "dep" or arg[1] == "d" then
- local deploy_args = {}
- local nix_args = {}
+ local function switchToConfiguration(verb)
+ local proc_store_path = io.popen(("readlink -f %s/result"):format(TARGET))
+ local store_path = proc_store_path:read("*l")
+ proc_store_path:close()
- local found_dashes = false
- if arg[2] ~= nil then
- for i = 2, #arg do
- if arg[i] == "--" then
- found_dashes = true
- elseif found_dashes then
- table.insert(nix_args, arg[i])
- else
- table.insert(deploy_args, arg[i])
- end
- end
- end
+ -- create generation
+ local create_gen_cmd = ("nix build --no-link --profile %s %s"):format("/nix/var/nix/profiles/system", store_path)
+
+ local verb_cmd = ("%s/result/bin/switch-to-configuration %s"):format(TARGET, verb)
+
+ local sudo_verb_cmd = ("%s ${pkgs.bashNonInteractive}/bin/bash -c '%s; %s'"):format(SUDO, create_gen_cmd, verb_cmd)
+ print("+ "..sudo_verb_cmd)
+ os.execute(sudo_verb_cmd)
+ end
- cmd = ("nix run github:serokell/deploy-rs -- --skip-checks %s -- --log-format internal-json %s |& ${pkgs.nix-output-monitor}/bin/nom --json"):format(table.concat(deploy_args, " "), table.concat(nix_args, " "))
+ local function deployConfiguration(args)
+ local flake_path = args.flakePath
+ cmd = ("nix run github:serokell/deploy-rs %s -- --skip-checks -- --log-format internal-json |& ${pkgs.nix-output-monitor}/bin/nom --json"):format(flake_path)
print("+ "..cmd)
os.execute(cmd)
- elseif arg[1] == "switch" or arg[1] == "sw" or arg[1] == "s" then
- local target = "/home/collin/nixos"
- if arg[2] ~= nil and arg[2]:match("#") then
- target = arg[2]
- end
+ end
- nixosRebuild{
- sudo = true,
- verb = "switch",
- flake = target,
- extraArgs = collectArgs(3)
+ if arg[1] == "deploy" or arg[1] == "dep" or arg[1] == "d" then
+ deployConfiguration{
+ flakePath = TARGET
+ }
+ elseif arg[1] == "switch" or arg[1] == "sw" then
+ buildConfiguration{
+ flakePath = TARGET,
+ hostname = getHostname()
+ }
+ switchToConfiguration("switch")
+ elseif arg[1] == "boot" then
+ buildConfiguration {
+ flakePath = TARGET,
+ hostname = getHostname()
+ }
+ switchToConfiguration("boot")
+ elseif arg[1] == "test" then
+ buildConfiguration {
+ flakePath = TARGET,
+ hostname = getHostname()
+ }
+ switchToConfiguration("test")
+ elseif arg[1] == "build" then
+ local hostname = arg[2] or getHostname()
+ buildConfiguration {
+ flakePath = TARGET,
+ hostname = hostname
}
- elseif arg[1] == "boot" or arg[1] == "bo" then
- nixosRebuild{sudo = true, verb = "boot", extraArgs = collectArgs()}
- elseif arg[1] == "test" or arg[1] == "t" then
- nixosRebuild{sudo = true, verb = "test", extraArgs = collectArgs()}
- elseif arg[1] == "build" or arg[1] == "bu" then
- local target = "/home/collin/nixos"
- if arg[2] ~= nil and arg[2]:match("#") then
- target = arg[2]
- end
-
- nixosRebuild{verb = "build", flake = target, extraArgs = collectArgs(3)}
end
'';
in