stage-2: replace readonly-mountpoint by findmnt

Changed files
+5 -32
nixos
-20
nixos/modules/system/boot/readonly-mountpoint.c
···
-
#include <sys/statvfs.h>
-
#include <stdio.h>
-
#include <stdlib.h>
-
-
int main(int argc, char ** argv) {
-
struct statvfs stat;
-
if (argc != 2) {
-
fprintf(stderr, "Usage: %s PATH", argv[0]);
-
exit(2);
-
}
-
if (statvfs(argv[1], &stat) != 0) {
-
perror("statvfs");
-
exit(3);
-
}
-
if (stat.f_flag & ST_RDONLY)
-
exit(0);
-
else
-
exit(1);
-
}
-
+3 -1
nixos/modules/system/boot/stage-2-init.sh
···
chown -f 0:30000 /nix/store
chmod -f 1775 /nix/store
if [ -n "@readOnlyStore@" ]; then
-
if ! readonly-mountpoint /nix/store; then
+
if ! [[ "$(findmnt --noheadings --output OPTIONS /nix/store)" =~ ro(,|$) ]]; then
+
# FIXME when linux < 4.5 is EOL, switch to atomic bind mounts
+
#mount /nix/store /nix/store -o bind,remount,ro
mount --bind /nix/store /nix/store
mount -o remount,ro,bind /nix/store
fi
+2 -11
nixos/modules/system/boot/stage-2.nix
···
kernel = config.boot.kernelPackages.kernel;
activateConfiguration = config.system.activationScripts.script;
-
readonlyMountpoint = pkgs.stdenv.mkDerivation {
-
name = "readonly-mountpoint";
-
unpackPhase = "true";
-
installPhase = ''
-
mkdir -p $out/bin
-
cc -O3 ${./readonly-mountpoint.c} -o $out/bin/readonly-mountpoint
-
'';
-
};
-
bootStage2 = pkgs.substituteAll {
src = ./stage-2-init.sh;
shellDebug = "${pkgs.bashInteractive}/bin/bash";
···
inherit (config.nix) readOnlyStore;
inherit (config.networking) useHostResolvConf;
inherit (config.system.build) earlyMountScript;
-
path = lib.makeBinPath ([
+
path = lib.makeBinPath [
pkgs.coreutils
pkgs.utillinux
pkgs.openresolv
-
] ++ optional config.nix.readOnlyStore readonlyMountpoint);
+
];
postBootCommands = pkgs.writeText "local-cmds"
''
${config.boot.postBootCommands}