mod/direnv: add nix shell

This commit is contained in:
Dmitriy Pleshevskiy 2024-03-19 12:00:48 +03:00
parent 154c9de515
commit 0a74fec499
Signed by: pleshevskiy
GPG key ID: 17041163DA10A9A2
3 changed files with 12 additions and 0 deletions

View file

@ -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<DirenvModuleCliArgs> 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,
}

View file

@ -9,6 +9,10 @@ pub struct DirenvModuleConfig {
impl From<DirenvModuleConfig> 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")

View file

@ -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),
]