lib/confctl/nix.rb in confctl-1.0.0 vs lib/confctl/nix.rb in confctl-2.0.0

- old
+ new

@@ -13,14 +13,15 @@ new(show_trace:, max_jobs:) end include Utils::File - def initialize(conf_dir: nil, show_trace: false, max_jobs: nil) + def initialize(conf_dir: nil, show_trace: false, max_jobs: nil, cores: nil) @conf_dir = conf_dir || ConfDir.path @show_trace = show_trace @max_jobs = max_jobs || Settings.instance.max_jobs + @cores = cores @cmd = SystemCommand.new end def confctl_settings out_link = File.join( @@ -38,10 +39,11 @@ 'nix-build', '--arg', 'jsonArg', arg, '--out-link', out_link, (show_trace ? '--show-trace' : nil), (max_jobs ? ['--max-jobs', max_jobs.to_s] : nil), + (cores ? ['--cores', cores.to_s] : nil), ConfCtl.nix_asset('evaluator.nix') ].flatten.compact cmd.run(*cmd_args) end @@ -86,10 +88,11 @@ 'nix-build', '--arg', 'jsonArg', arg, '--out-link', out_link, (show_trace ? '--show-trace' : nil), (max_jobs ? ['--max-jobs', max_jobs.to_s] : nil), + (cores ? ['--cores', cores.to_s] : nil), ConfCtl.nix_asset('evaluator.nix') ].flatten.compact cmd.run(*cmd_args) end @@ -122,10 +125,11 @@ 'nix-build', '--arg', 'jsonArg', arg, '--out-link', out_link, (show_trace ? '--show-trace' : nil), (max_jobs ? ['--max-jobs', max_jobs.to_s] : nil), + (cores ? ['--cores', cores.to_s] : nil), ConfCtl.nix_asset('evaluator.nix') ].flatten.compact out, = cmd.run(*cmd_args).stdout @@ -152,10 +156,11 @@ 'nix-build', '--arg', 'jsonArg', arg, '--out-link', out_link, (show_trace ? '--show-trace' : nil), (max_jobs ? ['--max-jobs', max_jobs.to_s] : nil), + (cores ? ['--cores', cores.to_s] : nil), ConfCtl.nix_asset('evaluator.nix') ].flatten.compact out, = cmd.run(*cmd_args) @@ -163,22 +168,22 @@ end end # Build config.system.build.toplevel for selected hosts # - # @param hosts [Array<String>] + # @param hosts [Array<Machine>] # @param swpin_paths [Hash] # @param host_swpin_specs [Hash] # @param time [Time] # # @yieldparam type [:build, :fetch] # @yieldparam progress [Integer] # @yieldparam total [Integer] # @yieldparam path [String] # # @return [Hash<String, Generation::Build>] - def build_toplevels(hosts: [], swpin_paths: {}, host_swpin_specs: {}, time: nil, &block) + def build_attributes(hosts: [], swpin_paths: {}, host_swpin_specs: {}, time: nil, &block) with_argument({ confDir: conf_dir, build: :toplevel, machines: hosts }) do |arg| @@ -189,10 +194,11 @@ cmd_args = [ '--arg', 'jsonArg', arg, '--out-link', out_link, (show_trace ? '--show-trace' : nil), (max_jobs ? ['--max-jobs', max_jobs.to_s] : nil), + (cores ? ['--cores', cores.to_s] : nil), ConfCtl.nix_asset('evaluator.nix') ].flatten.compact nb = NixBuild.new(cmd_args, swpin_paths) nb.run(&block) @@ -234,10 +240,13 @@ # # @return [Boolean] def copy(machine, toplevel, &) if machine.localhost? true + elsif machine.carried? + cp = NixCopy.new(machine.carrier_machine.target_host, toplevel) + cp.run!(&).success? else cp = NixCopy.new(machine.target_host, toplevel) cp.run!(&).success? end end @@ -256,17 +265,30 @@ # @param toplevel [String] # @return [Boolean] def set_profile(machine, toplevel) args = [ 'nix-env', - '-p', '/nix/var/nix/profiles/system', + '-p', machine.profile, '--set', toplevel ] MachineControl.new(machine).execute!(*args).success? end + # @param machine [Machine] + # @param toplevel [String] + # @return [Boolean] + def set_carried_profile(machine, toplevel) + args = [ + 'carrier-env', + '-p', machine.profile, + '--set', toplevel + ] + + MachineControl.new(machine.carrier_machine).execute!(*args).success? + end + # @param packages [Array<String>] # @param command [String] # @return [Boolean] def run_command_in_shell(packages: [], command: nil) args = ['nix-shell'] @@ -290,11 +312,11 @@ gc.run!(&).success? end protected - attr_reader :conf_dir, :show_trace, :max_jobs, :cmd + attr_reader :conf_dir, :show_trace, :max_jobs, :cores, :cmd # Execute block only if `out_link` does not exist or conf dir has changed # @param out_link [String] out link path def with_cache(out_link) unchanged = false @@ -355,9 +377,10 @@ '--strict', '--read-write-mode', '--arg', 'jsonArg', arg, (show_trace ? '--show-trace' : nil), (max_jobs ? ['--max-jobs', max_jobs.to_s] : nil), + (cores ? ['--cores', cores.to_s] : nil), ConfCtl.nix_asset('evaluator.nix') ].flatten.compact out, = cmd.run(*cmd_args).stdout