diff --git a/src/flake-compat-shell.nix b/src/flake-compat-shell.nix new file mode 100644 index 00000000..e3a3dcc2 --- /dev/null +++ b/src/flake-compat-shell.nix @@ -0,0 +1,3 @@ +{ system ? builtins.currentSystem }: + +(builtins.getFlake (toString ./.)).devShell.${system} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index d4820d87..582eb614 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,10 +11,12 @@ use lorri::NixFile; use slog::{debug, error, o}; use slog_scope::GlobalLoggerGuard; use std::env; +use std::path; use std::path::PathBuf; use structopt::StructOpt; const TRIVIAL_SHELL_SRC: &str = include_str!("./trivial-shell.nix"); +const FLAKE_COMPAT_SHELL_SRC: &str = include_str!("./flake-compat-shell.nix"); const DEFAULT_ENVRC: &str = "eval \"$(lorri direnv)\"\n"; fn main() { @@ -65,13 +67,22 @@ fn get_shell_nix(shellfile: &PathBuf) -> Result { // use shell.nix from cwd Ok(NixFile::from(locate_file::in_cwd(&shellfile).map_err( |_| { - ExitError::user_error(format!( - "`{}` does not exist\n\ - You can use the following minimal `shell.nix` to get started:\n\n\ - {}", - shellfile.display(), - TRIVIAL_SHELL_SRC - )) + ExitError::user_error( + if path::PathBuf::from("flake.nix").exists() { + format!( + "lorri does not currently natively support flakes.\nYou can use the following compatibility `shell.nix` to use lorri with flakes:\n\n\ + {}", + FLAKE_COMPAT_SHELL_SRC + ) + } else { + format!( + "`{}` does not exist\n\ + You can use the following minimal `shell.nix` to get started:\n\n\ + {}", + shellfile.display(), + TRIVIAL_SHELL_SRC + ) + }) }, )?)) }