File tree Expand file tree Collapse file tree 2 files changed +46
-16
lines changed Expand file tree Collapse file tree 2 files changed +46
-16
lines changed Original file line number Diff line number Diff line change
1
+ { config , pkgs , lib , ... } :
2
+
3
+ with lib ;
4
+
5
+ let
6
+ conf = config . shell_nix ;
7
+
8
+ nixpkgs_incl = if conf . nixpkgs != null then
9
+ "-I nixpkgs=${ escapeShellArg conf . nixpkgs } "
10
+ else
11
+ "" ;
12
+
13
+ in {
14
+ options . shell_nix = {
15
+ enabled = mkOption {
16
+ type = types . bool ;
17
+ default = false ;
18
+ description = "Whether use 'shell.nix' in the workspace's tree." ;
19
+ } ;
20
+
21
+ nixpkgs = mkOption {
22
+ type = types . nullOr types . path ;
23
+ default = null ;
24
+ description = "Pinned nixpkgs for evaluating the local shell." ;
25
+ } ;
26
+ } ;
27
+
28
+ config = mkIf conf . enabled {
29
+ activation_command = ''
30
+ if [[ -e ./shell.nix ]]
31
+ then exec nix-shell ./shell.nix ${ nixpkgs_incl } --run ${
32
+ escapeShellArg config . command
33
+ }
34
+ else ${ config . command }
35
+ fi
36
+ '' ;
37
+ } ;
38
+ }
Original file line number Diff line number Diff line change 43
43
"Directory for per-workspace cache, relative to the home directory. Used to store history files and other unimportant things." ;
44
44
} ;
45
45
46
- local_shell = mkOption {
47
- type = types . bool ;
48
- default = false ;
49
- description = "Whether to build and use a local 'shell.nix'." ;
46
+ activation_command = mkOption {
47
+ type = types . str ;
48
+ default = config . command ;
49
+ description =
50
+ "Command run at the end of the activation script. The default is to run 'command'." ;
50
51
} ;
51
-
52
52
} ;
53
53
54
54
config = {
70
70
base_module
71
71
default_name # Base modules
72
72
modules/git.nix
73
- modules/vim .nix
73
+ modules/shell_nix .nix
74
74
modules/tools.nix
75
+ modules/vim.nix
75
76
modules/xdg.nix
76
77
configuration # User configuration
77
78
] ;
78
79
} ;
79
80
in modules . config ;
80
81
81
- make_activate_command = w :
82
- if w . local_shell then ''
83
- if [[ -e ./shell.nix ]]
84
- then exec nix-shell ./shell.nix --run ${ escapeShellArg w . command }
85
- else ${ w . command }
86
- fi
87
- '' else
88
- w . command ;
89
-
90
82
stdenv = pkgs . stdenvNoCC ;
91
83
92
84
# Generate the 'workspace-init' and 'workspace-activate' script for the
105
97
activation_script = ''
106
98
mkdir -p "$HOME/${ w . cache_dir } "
107
99
${ w . activation_script }
108
- ${ make_activate_command w }
100
+ ${ w . activation_command }
109
101
'' ;
110
102
111
103
# Similar to 'pkgs.writeShellScriptBin', inlined to avoid generating many
You can’t perform that action at this time.
0 commit comments