diff --git a/src/cli/direnv.rs b/src/cli/direnv.rs index 3ee510b..73aa9a3 100644 --- a/src/cli/direnv.rs +++ b/src/cli/direnv.rs @@ -3,6 +3,7 @@ use crate::module::direnv::DirenvModuleArgs; #[derive(Debug, Clone, clap::ValueEnum)] pub enum DirenvCliNixValue { Flake, + Shell, } #[derive(Debug, Clone, clap::Args)] @@ -16,6 +17,7 @@ pub struct DirenvModuleCliArgs { impl From for DirenvModuleArgs { fn from(args: DirenvModuleCliArgs) -> Self { DirenvModuleArgs { + nix_shell: matches!(args.nix, Some(DirenvCliNixValue::Shell)), nix_flake: matches!(args.nix, Some(DirenvCliNixValue::Flake)), nodejs: args.nodejs, } diff --git a/src/config/direnv.rs b/src/config/direnv.rs index e5fc12f..24626e2 100644 --- a/src/config/direnv.rs +++ b/src/config/direnv.rs @@ -9,6 +9,10 @@ pub struct DirenvModuleConfig { impl From for DirenvModuleArgs { fn from(cfg: DirenvModuleConfig) -> Self { DirenvModuleArgs { + nix_shell: cfg + .nix + .map(|v| v.to_lowercase() == "shell") + .unwrap_or_default(), nix_flake: cfg .nix .map(|v| v.to_lowercase() == "flake") diff --git a/src/module/direnv.rs b/src/module/direnv.rs index 4d11fbd..a3a61c6 100644 --- a/src/module/direnv.rs +++ b/src/module/direnv.rs @@ -2,6 +2,10 @@ use std::collections::HashMap; use super::Module; +const NIX_SHELL_PART: &str = "\ +# nix +use nix"; + const NIX_FLAKE_PART: &str = "\ # nix use flake"; @@ -11,12 +15,14 @@ const NODEJS_PART: &str = "\ layout node"; pub struct DirenvModuleArgs { + pub nix_shell: bool, pub nix_flake: bool, pub nodejs: bool, } fn make_gitignore_content(args: DirenvModuleArgs) -> String { [ + args.nix_shell.then_some(NIX_SHELL_PART), args.nix_flake.then_some(NIX_FLAKE_PART), args.nodejs.then_some(NODEJS_PART), ]