This repository was archived by the owner on Feb 1, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +77
-7
lines changed Expand file tree Collapse file tree 4 files changed +77
-7
lines changed Original file line number Diff line number Diff line change 17
17
./modules/shell.nix
18
18
./modules/niv.nix
19
19
./modules/pre-commit.nix
20
+ ./modules/activation.nix
20
21
] ;
21
22
22
23
in
Original file line number Diff line number Diff line change
1
+ { config , lib , ... } :
2
+
3
+ let
4
+
5
+ inherit ( lib )
6
+ concatStringsSep
7
+ hasPrefix
8
+ literalExample
9
+ mkIf
10
+ mkOption
11
+ mkOptionType
12
+ mkOrder
13
+ types
14
+ ;
15
+
16
+ cfg = config . activation ;
17
+
18
+ isOutsideStore = p : ! ( hasPrefix builtins . storeDir ( toString p ) ) ;
19
+
20
+ in
21
+ {
22
+ options = {
23
+
24
+ activation . hooks = mkOption {
25
+ type = types . listOf types . str ;
26
+ description = ''
27
+ bash snippets to run on activation.
28
+
29
+ This is quite distinct from a shell hook:
30
+ - the working directory is always the project root.
31
+ - variables are not propagated to the shell.
32
+ - activation hooks may be run separately or before most shell.hooks.
33
+ '' ;
34
+ default = [ ] ;
35
+ } ;
36
+
37
+ activation . enableShellHook = mkOption {
38
+ type = types . bool ;
39
+ description = ''
40
+ Whether to run the activation hooks whenever the project shell is opened.
41
+ '' ;
42
+ default = true ;
43
+ } ;
44
+
45
+ } ;
46
+
47
+ config =
48
+ mkIf cfg . enableShellHook {
49
+
50
+ shell . extraAttrs . activationHook =
51
+ concatStringsSep "\n " cfg . hooks ;
52
+
53
+ shell . hooks = mkIf ( isOutsideStore config . root ) ( mkOrder 300 [ ''
54
+ (
55
+ echo 1>&2 project.nix: activating in ${ lib . escapeShellArg config . root }
56
+ cd ${ lib . escapeShellArg config . root }
57
+ runHook activationHook
58
+ )
59
+ '' ] ) ;
60
+ } ;
61
+
62
+ }
Original file line number Diff line number Diff line change 163
163
164
164
config = mkIf cfg . enable {
165
165
166
- # TODO: generalize the setup logic
167
- # TODO: only autoinstall when in the project root
168
- # TODO: always ignore when src is in the store
169
- shell . hooks = mkIf cfg . enableAutoInstall [
166
+ shell . packages = [ cfg . package ] ;
167
+
168
+ activation . hooks = mkIf cfg . enableAutoInstall [
170
169
''
171
170
export PATH=$PATH:${ cfg . package } /bin
172
171
if ! type -t git >/dev/null; then
Original file line number Diff line number Diff line change 28
28
example = [ ''if ! type git >/dev/null; then echo 1>&2 "git command not found! Please install git on your system or user profile"; fi'' ] ;
29
29
} ;
30
30
31
- # TODO environment variables
31
+ # TODO: can we specify merge functions in an extensible way?
32
+ extraAttrs = mkOption {
33
+ type = types . attrsOf types . str ;
34
+ description = ''
35
+ Extra variables to set in the project's nix-shell.
36
+ '' ;
37
+ default = { } ;
38
+ example = { LANG = "en_US.UTF-8" ; } ;
39
+ } ;
32
40
33
41
shell = mkOption {
34
42
type = types . package ;
39
47
} ;
40
48
41
49
config = {
42
- shell . shell = pkgs . mkShell {
50
+ shell . shell = pkgs . mkShell ( cfg . extraAttrs // {
43
51
nativeBuildInputs = cfg . packages ;
44
52
shellHook = lib . concatStringsSep "\n " cfg . hooks ;
45
- } ;
53
+ } ) ;
46
54
} ;
47
55
}
You can’t perform that action at this time.
0 commit comments