summaryrefslogtreecommitdiff
path: root/modules/system/base.nix
blob: f20e2b6407c80988cd3600e1ff784592e3c55d08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{ ... }:

{
  system.activationScripts.createRun.text = ''
    IFS="." read -r -a macOSVersion <<< "$(sw_vers -productVersion)"

    if [[ ''${macOSVersion[0]} -gt 10 || ( ''${macOSVersion[0]} -eq 10 && ''${macOSVersion[1]} -ge 15 ) ]]; then
      if ! grep -q '^run\b' /etc/synthetic.conf 2>/dev/null; then
        echo "setting up /run via /etc/synthetic.conf..."
        printf 'run\tprivate/var/run\n' | sudo tee -a /etc/synthetic.conf >/dev/null
      fi

      if [[ ''${macOSVersion[0]} -gt 10 ]]; then
        sudo /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -t || true
      else
        sudo /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -B || true
      fi

      if [[ ! -L /run ]]; then
        printf >&2 'error: apfs.util failed to symlink /run, aborting activation\n'
        printf >&2 'To create a symlink from /run to /var/run, please run:\n'
        printf >&2 '\n'
        printf >&2 "$ printf 'run\tprivate/var/run\n' | sudo tee -a /etc/synthetic.conf"

        if [[ ''${macOSVersion[0]} -gt 10 ]]; then
          printf >&2 '$ sudo /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -t\n'
        else
          printf >&2 '$ sudo /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -B\n'
        fi

        printf >&2 '\n'
        printf >&2 'The current contents of /etc/synthetic.conf is:\n'
        printf >&2 '\n'
        sudo sed 's/^/    /' /etc/synthetic.conf >&2
        printf >&2 '\n'
        exit 1
      fi
    else
      echo "setting up /run..."
      sudo ln -sfn private/var/run /run

      if [[ ! -L /run ]]; then
        printf >&2 'error: failed to symlink /run, aborting activation\n'
        printf >&2 'To create a symlink from /run to /var/run, please run:\n'
        printf >&2 '\n'
        printf >&2 '$ sudo ln -sfn private/var/link /run\n'
        exit 1
      fi
    fi
  '';
}