Skip to content

Commit

Permalink
stage2 - replace tmp.mount with tmpfs handling on bootup/activation
Browse files Browse the repository at this point in the history
  • Loading branch information
sheenobu committed Apr 17, 2016
1 parent a827228 commit 5bad72d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
5 changes: 4 additions & 1 deletion nixos/modules/system/activation/activation-script.nix
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,11 @@ in
${pkgs.utillinux}/bin/mount -o "remount,size=${config.boot.devSize}" none /dev
${pkgs.utillinux}/bin/mount -o "remount,size=${config.boot.devShmSize}" none /dev/shm
${pkgs.utillinux}/bin/mount -o "remount,size=${config.boot.runSize}" none /run
'' + optionalString config.boot.tmpOnTmpfs ''
if [ mountpoint -q /tmp ]; then
${pkgs.utillinux}/bin/mount -o "remount,size=${config.boot.tmpFsSize}" none /tmp
fi
'';

};

}
10 changes: 10 additions & 0 deletions nixos/modules/system/boot/stage-2-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ if ! mountpoint -q /dev/shm; then
fi
mkdir -m 0755 -p /dev/pts
[ -e /proc/bus/usb ] && mount -t usbfs usbfs /proc/bus/usb # UML doesn't have USB by default

# Clean tmp directory, if requested
if [ -n "@cleanTmpDir@" ]; then
rm -rf /tmp
fi

mkdir -m 01777 -p /tmp
mkdir -m 0755 -p /var /var/log /var/lib /var/db
mkdir -m 0755 -p /nix/var
Expand All @@ -109,6 +115,10 @@ rm -f /etc/{group,passwd,shadow}.lock
# Also get rid of temporary GC roots.
rm -rf /nix/var/nix/gcroots/tmp /nix/var/nix/temproots

# Create a tmpfs on /tmp, if tmpOnTmpfs is enabled
if [ -n "@tmpOnTmpfs@" ]; then
mount -t tmpfs -o "mode=1777,strictatime,size=@tmpFsSize@" tmpfs /tmp
fi

# Create a tmpfs on /run to hold runtime state for programs such as
# udev (if stage 1 hasn't already done so).
Expand Down
1 change: 1 addition & 0 deletions nixos/modules/system/boot/stage-2.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ let
src = ./stage-2-init.sh;
shellDebug = "${pkgs.bashInteractive}/bin/bash";
isExecutable = true;
inherit (config.boot) cleanTmpDir tmpOnTmpfs tmpFsSize;
inherit (config.boot) devShmSize runSize;
inherit (config.nix) readOnlyStore;
inherit (config.networking) useHostResolvConf;
Expand Down
21 changes: 10 additions & 11 deletions nixos/modules/system/boot/tmp.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ with lib;
'';
};

boot.tmpFsSize = mkOption {
default = "90%";
example = "256m";
type = types.str;
description = ''
Size limit for the <filename>/tmp</filename> tmpfs. Look at mount(8), tmpfs size option,
for the accepted syntax.
'';
};
};

###### implementation

config = {

systemd.additionalUpstreamSystemUnits = optional config.boot.tmpOnTmpfs "tmp.mount";

systemd.tmpfiles.rules = optional config.boot.cleanTmpDir "D! /tmp 1777 root root";

};

}
}

0 comments on commit 5bad72d

Please sign in to comment.