Deployment and lifecycle management for Nix
0
fork

Configure Feed

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

agent: handle nixos upgrades

+34 -3
+34 -3
apps/sower_agent/lib/sower_agent/seed.ex
··· 23 23 end 24 24 end 25 25 26 - def activate(%Seed{seed_type: "nixos"}) do 27 - # err = setProfile("/nix/var/nix/profiles/system", storePath) 28 - # switchCmd := exec.Command(fmt.Sprintf("%s/bin/switch-to-configuration", storePath), mode) 26 + def activate(%Seed{seed_type: "nixos"} = seed) do 27 + {_, 0} = 28 + maybe_sudo_cmd( 29 + "nix-env", 30 + [ 31 + "--set", 32 + "--profile", 33 + Nix.NixOS.profile_path(), 34 + seed.artifact 35 + ] 36 + ) 37 + 38 + case maybe_sudo_cmd("#{seed.artifact}/bin/switch-to-configuration", ["switch"], 39 + into: [], 40 + lines: 1024, 41 + stderr_to_stdout: true 42 + ) do 43 + {output, 0} -> 44 + Logger.debug(output: output) 45 + {:ok, output} 46 + 47 + {output, code} -> 48 + Logger.error(msg: "Failed to activate", output: output, return_code: code) 49 + {:error, code} 50 + end 51 + 29 52 {:error, :TODO} 53 + end 54 + 55 + defp maybe_sudo_cmd(command, args, opts \\ []) do 56 + if Application.get_env(:sower_agent, :sudo, false) do 57 + System.cmd("sudo", [command | args], opts) 58 + else 59 + System.cmd(command, args, opts) 60 + end 30 61 end 31 62 end