summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatej Urbas <matej.urbas@gmail.com>2021-02-07 21:00:00 +0000
committerMatej Urbas <matej.urbas@gmail.com>2021-02-15 18:44:34 +0000
commita6766bee7bee10903232660dd9f200da9cdc1210 (patch)
tree535b2ad8412ae619ce0988edf3f0c6a1abfe0b88
parent4c9a74aa459dc525fcfdfb3019b234f68de66c8a (diff)
downloadnixpkgs-a6766bee7bee10903232660dd9f200da9cdc1210.tar
nixpkgs-a6766bee7bee10903232660dd9f200da9cdc1210.tar.gz
nixpkgs-a6766bee7bee10903232660dd9f200da9cdc1210.tar.bz2
nixpkgs-a6766bee7bee10903232660dd9f200da9cdc1210.tar.lz
nixpkgs-a6766bee7bee10903232660dd9f200da9cdc1210.tar.xz
nixpkgs-a6766bee7bee10903232660dd9f200da9cdc1210.tar.zst
nixpkgs-a6766bee7bee10903232660dd9f200da9cdc1210.zip
virtualization/amazon-init: enable option
-rw-r--r--nixos/modules/virtualisation/amazon-init.nix41
1 files changed, 29 insertions, 12 deletions
diff --git a/nixos/modules/virtualisation/amazon-init.nix b/nixos/modules/virtualisation/amazon-init.nix
index c5470b7af09..be83607c0af 100644
--- a/nixos/modules/virtualisation/amazon-init.nix
+++ b/nixos/modules/virtualisation/amazon-init.nix
@@ -1,6 +1,10 @@
-{ config, pkgs, ... }:
+{ config, lib, pkgs, ... }:
+
+with lib;
 
 let
+  cfg = config.virtualisation.amazon-init;
+
   script = ''
     #!${pkgs.runtimeShell} -eu
 
@@ -41,20 +45,33 @@ let
     nixos-rebuild switch
   '';
 in {
-  systemd.services.amazon-init = {
-    inherit script;
-    description = "Reconfigure the system from EC2 userdata on startup";
 
-    wantedBy = [ "multi-user.target" ];
-    after = [ "multi-user.target" ];
-    requires = [ "network-online.target" ];
+  options.virtualisation.amazon-init = {
+    enable = mkOption {
+      default = true;
+      type = types.bool;
+      description = ''
+        Enable or disable the amazon-init service.
+      '';
+    };
+  };
+
+  config = mkIf cfg.enable {
+    systemd.services.amazon-init = {
+      inherit script;
+      description = "Reconfigure the system from EC2 userdata on startup";
+
+      wantedBy = [ "multi-user.target" ];
+      after = [ "multi-user.target" ];
+      requires = [ "network-online.target" ];
 
-    restartIfChanged = false;
-    unitConfig.X-StopOnRemoval = false;
+      restartIfChanged = false;
+      unitConfig.X-StopOnRemoval = false;
 
-    serviceConfig = {
-      Type = "oneshot";
-      RemainAfterExit = true;
+      serviceConfig = {
+        Type = "oneshot";
+        RemainAfterExit = true;
+      };
     };
   };
 }