Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

intial draft NixOS depext support #5942

Closed
wants to merge 1 commit into from
Closed
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
44 changes: 26 additions & 18 deletions src/client/opamSolution.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1179,24 +1179,32 @@ let install_depexts ?(force_depext=false) ?(confirm=true) t packages =
manual_install t sys_packages
and menu t sys_packages =
let answer =
let pkgman =
OpamConsole.colorise `yellow
(OpamSysInteract.package_manager_name ~env config)
in
OpamConsole.menu ~unsafe_yes:`Yes ~default:`Yes ~no:`Quit
"opam believes some required external dependencies are missing. opam \
can:"
~options:[
`Yes, Printf.sprintf
"Run %s to install them (may need root/sudo access)" pkgman;
`No, Printf.sprintf
"Display the recommended %s command and wait while you run it \
manually (e.g. in another terminal)" pkgman;
`Ignore, "Continue anyway, and, upon success, permanently register \
that this external dependency is present, but not \
detectable";
`Quit, "Abort the installation";
]
let pkgman = OpamSysInteract.package_manager_name ~env config in
let pkgman_colourised = OpamConsole.colorise `yellow pkgman in
match pkgman with
| "nix" ->
OpamConsole.menu ~unsafe_yes:`Ignore ~default:`Quit ~no:`Quit
"opam supports external dependencies with %s by creating a shell.nix file. opam \
can:" pkgman_colourised
~options:[
`Quit, "Abort the installation if you haven't configured an evironment with your depexts.";
`Ignore, "Continue the installation if you've called nix-shell or an alternative.";
]
| _ ->
OpamConsole.menu ~unsafe_yes:`Yes ~default:`Yes ~no:`Quit
"opam believes some required external dependencies are missing. opam \
can:"
~options:[
`Yes, Printf.sprintf
"Run %s to install them (may need root/sudo access)" pkgman_colourised;
`No, Printf.sprintf
"Display the recommended %s command and wait while you run it \
manually (e.g. in another terminal)" pkgman_colourised;
`Ignore, "Continue anyway, and, upon success, permanently register \
that this external dependency is present, but not \
detectable";
`Quit, "Abort the installation";
]
in
OpamConsole.msg "\n";
match answer with
Expand Down
17 changes: 17 additions & 0 deletions src/state/opamSysInteract.ml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ type families =
| Macports
| Msys2
| Netbsd
| Nixos
| Openbsd
| Suse

Expand Down Expand Up @@ -198,6 +199,7 @@ let family ~env () =
| "gentoo" -> Gentoo
| "homebrew" -> Homebrew
| "macports" -> Macports
| "nixos" -> Nixos
| "macos" ->
failwith
"External dependency handling for macOS requires either \
Expand Down Expand Up @@ -896,6 +898,18 @@ let packages_status ?(env=OpamVariable.Map.empty) config packages =
|> package_set_of_pkgpath
in
compute_sets sys_installed
| Nixos ->
(* TODO should we rely on being in the cwd? *)
let open OpamFilename in
let file = create (cwd ()) (basename (raw "shell.nix")) in
(* TODO create the correct format *)
Printf.printf "%s\n\n" (OpamSysPkg.Set.to_string packages);
let contents = String.concat " " (List.rev (OpamSysPkg.Set.fold (fun p l -> OpamSysPkg.to_string p :: l) packages [])) in
(* TODO don't override if already there *)
(* TODO this write doesn't work *)
write file contents;
Printf.printf "\n\nCONTENTS %s\n\n" contents;
packages, OpamSysPkg.Set.empty
| Openbsd ->
let sys_installed =
run_query_command "pkg_info" ["-mqP"]
Expand Down Expand Up @@ -1009,6 +1023,8 @@ let install_packages_commands_t ?(env=OpamVariable.Map.empty) config sys_package
[`AsUser (Commands.msys2 config),
"-Su"::"--noconfirm"::packages], None
| Netbsd -> [`AsAdmin "pkgin", yes ["-y"] ("install" :: packages)], None
(* shim command to communicate that we're using Nix *)
| Nixos -> [`AsUser "nix", [] ], None
| Openbsd -> [`AsAdmin "pkg_add", yes ~no:["-i"] ["-I"] packages], None
| Suse -> [`AsAdmin "zypper", yes ["--non-interactive"] ("install"::packages)], None

Expand Down Expand Up @@ -1069,6 +1085,7 @@ let update ?(env=OpamVariable.Map.empty) config =
| Macports -> Some (`AsAdmin "port", ["sync"])
| Msys2 -> Some (`AsUser (Commands.msys2 config), ["-Sy"])
| Netbsd -> None
| Nixos -> None
| Openbsd -> None
| Suse -> Some (`AsAdmin "zypper", ["--non-interactive"; "refresh"])
in
Expand Down