about summary refs log tree commit diff
path: root/modules/nixos-apple-silicon/.github/workflows/installer.yml
blob: 2fe0b6d0655b5185de16065a15ae1330ae4cc175 (plain) (blame)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
name: build bootstrap installer

on:
  push:
    tags:
      - 'release-*'

  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - uses: cachix/install-nix-action@v18
        with:
          install_url: https://releases.nixos.org/nix/nix-2.13.2/install
          nix_path: nixpkgs=channel:nixos-unstable
          extra_nix_config: |
            # save space on disk and in cache
            auto-optimise-store = true
            # keep all store paths necessary to build the outputs
            keep-outputs = true
            keep-derivations = true

      - name: cache nix store
        id: cache-nix-store
        uses: actions/cache@v3
        with:
          key: installer5-${{ github.sha }}
          restore-keys: |
            installer5
          path: |
            nix_store_dir
            nix_store_db.sqlite

      - name: restore cached nix store
        run: |
          if [ -e nix_store_db.sqlite ]; then
            sudo systemctl stop nix-daemon

            # put cached store paths back in their proper locations
            sudo rm -rf /nix/store /nix/var/nix/db/db.sqlite
            sudo mv nix_store_dir /nix/store
            sudo cp nix_store_db.sqlite /nix/var/nix/db/db.sqlite

            # fix store permissions
            sudo chmod 1775 /nix/store
            sudo chown root:nixbld /nix/store
            sudo chmod 0644 /nix/var/nix/db/db.sqlite
            sudo chown -R root:root /nix/store /nix/var/nix/db/db.sqlite

            sudo systemctl start nix-daemon
          fi

      - name: build installer
        run: |
          nix build --extra-experimental-features 'nix-command flakes' .#installer-bootstrap -j2 -L
          cp result/iso/*.iso $(basename result/iso/*.iso | sed s/aarch64-linux/apple-silicon-${{ github.ref_name }}/)

      - uses: actions/upload-artifact@v3
        with:
          name: installer
          path: ./*.iso

      - uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        with:
          files: ./*.iso
      
      - name: prepare nix store for caching
        run: |
          # delete old stuff not relevant to this build
          nix-collect-garbage
          sudo systemctl stop nix-daemon

          # move store to a place where the cache action can read it
          sudo mv /nix/store nix_store_dir
          sudo mv /nix/var/nix/db/db.sqlite nix_store_db.sqlite