diff --git a/.drone.jsonnet b/.drone.jsonnet index 473144a..b68d9e8 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -1,8 +1,45 @@ +local Cache(name, settings) = { + name: name, + image: "meltwater/drone-cache", + pull: true, + settings: { + backend: "filesystem", + cache_key: "{{ .Repo.Name }}", + archive_format: "gzip", + mount: [ + "/nix/store" + ] + } + settings, + volumes: [ + { + name: "cache", + path: "/tmp/cache" + } + ] +}; + local Pipeline(channel) = { kind: "pipeline", type: "docker", name: channel, + // This is ignored by the drone-cli YAML translator, so unfortunately, it has + // to be copy-pasted into relevant steps. + environment: { + NIXPKGS_ALLOW_UNFREE: 1, + NUR_REPO: "xeals", + CACHIX_CACHE: "xeals", + CACHIX_SIGNING_KEY: { from_secret: "cachix_key" }, + }, + volumes: [ + { + name: "cache", + temp: {} + } + ], steps: [ + Cache("restore-nix-store", { + restore: true + }), { name: "build", image: "nixos/nix", @@ -32,7 +69,12 @@ local Pipeline(channel) = { CACHIX_CACHE: "xeals", CACHIX_SIGNING_KEY: { from_secret: "cachix_key" }, }, - } + }, + Cache("save-nix-store", { + rebuild: true + }) + { + when: { status: [ "success", "failure" ] } + }, ] }; diff --git a/.drone.yml b/.drone.yml index 9284088..1d1895f 100644 --- a/.drone.yml +++ b/.drone.yml @@ -8,6 +8,20 @@ platform: arch: amd64 steps: +- name: restore-nix-store + pull: true + image: meltwater/drone-cache + settings: + archive_format: gzip + backend: filesystem + cache_key: "{{ .Repo.Name }}" + mount: + - /nix/store + restore: true + volumes: + - name: cache + path: /tmp/cache + - name: build image: nixos/nix commands: @@ -31,6 +45,28 @@ steps: NIXPKGS_ALLOW_UNFREE: 1 NUR_REPO: xeals +- name: save-nix-store + pull: true + image: meltwater/drone-cache + settings: + archive_format: gzip + backend: filesystem + cache_key: "{{ .Repo.Name }}" + mount: + - /nix/store + rebuild: true + volumes: + - name: cache + path: /tmp/cache + when: + status: + - success + - failure + +volumes: +- name: cache + temp: {} + --- kind: pipeline type: docker @@ -41,6 +77,20 @@ platform: arch: amd64 steps: +- name: restore-nix-store + pull: true + image: meltwater/drone-cache + settings: + archive_format: gzip + backend: filesystem + cache_key: "{{ .Repo.Name }}" + mount: + - /nix/store + restore: true + volumes: + - name: cache + path: /tmp/cache + - name: build image: nixos/nix commands: @@ -64,6 +114,28 @@ steps: NIXPKGS_ALLOW_UNFREE: 1 NUR_REPO: xeals +- name: save-nix-store + pull: true + image: meltwater/drone-cache + settings: + archive_format: gzip + backend: filesystem + cache_key: "{{ .Repo.Name }}" + mount: + - /nix/store + rebuild: true + volumes: + - name: cache + path: /tmp/cache + when: + status: + - success + - failure + +volumes: +- name: cache + temp: {} + --- kind: pipeline type: docker @@ -74,6 +146,20 @@ platform: arch: amd64 steps: +- name: restore-nix-store + pull: true + image: meltwater/drone-cache + settings: + archive_format: gzip + backend: filesystem + cache_key: "{{ .Repo.Name }}" + mount: + - /nix/store + restore: true + volumes: + - name: cache + path: /tmp/cache + - name: build image: nixos/nix commands: @@ -97,4 +183,26 @@ steps: NIXPKGS_ALLOW_UNFREE: 1 NUR_REPO: xeals +- name: save-nix-store + pull: true + image: meltwater/drone-cache + settings: + archive_format: gzip + backend: filesystem + cache_key: "{{ .Repo.Name }}" + mount: + - /nix/store + rebuild: true + volumes: + - name: cache + path: /tmp/cache + when: + status: + - success + - failure + +volumes: +- name: cache + temp: {} + ...