Deployment and lifecycle management for Nix
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

agent: use activator

+15 -38
+7 -37
apps/sower_agent/lib/sower_agent/seed.ex
··· 3 3 4 4 require Logger 5 5 6 - def activate(%Seed{seed_type: "home-manager"} = seed) do 6 + def run_activator(args) when is_list(args) do 7 7 if Application.get_env(:sower_agent, :enable_activation, true) do 8 - case System.cmd("#{seed.artifact}/activate", [], 8 + case System.cmd(System.find_executable("sower-activator"), args, 9 9 into: [], 10 10 lines: 1024, 11 11 stderr_to_stdout: true ··· 23 23 end 24 24 end 25 25 26 - def activate(%Seed{seed_type: "nixos"} = seed) do 27 - if Application.get_env(:sower_agent, :enable_activation, true) do 28 - {_, 0} = 29 - maybe_sudo_cmd( 30 - "nix-env", 31 - [ 32 - "--set", 33 - "--profile", 34 - Nix.NixOS.profile_path(), 35 - seed.artifact 36 - ] 37 - ) 38 - 39 - case maybe_sudo_cmd("#{seed.artifact}/bin/switch-to-configuration", ["switch"], 40 - into: [], 41 - lines: 1024, 42 - stderr_to_stdout: true 43 - ) do 44 - {output, 0} -> 45 - Logger.debug(output: output) 46 - {:ok, output} 47 - 48 - {output, code} -> 49 - Logger.error(msg: "Failed to activate", output: output, return_code: code) 50 - {:error, code} 51 - end 52 - else 53 - {:ok, ["noop"]} 54 - end 26 + def activate(%Seed{seed_type: "home-manager"} = seed) do 27 + run_activator(["-path", seed.artifact, "-type", "home-manager"]) 55 28 end 56 29 57 - defp maybe_sudo_cmd(command, args, opts \\ []) do 58 - if Application.get_env(:sower_agent, :sudo, false) do 59 - System.cmd("sudo", [command | args], opts) 60 - else 61 - System.cmd(command, args, opts) 62 - end 30 + def activate(%Seed{seed_type: "nixos"} = seed) do 31 + mode = "switch" 32 + run_activator(["-path", seed.artifact, "-type", "nixos", "-mode", mode]) 63 33 end 64 34 end
+8 -1
nix/nixos/agent.nix
··· 35 35 }; 36 36 37 37 package = lib.mkOption { type = lib.types.package; }; 38 + activatorPackage = lib.mkOption { type = lib.types.package; }; 38 39 39 40 settings = lib.mkOption { 40 41 type = lib.types.submodule { ··· 68 69 "network-online.target" 69 70 ] 70 71 ++ lib.optionals config.services.sower.server.enable [ "sower.service" ]; 71 - path = [ config.nix.package ]; 72 + path = [ 73 + config.nix.package 74 + cfg.activatorPackage 75 + ]; 72 76 73 77 environment = { 74 78 SHELL = lib.getExe pkgs.bash; ··· 102 106 exec ${lib.getExe cfg.package} start 103 107 ''; 104 108 ExecStop = "${lib.getExe cfg.package} stop"; 109 + 110 + MemoryAccounting = true; 111 + MemoryMax = "200M"; 105 112 }; 106 113 }; 107 114