Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Better error msg for flakes #506

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
3 changes: 3 additions & 0 deletions src/flake-compat-shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{ system ? builtins.currentSystem }:

(builtins.getFlake (toString ./.)).devShell.${system}
25 changes: 18 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -65,13 +67,22 @@ fn get_shell_nix(shellfile: &PathBuf) -> Result<NixFile, ExitError> {
// 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
)
})
},
)?))
}
Expand Down