-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
138 lines (103 loc) · 4.09 KB
/
Makefile
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
MAX_AGE = 14
UNAME := $(shell uname -s)
SHELL := $(shell which bash)
ROOT_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
# Lazily evaluated variables; expensive to compute, but we only want it do it
# when first necessary.
GIT_DATE = git --git-dir=nixpkgs-unstable/.git show -s --format=%cd --date=format:%Y%m%d_%H%M%S
HEAD_DATE = $(eval HEAD_DATE := $(shell $(GIT_DATE) HEAD))$(HEAD_DATE)
LKG_DATE = $(eval LKG_DATE := $(shell $(GIT_DATE) last-known-good))$(LKG_DATE)
BUILDPATH = /run/current-system
BUILD_ARGS = --keep-going --argstr version $(HEAD_DATE)
NIXPATH = darwin=$(ROOT_DIR)nix-darwin:darwin-config=$(ROOT_DIR)config/nix-darwin:home-manager=$(ROOT_DIR)home-manager:home-manager-config=$(ROOT_DIR)config/home-manager:nixpkgs-overlays=$(ROOT_DIR)overlays:nixpkgs=$(ROOT_DIR)nixpkgs-unstable:nixpkgs-stable=$(ROOT_DIR)nixpkgs-stable
PRENIX = NIX_PATH=$(NIXPATH)
NIX = $(PRENIX) nix
NIX_BUILD = $(PRENIX) nix-build
NIX_ENV = $(PRENIX) nix-env
NIX_STORE = $(PRENIX) nix-store
NIX_GC = $(PRENIX) nix-collect-garbage
DARWIN_REBUILD = $(PRENIX) $(BUILDPATH)/sw/bin/darwin-rebuild
HOME_MANAGER = $(PRENIX) HOME_MANAGER_CONFIG=$(ROOT_DIR)config/home-manager $(BUILDPATH)/sw/bin/home-manager
# Manage
all: rebuild
build:
@$(NIX) build -f . $(BUILD_ARGS)
@rm -f result*
build-darwin:
@$(NIX_BUILD) . -A nix-darwin
@rm -f result*
build-home:
@$(NIX_BUILD) . -A home-manager
@rm -f result*
darwin-switch:
@$(DARWIN_REBUILD) switch -Q
@echo "# Nix-darwin generation: $$(darwin-rebuild --list-generations | tail -1)"
home-switch:
@$(HOME_MANAGER) switch
@echo "# Home-manager generation: $$(home-manager generations | head -1)"
switch: darwin-switch home-switch
rebuild: build switch
pull:
@echo "# Updating repositories"
@echo "# Pulling nixpkgs-stable"
@(cd nixpkgs-stable && git pull --rebase)
@echo "# Pulling nixpkgs-unstable"
@(cd nixpkgs-unstable && git pull --rebase)
@echo "# Pulling nix-darwin"
@(cd nix-darwin && git pull --rebase origin master)
@echo "# Pulling home-manager"
@(cd home-manager && git pull --rebase origin master)
tag-before:
@echo "# Tagging before update"
@git --git-dir=nixpkgs-unstable/.git branch -f before-update HEAD
tag-working:
@echo "# Tagging after update"
@git --git-dir=nixpkgs-unstable/.git branch -f last-known-good before-update
@git --git-dir=nixpkgs-unstable/.git branch -D before-update
@git --git-dir=nixpkgs-unstable/.git tag -f known-good-$(LKG_DATE) last-known-good
mirror:
@echo "# Pushing changes to mirrors on pjan"
@git --git-dir=nixpkgs-unstable/.git push pjan -f master:master
@git --git-dir=nixpkgs-unstable/.git push pjan -f nixpkgs-unstable:nixpkgs-unstable
@git --git-dir=nixpkgs-unstable/.git push pjan -f last-known-good:last-known-good
@git --git-dir=nixpkgs-unstable/.git push -f --tags pjan
@git --git-dir=nix-darwin/.git push --mirror pjan
@git --git-dir=home-manager/.git push --mirror pjan
working: tag-working mirror
update: tag-before pull rebuild working
check:
@$(NIX_STORE) --verify --repair --check-contents
########################################################################
define delete-generations
$(NIX_ENV) $(1) --delete-generations \
$(shell $(NIX_ENV) $(1) \
--list-generations | field 1 | head -n -$(2))
endef
define delete-generations-all
$(call delete-generations,,$(1))
$(call delete-generations,-p /nix/var/nix/profiles/system,$(1))
endef
clean: gc check
fullclean: gc-old check
remove-build-products:
clean $(HOME)/Documents $(HOME)/src
gc:
$(call delete-generations-all,$(MAX_AGE))
$(NIX_GC) --delete-older-than $(MAX_AGE)d
gc-old: remove-build-products
$(call delete-generations-all,1)
$(NIX_GC) --delete-old
########################################################################
# env-build:
# @nix build darwin.pkgs.envs.ghc82
# @rm result
# env-update:
# @nix-env -f '<darwin>' -u --leq -Q -k -A pkgs.envs.ghc82
# @rm result
# env-build-all:
# @nix build darwin.pkgs.envs.ghc82
# @nix build darwin.pkgs.envs.ghc82-profiled
# @rm result
# env-update-all:
# @nix-env -f '<darwin>' -u --leq -Q -j4 -k -A pkgs \
# || nix-env -f '<darwin>' -u --leq -Q -A pkgs