diff options
| author | Kj Tsanaktsidis <kjtsanaktsidis@groq.com> | 2025-09-07 16:32:01 +1000 |
|---|---|---|
| committer | Kj Tsanaktsidis <kjtsanaktsidis@groq.com> | 2025-09-07 16:32:01 +1000 |
| commit | 21aac7678f85c81505fc0c7171f46eaa9ccfd2df (patch) | |
| tree | cbcfd2627c8be52f6676188e5425b2af19e44013 /nixos-update.rb | |
| parent | 6ad580f49e7412eb428b45b4fa03039f17fb5c8e (diff) | |
sort of works now
Diffstat (limited to 'nixos-update.rb')
| -rwxr-xr-x[-rw-r--r--] | nixos-update.rb | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/nixos-update.rb b/nixos-update.rb index b6f3607..2640835 100644..100755 --- a/nixos-update.rb +++ b/nixos-update.rb @@ -9,9 +9,7 @@ require 'optparse' class NixOSUpdater def initialize - @options = parse_options - @system_flake = ARGV[0] - @target_host = ARGV[1] + parse_options! validate_args! @@ -19,7 +17,7 @@ class NixOSUpdater end def run - if @options[:install] + if @install perform_install else perform_update @@ -28,14 +26,14 @@ class NixOSUpdater private - def parse_options + def parse_options! options = {} OptionParser.new do |opts| opts.banner = 'Usage: nixos-update.rb [--install] --system-def <def> --target <target>' opts.on('--install', 'Perform initial installation with nixos-anywhere') do - options[:install] = true + @install = true end opts.on('-h', '--help', 'Show this help message') do @@ -43,15 +41,15 @@ class NixOSUpdater exit end - opts.on('--system-def', 'what system configuration to install') do |defn| + opts.on('--system-def=DEFN', 'what system configuration to install') do |defn| @system_def = defn end - opts.on('--target', 'what user@host to install to') do |target| + opts.on('--target=TARGET', 'what user@host to install to') do |target| @target = target end - opts.on('--build-on', 'what user@host to build on') do |build_on| + opts.on('--build-on=BUILD_ON', 'what user@host to build on') do |build_on| @build_on = build_on end end.parse! @@ -67,11 +65,13 @@ class NixOSUpdater @target = "#{Etc.getlogin}@#{@system_def}" if @target.nil? @build_on = @target if @build_on.nil? && RUBY_PLATFORM !~ /linux/ + + puts "TARGET: #{@target} BUILD_ON #{@build_on} DEF #{@system_def}" end def decrypt_secrets cmd = TTY::Command.new(printer: :null) - result = cmd.run(sops_exe, 'decrypt', '--output-type', 'json', "#{@system_flake}/secrets.yaml") + result = cmd.run(sops_exe, 'decrypt', '--output-type', 'json', "#{@system_def}/secrets.yaml") JSON.parse(result.out) end @@ -89,7 +89,7 @@ class NixOSUpdater 'nixos-anywhere', '--disk-encryption-keys', "#{dir}/luks_passphrase", "#{dir}/luks_passphrase", '--extra-files', "#{dir}/copy_dir", - '--flake', ".##{@system_flake}" + '--flake', ".##{@system_def}" ] cmd_args << '--build-on-remote' if RUBY_PLATFORM !~ /linux/ @@ -102,23 +102,22 @@ class NixOSUpdater end def perform_update - puts "### Updating #{@system_flake} configuration on #{@target_host} ###" + puts "### Updating #{@system_def} configuration on #{@target} ###" cmd_args = [ 'nixos-rebuild-ng', 'switch', - '--flake', ".##{@system_flake}", - '--sudo', '--ask-sudo-passowrd' + '--flake', ".##{@system_def}", + '--sudo', '--ask-sudo-password' ] - if @target_host - cmd_args << '--target-host' << @target_host - cmd_args << '--use-remote-sudo' + if @target + cmd_args << '--target-host' << @target end - cmd_args << '--build-on' << @build_on if @build_on + cmd_args << '--build-host' << @build_on if @build_on - cmd = TTY::Command.new + cmd = TTY::Command.new(printer: :quiet, pty: true) cmd.run(*cmd_args) end end |
