From 2148123b9ca44f7d0df5d24fe22493237f1323d2 Mon Sep 17 00:00:00 2001
From: Eelco Dolstra <eelco.dolstra@logicblox.com>
Date: Mon, 8 Jan 2007 22:41:41 +0000
Subject: [PATCH] * Merge splash-themes.nix into the regular options
 infrastructure.

svn path=/nixos/trunk/; revision=7576
---
 system/config.nix        |  6 ++--
 system/options.nix       | 59 ++++++++++++++++++++++++++++++++++++++++
 system/splash-themes.nix | 58 ---------------------------------------
 system/system.nix        | 12 ++------
 system/upstart.nix       | 48 +++++++++++++++++++++++++-------
 5 files changed, 104 insertions(+), 79 deletions(-)
 delete mode 100644 system/splash-themes.nix

diff --git a/system/config.nix b/system/config.nix
index 46b9b1e76b8..7092ef6813c 100644
--- a/system/config.nix
+++ b/system/config.nix
@@ -3,13 +3,15 @@
 # defaults declared in options.nix if no value is given for an
 # option.
 
-lib: config:
+pkgs: config:
+
+let lib = pkgs.library; in
 
 rec {
 
   # The option declarations, i.e., option names with defaults and
   # documentation.
-  declarations = import ./options.nix;
+  declarations = import ./options.nix {inherit pkgs;};
 
   # Get the option named `name' from the user configuration, using
   # its default value if it's not defined.
diff --git a/system/options.nix b/system/options.nix
index 80ae8ead0a7..a1420c7037a 100644
--- a/system/options.nix
+++ b/system/options.nix
@@ -1,3 +1,5 @@
+{pkgs}:
+
 [
 
 
@@ -237,6 +239,63 @@
   }
 
       
+  {
+    name = ["services" "ttyBackgrounds" "enable"];
+    default = true;
+    description = "
+      Whether to enable graphical backgrounds for the virtual consoles.
+    ";
+  }
+
+      
+  {
+    name = ["services" "ttyBackgrounds" "defaultTheme"];
+    default = pkgs.fetchurl {
+      url = http://www.bootsplash.de/files/themes/Theme-BabyTux.tar.bz2;
+      md5 = "a6d89d1c1cff3b6a08e2f526f2eab4e0";
+    };
+    description = "
+      The default theme for the virtual consoles.  Themes can be found
+      at http://www.bootsplash.de/.
+    ";
+  }
+
+      
+  {
+    name = ["services" "ttyBackgrounds" "defaultSpecificThemes"];
+    default = [
+      { tty = 6;
+        theme = pkgs.fetchurl { # Yeah!
+          url = http://www.bootsplash.de/files/themes/Theme-Pativo.tar.bz2;
+          md5 = "9e13beaaadf88d43a5293e7ab757d569";
+        };
+      }
+      { tty = 10;
+        theme = pkgs.fetchurl {
+          url = http://www.bootsplash.de/files/themes/Theme-GNU.tar.bz2;
+          md5 = "61969309d23c631e57b0a311102ef034";
+        };
+      }
+    ];
+    description = "
+      This option sets specific themes for virtual consoles.  If you
+      just want to set themes for additional consoles, use
+      <option>services.ttyBackgrounds.specificThemes</option>.
+    ";
+  }
+
+      
+  {
+    name = ["services" "ttyBackgrounds" "specificThemes"];
+    default = [
+    ];
+    description = "
+      This option allows you to set specific themes for virtual
+      consoles.
+    ";
+  }
+
+      
   {
     name = ["services" "mingetty" "ttys"];
     default = [1 2 3 4 5 6];
diff --git a/system/splash-themes.nix b/system/splash-themes.nix
deleted file mode 100644
index 25be6168b37..00000000000
--- a/system/splash-themes.nix
+++ /dev/null
@@ -1,58 +0,0 @@
-{fetchurl}:
-
-rec {
-
-  # Some themes.
-  
-  themeBabyTux = fetchurl {
-    url = http://www.bootsplash.de/files/themes/Theme-BabyTux.tar.bz2;
-    md5 = "a6d89d1c1cff3b6a08e2f526f2eab4e0";
-  };
-
-  themeFrozenBubble = fetchurl {
-    url = http://www.bootsplash.de/files/themes/Theme-FrozenBubble.tar.bz2;
-    md5 = "da49f04988ab04b7e0de117b0d25061a";
-  };
-
-  themePativo = fetchurl { # Yeah!
-    url = http://www.bootsplash.de/files/themes/Theme-Pativo.tar.bz2;
-    md5 = "9e13beaaadf88d43a5293e7ab757d569";
-  };
-
-  themeGNU = fetchurl {
-    url = http://www.bootsplash.de/files/themes/Theme-GNU.tar.bz2;
-    md5 = "61969309d23c631e57b0a311102ef034";
-  };
-
-
-  # The splash screen.
-  
-  splashScreen = themeBabyTux;
-
-
-  # The themes to use for each tty.  For each tty except the first
-  # entry in the list, you can omit `theme' to get the same theme as
-  # the first one.  If a tty does not appear, it doesn't get a
-  # theme (i.e., it will keep a black background).
-  
-  ttyBackgrounds = [
-    { tty = 1;
-      theme = themeBabyTux;
-    }
-    { tty = 2;
-    }
-    { tty = 3;
-      theme = themeGNU;
-    }
-    { tty = 4;
-      theme = themeGNU;
-    }
-    { tty = 5;
-      theme = themePativo;
-    }
-    { tty = 10; # logging console
-      theme = themeGNU;
-    }
-  ];
-  
-}
diff --git a/system/system.nix b/system/system.nix
index 2b5c098c8b2..9089f451395 100644
--- a/system/system.nix
+++ b/system/system.nix
@@ -7,7 +7,7 @@ rec {
 
   # Make a configuration object from which we can retrieve option
   # values.
-  config = import ./config.nix pkgs.library configuration;
+  config = import ./config.nix pkgs configuration;
   
 
   pkgs = import ../pkgs/top-level/all-packages.nix {system = platform;};
@@ -30,12 +30,6 @@ rec {
   nix = pkgs.nixUnstable; # we need the exportReferencesGraph feature
 
 
-  # Splash configuration.
-  splashThemes = import ./splash-themes.nix {
-    inherit (pkgs) fetchurl;
-  };
-
-
   rootModules = 
     (config.get ["boot" "initrd" "extraKernelModules"]) ++
     (config.get ["boot" "initrd" "kernelModules"]);
@@ -100,7 +94,7 @@ rec {
       }
       { object = import ../helpers/unpack-theme.nix {
           inherit (pkgs) stdenv;
-          theme = splashThemes.splashScreen;
+          theme = config.get ["services" "ttyBackgrounds" "defaultTheme"];
         };
         symlink = "/etc/splash";
       }
@@ -117,7 +111,7 @@ rec {
 
   # The services (Upstart) configuration for the system.
   upstartJobs = import ./upstart.nix {
-    inherit config pkgs nix splashThemes;
+    inherit config pkgs nix;
   };
 
 
diff --git a/system/upstart.nix b/system/upstart.nix
index f93098478b7..f2227a729cd 100644
--- a/system/upstart.nix
+++ b/system/upstart.nix
@@ -1,4 +1,4 @@
-{config, pkgs, nix, splashThemes}:
+{config, pkgs, nix}:
 
 let 
 
@@ -66,12 +66,6 @@ import ../upstart-jobs/gather.nix {
       inherit nix;
     })
 
-    # Transparent TTY backgrounds.
-    (import ../upstart-jobs/tty-backgrounds.nix {
-      inherit (pkgs) stdenv splashutils;
-      backgrounds = splashThemes.ttyBackgrounds;
-    })
-
     # Handles the maintenance/stalled event (single-user shell).
     (import ../upstart-jobs/maintenance-shell.nix {
       inherit (pkgs) bash;
@@ -123,13 +117,47 @@ import ../upstart-jobs/gather.nix {
   # The terminals on ttyX.
   ++ (map 
     (ttyNumber: makeJob (import ../upstart-jobs/mingetty.nix {
-      inherit (pkgs) mingetty;
-      inherit ttyNumber;
-      loginProgram = "${pkgs.pam_login}/bin/login";
+        inherit (pkgs) mingetty;
+        inherit ttyNumber;
+        loginProgram = "${pkgs.pam_login}/bin/login";
     }))
     (config.get ["services" "mingetty" "ttys"])
   )
 
+  # Transparent TTY backgrounds.
+  ++ optional ["services" "ttyBackgrounds" "enable"]
+    (import ../upstart-jobs/tty-backgrounds.nix {
+      inherit (pkgs) stdenv splashutils;
+      
+      backgrounds =
+      
+        let
+        
+          specificThemes =
+            config.get ["services" "ttyBackgrounds" "defaultSpecificThemes"]
+            ++ config.get ["services" "ttyBackgrounds" "specificThemes"];
+            
+          overridenTTYs = map (x: x.tty) specificThemes;
+
+          requiredTTYs =
+            (config.get ["services" "mingetty" "ttys"])
+            ++ [10] /* !!! sync with syslog.conf */ ;
+
+          # Use the default theme for all the mingetty ttys and for the
+          # syslog tty, except those for which a specific theme is
+          # specified.
+          defaultTTYs =
+            pkgs.library.filter (x: !(pkgs.library.elem x overridenTTYs)) requiredTTYs;
+
+        in      
+          (map (ttyNumber: {
+            tty = ttyNumber;
+            theme = config.get ["services" "ttyBackgrounds" "defaultTheme"];
+          }) defaultTTYs)
+          ++ specificThemes;
+          
+    })
+
   # User-defined events.
   ++ (map makeJob (config.get ["services" "extraJobs"]))