commit d04233b8544580264cea8db43bc0c900699698f0
parent 91baa3db02923bd58f952df19a13ef4188f7d45e
Author: Vincent Demeester <vincent@sbr.pm>
Date: Mon, 11 May 2020 15:46:24 +0200
Makefile: simplify targets and fix nix auto update
No more test if user == root, … Use different targets
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Diffstat:
2 files changed, 66 insertions(+), 76 deletions(-)
diff --git a/Makefile b/Makefile
@@ -38,28 +38,23 @@ assets:
.PHONY: build
build: assets setup
- @if test $(USER) = root;\
- then\
- nixos-rebuild build;\
- else\
- home-manager build;\
- fi
+ home-manager build
-.PHONY: dry-build
-dry-build: assets setup
- @if test $(USER) = root;\
- then\
- nixos-rebuild dry-build;\
- fi
+.PHONY: nixos-build
+nixos-build: assets setup
+ nixos-rebuild build
+
+.PHONY: nixos-dry-build
+nixos-dry-build: assets setup
+ nixos-rebuild dry-build
.PHONY: switch
switch: assets setup
- @if test $(USER) = root;\
- then\
- nixos-rebuild switch;\
- else\
- home-manager switch;\
- fi
+ home-manager switch
+
+.PHONY: nixos-switch
+nixos-switch: assets setup
+ nixos-rebuild switch
install-hooks:
if [ -e .git ]; then nix-shell -p git --run 'git config core.hooksPath .githooks'; fi
@@ -111,7 +106,7 @@ doctor:
@readlink $(DOTNIXPKGS) || $(error $(DOTNIXPKGS) is not correctly linked, you may need to run setup)
.PHONY: setup
-setup: $(DOTEMACS) $(DOTGNUS) $(DOTNIXPKGS) $(ETCNIXOS) $(SYNCDIR)
+setup: $(DOTEMACS) $(DOTGNUS) $(DOTNIXPKGS) $(SYNCDIR)
$(DOTEMACS):
@echo "Link $(DOTEMACS) to $(CURDIR)/tools/emacs"
@@ -125,12 +120,5 @@ $(DOTNIXPKGS):
@echo "Link $(DOTNIXPKGS) to $(CURDIR)"
@ln -s $(CURDIR) $(DOTNIXPKGS)
-$(ETCNIXOS):
- @if test $(USER) = root;\
- then\
- echo "Link $(ETCNIXOS) $(CURDIR)";\
- ln -s $(CURDIR) $(ETCNIXOS);\
- fi
-
$(SYNCDIR):
$(error $(SYNCDIR) is not present, you need to configure syncthing before running this command)
diff --git a/modules/profiles/nix-auto-update.nixos.nix b/modules/profiles/nix-auto-update.nixos.nix
@@ -29,56 +29,58 @@ in
};
};
};
- config = mkIf cfg.enable
- (
- mkMerge [
- {
- system = {
- stateVersion = cfg.version;
- };
- }
- (
- mkIf cfg.autoUpgrade {
- systemd.services.nixos-update = {
- description = "NixOS Upgrade";
- unitConfig.X-StopOnRemoval = false;
- restartIfChanged = false;
- serviceConfig.Type = "oneshot";
- environment = config.nix.envVars
- // {
- inherit (config.environment.sessionVariables) NIX_PATH;
- HOME = "/root";
- };
- path = [ pkgs.gnutar pkgs.xz pkgs.git pkgs.gnumake config.nix.package.out pkgs.commonsCompress ];
- script = ''
- export PATH=/run/current-system/sw/bin
- cd /etc/nixos/
- make update switch
- '';
- startAt = cfg.dates;
- onFailure = [ "status-email-root@%n.service" ];
- };
- systemd.services.etc-nixos-git-update = {
- description = "Update NixOS source git repository";
- unitConfig.X-StopOnRemoval = false;
- restartIfChanged = false;
- serviceConfig.Type = "oneshot";
- serviceConfig.User = "vincent";
- environment = config.nix.envVars
- // {
- inherit (config.environment.sessionVariables) NIX_PATH;
- };
- path = [ pkgs.gnutar pkgs.xz pkgs.git ];
- script = ''
- export PATH=/run/current-system/sw/bin
- cd /etc/nixos/
- git pull --rebase --autostash --recurse-submodules
- '';
- startAt = "daily";
- onFailure = [ "status-email-root@%n.service" ];
+ config =
+ mkIf
+ cfg.enable
+ (
+ mkMerge [
+ {
+ system = {
+ stateVersion = cfg.version;
};
}
- )
- ]
- );
+ (
+ mkIf cfg.autoUpgrade {
+ systemd.services.nixos-update = {
+ description = "NixOS Upgrade";
+ unitConfig.X-StopOnRemoval = false;
+ restartIfChanged = false;
+ serviceConfig.Type = "oneshot";
+ environment = config.nix.envVars
+ // {
+ inherit (config.environment.sessionVariables) NIX_PATH;
+ HOME = "/root";
+ };
+ path = [ pkgs.gnutar pkgs.xz pkgs.git pkgs.gnumake config.nix.package.out pkgs.commonsCompress ];
+ script = ''
+ export PATH=/run/current-system/sw/bin
+ cd /etc/nixos/
+ make update nixos-switch
+ '';
+ startAt = cfg.dates;
+ onFailure = [ "status-email-root@%n.service" ];
+ };
+ systemd.services.etc-nixos-git-update = {
+ description = "Update NixOS source git repository";
+ unitConfig.X-StopOnRemoval = false;
+ restartIfChanged = false;
+ serviceConfig.Type = "oneshot";
+ serviceConfig.User = "vincent";
+ environment = config.nix.envVars
+ // {
+ inherit (config.environment.sessionVariables) NIX_PATH;
+ };
+ path = [ pkgs.gnutar pkgs.xz pkgs.git ];
+ script = ''
+ export PATH=/run/current-system/sw/bin
+ cd /etc/nixos/
+ git pull --rebase --autostash --recurse-submodules
+ '';
+ startAt = "daily";
+ onFailure = [ "status-email-root@%n.service" ];
+ };
+ }
+ )
+ ]
+ );
}