Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ open Ns
open Ns.Cmd
open Ns.Util

let main ({ installables; target_info; printcmd } : Cli.strategy) =
let main
({ installables; target_info; printcmd; force_experimental_features } :
Cli.strategy)
=
let ({ entrypoint; attribute; subshell_dir } : Cli.target_info) = target_info in
Option.value ~default:(Option.value ~default:(Sys.getcwd ()) entrypoint) subshell_dir
|> Unix.cd;
Expand All @@ -13,6 +16,7 @@ let main ({ installables; target_info; printcmd } : Cli.strategy) =
| true ->
Cmd.builder "nix"
|>+ [ "develop" ] @ [ Uri.sprintf_uri_attr_opt entrypoint attribute ]
|>+ Option.value ~default:[] force_experimental_features
| false ->
(match Unix.shell_exists_at entrypoint with
| true ->
Expand All @@ -24,7 +28,11 @@ let main ({ installables; target_info; printcmd } : Cli.strategy) =
| false ->
Error.handle_ns_error "no available devshell entrypoint: %s\n%!" entrypoint))
|>+ [ "--command"; Unix.shell ]
| None -> Cmd.builder "nix" |>+ [ "shell" ] |>+ installables
| None ->
Cmd.builder "nix"
|>+ [ "shell" ]
|>+ installables
|>+ Option.value ~default:[] force_experimental_features
in
if printcmd then print_endline (Cmd.to_string cmd) else ignore (Cmd.run cmd)
;;
Expand Down
25 changes: 22 additions & 3 deletions lib/cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module Cli = struct
{ installables : string list
; target_info : target_info
; printcmd : bool
; force_experimental_features : string list option
}

(** Positional URI arguments passed to the program via the command line. *)
Expand All @@ -28,9 +29,14 @@ module Cli = struct
Arg.(value & flag & info [ "printcmd" ] ~doc)
;;

let force_experimental_features =
let doc = "Force the use of flakes and nix-command experimental features." in
Arg.(value & flag & info [ "force"; "f" ] ~doc)
;;

(** Processes the args so that the main function knows what to do with them. *)
let make_strategy =
let build original_args printcmd =
let build original_args printcmd force_experimental_features =
let installables, target_info =
let default_installables = []
and default_target =
Expand Down Expand Up @@ -87,9 +93,22 @@ module Cli = struct
, { entrypoint = None; attribute = None; subshell_dir = Some subshell_dir } )
| _ -> Uri.parse_targets_tr original_args, default_target)
in
{ installables; target_info; printcmd }
{ installables
; target_info
; printcmd
; force_experimental_features =
(if force_experimental_features
then
Some
[ "--extra-experimental-features"
; "flakes"
; "--extra-experimental-features"
; "nix-command"
]
else None)
}
in
Term.(const build $ uris $ printcmd)
Term.(const build $ uris $ printcmd $ force_experimental_features)
;;

let cmd entrypoint =
Expand Down
Loading