Commit d04233b85445

Vincent Demeester <vincent@sbr.pm>
2020-05-11 15:46:24
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>
1 parent 91baa3d
Changed files (2)
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" ];
+              };
+            }
+          )
+        ]
+      );
 }
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)