Optionally make the Nix store read-only to enforce immutability

This will be the default once Nix 1.2 is released.
wip/yesman
Eelco Dolstra 12 years ago
parent fcebb3f3cd
commit a139fa14b1
  1. 11
      modules/services/misc/nix-daemon.nix
  2. 11
      modules/system/boot/stage-2-init.sh
  3. 1
      modules/system/boot/stage-2.nix

@ -183,6 +183,17 @@ in
you should increase this value.
'';
};
readOnlyStore = mkOption {
default = false;
description = ''
If set, NixOS will enforce the immutability of the Nix store
by making <filename>/nix/store</filename> a read-only bind
mount. Nix will automatically make the store writable when
needed.
'';
};
};
};

@ -41,6 +41,17 @@ if [ ! -e /proc/1 ]; then
fi
# Make /nix/store a read-only bind mount to enforce immutability of
# the Nix store.
if [ -n "@readOnlyStore@" ]; then
if ! mountpoint /nix/store; then
mkdir -p /nix/rw-store
mount --bind /nix/store /nix/store
mount -o remount,ro,bind /nix/store
fi
fi
# Provide a /etc/mtab.
mkdir -m 0755 -p /etc
test -e /etc/fstab || touch /etc/fstab # to shut up mount

@ -60,6 +60,7 @@ let
shellDebug = "${pkgs.bashInteractive}/bin/bash";
isExecutable = true;
inherit (config.boot) devShmSize runSize cleanTmpDir;
inherit (config.nix) readOnlyStore;
ttyGid = config.ids.gids.tty;
path =
[ pkgs.coreutils

Loading…
Cancel
Save