Cache nix store between builds
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
xeals 2020-10-15 20:46:37 +11:00
parent 1d75c44bc1
commit 45682cdbab
Signed by: xeals
GPG Key ID: A498C7AF27EC6B5C
2 changed files with 151 additions and 1 deletions

View File

@ -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) = { local Pipeline(channel) = {
kind: "pipeline", kind: "pipeline",
type: "docker", type: "docker",
name: channel, 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: [ steps: [
Cache("restore-nix-store", {
restore: true
}),
{ {
name: "build", name: "build",
image: "nixos/nix", image: "nixos/nix",
@ -32,7 +69,12 @@ local Pipeline(channel) = {
CACHIX_CACHE: "xeals", CACHIX_CACHE: "xeals",
CACHIX_SIGNING_KEY: { from_secret: "cachix_key" }, CACHIX_SIGNING_KEY: { from_secret: "cachix_key" },
}, },
} },
Cache("save-nix-store", {
rebuild: true
}) + {
when: { status: [ "success", "failure" ] }
},
] ]
}; };

View File

@ -8,6 +8,20 @@ platform:
arch: amd64 arch: amd64
steps: 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 - name: build
image: nixos/nix image: nixos/nix
commands: commands:
@ -31,6 +45,28 @@ steps:
NIXPKGS_ALLOW_UNFREE: 1 NIXPKGS_ALLOW_UNFREE: 1
NUR_REPO: xeals 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 kind: pipeline
type: docker type: docker
@ -41,6 +77,20 @@ platform:
arch: amd64 arch: amd64
steps: 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 - name: build
image: nixos/nix image: nixos/nix
commands: commands:
@ -64,6 +114,28 @@ steps:
NIXPKGS_ALLOW_UNFREE: 1 NIXPKGS_ALLOW_UNFREE: 1
NUR_REPO: xeals 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 kind: pipeline
type: docker type: docker
@ -74,6 +146,20 @@ platform:
arch: amd64 arch: amd64
steps: 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 - name: build
image: nixos/nix image: nixos/nix
commands: commands:
@ -97,4 +183,26 @@ steps:
NIXPKGS_ALLOW_UNFREE: 1 NIXPKGS_ALLOW_UNFREE: 1
NUR_REPO: xeals 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: {}
... ...