Deployment and lifecycle management for Nix
0
fork

Configure Feed

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

feat(server): client bootstrap script now understands caches

+57 -15
+5 -1
config/runtime.exs
··· 173 173 listen_address = json_config |> Keyword.get(:listen_address, "127.0.0.1") 174 174 listen_port = json_config |> Keyword.get(:listen_port, 4000) 175 175 176 + if not Keyword.has_key?(json_config, :nix_caches) do 177 + json_config = json_config |> Keyword.put(:nix_caches, []) 178 + end 179 + 176 180 secret_key_base = 177 181 with secret_key_base_file <- json_config |> Keyword.get(:secret_key_base_file), 178 182 {:ok, secret_key_base} <- read_credential(secret_key_base_file) do ··· 238 242 end 239 243 240 244 defp atomize([head | rest]) do 241 - [atomize(head), atomize(rest)] |> List.flatten() 245 + [atomize(head)] ++ atomize(rest) 242 246 end 243 247 244 248 defp atomize(map = %{}) do
+12 -5
lib/sower_web/controllers/app_controller.ex
··· 1 1 defmodule SowerWeb.AppController do 2 2 use SowerWeb, :controller 3 3 4 + action_fallback SowerWeb.AppFallbackController 5 + 4 6 def client_script(conn, _params) do 5 7 case Application.fetch_env(:sower, :clients) do 6 8 {:ok, clients} -> 7 - render(conn |> put_root_layout(false), :client_script, 8 - layout: false, 9 - clients: clients 10 - ) 9 + conn 10 + |> assign(:clients, clients) 11 + |> assign(:nix_caches, Application.fetch_env!(:sower, :nix_caches)) 12 + |> put_root_layout(false) 13 + |> render(:client_script, layout: false) 11 14 12 15 :error -> 13 - html(conn |> Plug.Conn.put_status(404) |> Plug.Conn.halt(), "not found") 16 + conn 17 + |> Plug.Conn.put_status(404) 18 + |> put_root_layout(false) 19 + |> Plug.Conn.halt() 20 + |> html("echo 'Error: client paths not configured on sower server'") 14 21 end 15 22 end 16 23 end
+34
lib/sower_web/controllers/app_html.ex
··· 2 2 use SowerWeb, :html 3 3 4 4 embed_templates("app_html/*") 5 + 6 + attr :arch, :string, required: true 7 + attr :path, :string, required: true 8 + 9 + def case_arch(assigns) do 10 + ~H""" 11 + <%= @arch %>) 12 + nix-store --realize <%= @path %> $cache_args # 13 + exec <%= @path %>/bin/sower "$@" 14 + ;; 15 + """ 16 + end 17 + 18 + attr :nix_caches, :list, required: true 19 + 20 + def cache_args(assigns) do 21 + substituters = 22 + if assigns.nix_caches |> length > 0 do 23 + "--extra-substituters " <> 24 + (assigns.nix_caches |> Enum.map_join(",", &(&1 |> Keyword.get(:url)))) 25 + else 26 + "" 27 + end 28 + 29 + keys = 30 + if assigns.nix_caches |> length > 0 do 31 + "--extra-trusted-public-keys " <> 32 + (assigns.nix_caches |> Enum.map_join(",", &(&1 |> Keyword.get(:public_key)))) 33 + else 34 + "" 35 + end 36 + 37 + ~H"<%= substituters %> <%= keys %>" 38 + end 5 39 end
+6 -9
lib/sower_web/controllers/app_html/client_script.sh.heex
··· 10 10 fi 11 11 12 12 system="${arch}-linux" 13 + cache_args="<.cache_args nix_caches={@nix_caches} />" 13 14 echo ":: Found system ${system}" 14 15 15 16 case "$system" in 16 17 <%= for {arch, props} <- @clients do %> 17 - 18 - <%= arch %>) 19 - nix-store --realize <%= props |> Keyword.get(:path) %> 20 - exec <%= props |> Keyword.get(:path) %>/bin/sower "$@" 21 - ;; 18 + <.case_arch arch={arch} path={props |> Keyword.get(:path)} /> 22 19 <% end %> 23 - *) 24 - echo "!! Unsupported system!" 25 - exit 1 26 - ;; 20 + *) 21 + echo "!! Unsupported system!" 22 + exit 1 23 + ;; 27 24 esac