Skip to content

Commit c4ab335

Browse files
committed
Pinned nixpkgs for local shell
Ensure a local shell is reproducible and doesn't need internet access to be activated. To make room for the new option, 'local_shell' is renamed 'shell_nix.enabled' and definition is moved. The new option 'activation_command' is needed to implement shells in a separate module.
1 parent d362506 commit c4ab335

File tree

2 files changed

+46
-16
lines changed

2 files changed

+46
-16
lines changed

modules/shell_nix.nix

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
}

workspaces.nix

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ let
4343
"Directory for per-workspace cache, relative to the home directory. Used to store history files and other unimportant things.";
4444
};
4545

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'.";
5051
};
51-
5252
};
5353

5454
config = {
@@ -70,23 +70,15 @@ let
7070
base_module
7171
default_name # Base modules
7272
modules/git.nix
73-
modules/vim.nix
73+
modules/shell_nix.nix
7474
modules/tools.nix
75+
modules/vim.nix
7576
modules/xdg.nix
7677
configuration # User configuration
7778
];
7879
};
7980
in modules.config;
8081

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-
9082
stdenv = pkgs.stdenvNoCC;
9183

9284
# Generate the 'workspace-init' and 'workspace-activate' script for the
@@ -105,7 +97,7 @@ let
10597
activation_script = ''
10698
mkdir -p "$HOME/${w.cache_dir}"
10799
${w.activation_script}
108-
${make_activate_command w}
100+
${w.activation_command}
109101
'';
110102

111103
# Similar to 'pkgs.writeShellScriptBin', inlined to avoid generating many

0 commit comments

Comments
 (0)