File tree Expand file tree Collapse file tree 3 files changed +34
-18
lines changed Expand file tree Collapse file tree 3 files changed +34
-18
lines changed Original file line number Diff line number Diff line change 2
2
3
3
with lib ;
4
4
5
- let conf = config . git ; in
5
+ let
6
+ conf = config . git ;
7
+
8
+ sync_remotes = ''
9
+ # Sync remotes
10
+ ${ pkgs . bash } /bin/bash ${ ./sync_git_remotes.sh } <<"EOF"
11
+ ${ concatStringsSep "\n " ( mapAttrsToList ( n : u : "${ n } ${ u } " ) conf . remotes ) }
12
+ EOF
13
+ '' ;
14
+
15
+ in
6
16
7
17
{
8
18
options . git = {
@@ -32,26 +42,20 @@ let conf = config.git; in
32
42
config = mkIf ( conf . remotes != { } ) {
33
43
buildInputs = with pkgs ; [ git ] ;
34
44
35
- activation_script = ''
36
- # Init if not already
37
- did_init=0
38
- if ! [[ -e .git ]]; then git init; did_init=1; fi
45
+ init_script = ''
46
+ git init
47
+ ${ sync_remotes }
48
+ git fetch --all
49
+ git checkout --track "${ conf . main_remote } /${ conf . main_branch } "
50
+ '' ;
39
51
40
- # Sync remotes
41
- ${ pkgs . bash } /bin/bash ${ ./sync_git_remotes.sh } <<"EOF"
42
- ${ concatStringsSep "\n " ( mapAttrsToList ( n : u : "${ n } ${ u } " ) conf . remotes ) }
43
- EOF
52
+ activation_script = ''
53
+ ${ sync_remotes }
44
54
45
55
${ if config . git . gitignore == "" then "" else ''
46
56
# Gitignore
47
- ln -sf "${ builtins . toFile "${ config . name } -vimrc" config . git . gitignore } " .git/info/exclude
57
+ ln -sf "${ builtins . toFile "${ config . name } -gitignore" conf . gitignore } " .git/info/exclude
48
58
'' }
49
-
50
- # If init, fetch remotes
51
- if [[ $did_init -eq 1 ]]; then
52
- git fetch --all
53
- git checkout --track "${ conf . main_remote } /${ conf . main_branch } "
54
- fi
55
59
'' ;
56
60
57
61
} ;
Original file line number Diff line number Diff line change @@ -42,7 +42,12 @@ open_workspace ()
42
42
let ws = import workspaces_nix { inherit pkgs config; }; in
43
43
ws.by_name { inherit wname; }' ) || wait_input_and_exit " Building of $wname in $2 failed."
44
44
45
- mkdir -p " $p "
45
+ if ! [[ -d " $p " ]]; then
46
+ mkdir -p " $p "
47
+ cd " $p "
48
+ nix-shell -p " ${buildInputs[@]} " --run workspace-init || wait_input_and_exit " Initialisation failed."
49
+ fi
50
+
46
51
cd " $p "
47
52
nix-shell -p " ${buildInputs[@]} " --run workspace-activate || wait_input_and_exit " Activating failed."
48
53
Original file line number Diff line number Diff line change 11
11
description = "Workspace name. Defaults to the attribute name used to define it." ;
12
12
} ;
13
13
14
+ init_script = mkOption {
15
+ type = types . lines ;
16
+ default = "" ;
17
+ description = "Run when the workspace is activated for the first time." ;
18
+ } ;
19
+
14
20
activation_script = mkOption {
15
21
type = types . lines ;
16
22
default = "" ;
66
72
assert ( builtins . hasAttr wname workspaces || throw "Workspace ${ wname } not found" ) ;
67
73
let
68
74
w = builtins . getAttr wname workspaces ;
75
+ init = pkgs . writeShellScriptBin "workspace-init" w . init_script ;
69
76
activate = pkgs . writeShellScriptBin "workspace-activate" w . activation_script ;
70
77
open = pkgs . writeShellScriptBin "workspace-open" w . command ;
71
78
in
72
- w . buildInputs ++ [ activate open ] ;
79
+ w . buildInputs ++ [ init activate open ] ;
73
80
} ;
74
81
75
82
in
You can’t perform that action at this time.
0 commit comments