From 7aa27dfee2ea7ae571717493058ad3123ffdb445 Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Fri, 2 Jan 2009 19:41:39 +0000 Subject: [PATCH 01/14] Merge branches 'fix-style' and 'master' into fix-style svn path=/nixos/branches/fix-style/; revision=13688 --- boot/boot-stage-1-init.sh | 55 +++++--- default.nix | 2 +- doc/manual/default.nix | 2 + doc/manual/manual.xml | 1 + etc/default.nix | 34 +++-- etc/pam.d/lsh-pam-checkpw | 4 - installer/cd-dvd/closed-install.nix | 1 + installer/cd-dvd/rescue-cd-configurable.nix | 1 - installer/cd-dvd/rescue-cd.nix | 14 +- release.nix | 75 +++++++++++ system/options.nix | 76 +++++++---- system/system-options.nix | 6 +- system/system.nix | 3 + upstart-jobs/atd.nix | 15 ++- upstart-jobs/default.nix | 6 +- upstart-jobs/fcron.nix | 138 ++++++++++++++++++++ upstart-jobs/lshd.nix | 1 + upstart-jobs/sshd.nix | 3 +- upstart-jobs/xserver.nix | 6 + 19 files changed, 361 insertions(+), 82 deletions(-) delete mode 100644 etc/pam.d/lsh-pam-checkpw create mode 100644 release.nix create mode 100644 upstart-jobs/fcron.nix diff --git a/boot/boot-stage-1-init.sh b/boot/boot-stage-1-init.sh index 0ddf6bb7eae..c6d7214028c 100644 --- a/boot/boot-stage-1-init.sh +++ b/boot/boot-stage-1-init.sh @@ -138,6 +138,26 @@ fi if test -n "$debug1devices"; then fail; fi +# Return true if the machine is on AC power, or if we can't determine +# whether it's on AC power. +onACPower () { + if test -d "/proc/acpi/battery"; then + if ls /proc/acpi/battery/BAT[0-9]* > /dev/null 2>&1; then + if cat /proc/acpi/battery/BAT*/state \ + | grep "^charging state" \ + | grep -q "discharg" ; then + false + else + true + fi + else + true + fi + else + true + fi +} + # Function for mounting a file system. mountFS() { local device="$1" @@ -158,24 +178,29 @@ mountFS() { fi if test -n "$mustCheck"; then - FSTAB_FILE="/etc/mtab" fsck -V -v -C -a "$device" - fsckResult=$? + if onACPower; then + FSTAB_FILE="/etc/mtab" fsck -V -v -C -a "$device" + fsckResult=$? - if test $(($fsckResult | 2)) = $fsckResult; then - echo "fsck finished, rebooting..." - sleep 3 - reboot - fi + if test $(($fsckResult | 2)) = $fsckResult; then + echo "fsck finished, rebooting..." + sleep 3 + reboot + fi - if test $(($fsckResult | 4)) = $fsckResult; then - echo "$device has unrepaired errors, please fix them manually." - fail - fi + if test $(($fsckResult | 4)) = $fsckResult; then + echo "$device has unrepaired errors, please fix them manually." + fail + fi - if test $fsckResult -ge 8; then - echo "fsck on $device failed." - fail - fi + if test $fsckResult -ge 8; then + echo "fsck on $device failed." + fail + fi + else + # Don't run `fsck' if the machine is on battery power. + echo "on battery power, so \`fsck' not run on \`$device'" + fi fi # Mount read-writable. diff --git a/default.nix b/default.nix index 1a621c3457e..86f437d3696 100644 --- a/default.nix +++ b/default.nix @@ -1,6 +1,6 @@ let - fromEnv = name : default : + fromEnv = name: default: let env = builtins.getEnv name; in if env == "" then default else env; configuration = import (fromEnv "NIXOS_CONFIG" /etc/nixos/configuration.nix); diff --git a/doc/manual/default.nix b/doc/manual/default.nix index e6f9b84329f..a7f51adf287 100644 --- a/doc/manual/default.nix +++ b/doc/manual/default.nix @@ -38,6 +38,8 @@ let ${pkgs.docbook5_xsl}/xml/xsl/docbook/html/docbook.xsl \ ./manual.xml cp ${./style.css} $out/style.css + ensureDir $out/nix-support + echo "doc manual $out" >> $out/nix-support/hydra-build-products ''; }; diff --git a/doc/manual/manual.xml b/doc/manual/manual.xml index 55adf3e647d..9f79b6fdb6e 100644 --- a/doc/manual/manual.xml +++ b/doc/manual/manual.xml @@ -15,6 +15,7 @@ 2007 + 2008 Eelco Dolstra diff --git a/etc/default.nix b/etc/default.nix index 731558b67f2..fc07a39f9be 100644 --- a/etc/default.nix +++ b/etc/default.nix @@ -30,13 +30,12 @@ let nssModulesPath = config.system.nssModules.path; wrapperDir = config.system.wrapperDir; systemPath = config.system.path; + binsh = config.system.build.binsh; optional = pkgs.lib.optional; # !!! ugh, these files shouldn't be created here. - - pamConsoleHandlers = pkgs.writeText "console.handlers" '' console consoledevs /dev/tty[0-9][0-9]* :[0-9]\.[0-9] :[0-9] ${pkgs.pam_console}/sbin/pam_console_apply lock logfail wait -t tty -s -c ${pamConsolePerms} @@ -131,14 +130,28 @@ let } { # Nix configuration. - source = pkgs.writeText "nix.conf" '' - # WARNING: this file is generated. - build-users-group = nixbld - build-max-jobs = ${toString (config.nix.maxJobs)} - build-use-chroot = ${if config.nix.useChroot then "true" else "false"} - build-chroot-dirs = /dev /dev/pts /proc /bin - ${config.nix.extraOptions} - ''; + source = + let + # Tricky: if we're using a chroot for builds, then we need + # /bin/sh in the chroot (our own compromise to purity). + # However, since /bin/sh is a symlink to some path in the + # Nix store, which furthermore has runtime dependencies on + # other paths in the store, we need the closure of /bin/sh + # in `build-chroot-dirs' - otherwise any builder that uses + # /bin/sh won't work. + refs = pkgs.writeReferencesToFile binsh; + in + pkgs.runCommand "nix.conf" {} '' + binshDeps=$(for i in $(cat ${refs}); do if test -d $i; then echo $i; fi; done) + cat > $out <> $out/nix-support/hydra-build-products + ''; # */ + + + }; + + +in jobs \ No newline at end of file diff --git a/system/options.nix b/system/options.nix index ad97565bb97..fbb316dc53a 100644 --- a/system/options.nix +++ b/system/options.nix @@ -301,7 +301,6 @@ in kernel = kernelPackages.kernel; in [ kernel ] - ++ pkgs.lib.optional ((config.networking.enableIntel3945ABGFirmware || config.networking.enableIntel4965AGNFirmware) && !kernel.features ? iwlwifi) kernelPackages.iwlwifi ++ pkgs.lib.optional config.hardware.enableGo7007 kernelPackages.wis_go7007 ++ config.boot.extraModulePackages # should only keep this one, other have to be set by the option owners. @@ -818,6 +817,13 @@ in no "; }; + + gatewayPorts = mkOption { + default = "no"; + description = " + Specifies whether remote hosts are allowed to connect to ports forwarded for the client. See man sshd_conf. + "; + }; }; lshd = { @@ -1255,9 +1261,11 @@ in default = []; example = [ "proxy_connect" { name = "php5_module"; path = "${pkgs.php}/modules/libphp5.so"; } ]; description = '' - Loads additional modules either beeing distributed with apache. - If the module is contained in a foreign package (such as php5_module) - kse an attrset as given in the example. + Specifies additional Apache modules. These can be specified + as a string in the case of modules distributed with Apache, + or as an attribute set specifying the + name and path of the + module. ''; }; @@ -1996,25 +2004,29 @@ in example = [ { type = "svn"; url = "https://svn.nixos.org/repos/nix/nixos/branches/stdenv-updates"; target = "/etc/nixos/nixos-stdenv-updates"; } { type = "git"; initialize = ''git clone git://mawercer.de/nixos $target''; update = "git pull origin"; target = "/etc/nixos/nixos-git"; } ]; - description = "The NixOS repository from which the system will be build. - nixos-checkout will update all working copies of the given repositories, - nixos-rebuild will use the first item which has - the attribute default = true falling back to the - first item. The type defines the repository tool added - to the path. It also defines a \"valid\" repository. - If the target directory already exists and it's not - valid it will be moved to the backup location - \${dir}-date. - For svn the default target and repositories are - /etc/nixos/nixos and - https://svn.nixos.org/repos/nix/nixos/trunk. - For git repositories update is called after - initialization when the repo is initialized. - The initialize code is run from working directory - dirname \$target and should create the directory - \$target. (git clone url nixos/nixpkgs/services should do) - For the executables beeing used see - "; + description = '' + The NixOS repository from which the system will be built. + nixos-checkout will update all working + copies of the given repositories, + nixos-rebuild will use the first item + which has the attribute default = true + falling back to the first item. The type defines the + repository tool added to the path. It also defines a "valid" + repository. If the target directory already exists and it's + not valid it will be moved to the backup location + dir-date. + For svn the default target and repositories are + /etc/nixos/nixos and + https://svn.nixos.org/repos/nix/nixos/trunk. + For git repositories update is called after initialization + when the repo is initialized. The initialize code is run + from working directory dirname + target and should create the + directory + dir. (git + clone url nixos/nixpkgs/services should do) For + the executables used see . + ''; }; nixpkgs = mkOption { @@ -2029,12 +2041,17 @@ in }; repoTypes = mkOption { - default = { - svn = { valid = "[ -d .svn ]"; env = [ pkgs.coreutils pkgs.subversion ]; }; - git = { valid = "[ -d .git ]"; env = [ pkgs.coreutils pkgs.git pkgs.gnused /* FIXME: use full path to sed in nix-pull */ ]; }; - }; - description = "defines PATH environment and when directory is considered beeing a valid repository. - If it's not it's moved to a backup directory"; + default = { + svn = { valid = "[ -d .svn ]"; env = [ pkgs.coreutils pkgs.subversion ]; }; + git = { valid = "[ -d .git ]"; env = [ pkgs.coreutils pkgs.git pkgs.gnused /* FIXME: use full path to sed in nix-pull */ ]; }; + }; + description = '' + Defines, for each supported version control system + (e.g. git), the dependencies for the + mechanism, as well as a test used to determine whether a + directory is a checkout created by that version control + system. + ''; }; manifests = mkOption { @@ -2423,6 +2440,7 @@ in (import ../upstart-jobs/zabbix-server.nix) (import ../upstart-jobs/disnix.nix) (import ../upstart-jobs/cron.nix) + (import ../upstart-jobs/fcron.nix) (import ../upstart-jobs/cron/locate.nix) # fonts diff --git a/system/system-options.nix b/system/system-options.nix index 650a08e0a76..97a9e05d4f5 100644 --- a/system/system-options.nix +++ b/system/system-options.nix @@ -88,6 +88,10 @@ in ]; system = { + build = { + binsh = pkgs.bashInteractive; + }; + activationScripts = { systemConfig = noDepEntry '' systemConfig="$1" @@ -122,7 +126,7 @@ in # Create the required /bin/sh symlink; otherwise lots of things # (notably the system() function) won't work. mkdir -m 0755 -p $mountPoint/bin - ln -sfn ${pkgs.bash}/bin/sh $mountPoint/bin/sh + ln -sfn ${config.system.build.binsh}/bin/sh $mountPoint/bin/sh '' [ activateLib.defaultPath # path to ln & mkdir activateLib.stdio # ? diff --git a/system/system.nix b/system/system.nix index 0eb86cc857d..75087708b83 100644 --- a/system/system.nix +++ b/system/system.nix @@ -184,6 +184,9 @@ rec { # at boot time (such as start `init'). activateConfiguration = config.system.activationScripts.script; + # The shell that we want to use for /bin/sh. + binsh = pkgs.bashInteractive; + # The init script of boot stage 2, which is supposed to do # everything else to bring up the system. diff --git a/upstart-jobs/atd.nix b/upstart-jobs/atd.nix index b477a38eee4..cfdbeb67915 100644 --- a/upstart-jobs/atd.nix +++ b/upstart-jobs/atd.nix @@ -19,7 +19,8 @@ let default = false; description = '' Whether to make /var/spool/at{jobs,spool} writeable - by everyone (and sticky). + by everyone (and sticky). This is normally not needed since + the `at' commands are setuid/setgid `atd'. ''; }; }; @@ -74,7 +75,7 @@ start script if [ ! -f "$etcdir"/at.deny ] then touch "$etcdir"/at.deny && \ - chown root:root "$etcdir"/at.deny && \ + chown root:atd "$etcdir"/at.deny && \ chmod 640 "$etcdir"/at.deny fi if [ ! -f "$jobdir"/.SEQ ] @@ -107,9 +108,13 @@ mkIf cfg.enable { ]; security = { - extraSetuidPrograms = [ - "at" "atq" "atrm" - ]; + setuidOwners = map (program: { + inherit program; + owner = "atd"; + group = "atd"; + setuid = true; + setgid = true; + }) [ "at" "atq" "atrm" ]; }; environment = { diff --git a/upstart-jobs/default.nix b/upstart-jobs/default.nix index f0862aaddec..3633dee63e7 100644 --- a/upstart-jobs/default.nix +++ b/upstart-jobs/default.nix @@ -150,7 +150,7 @@ let firmwareDirs = pkgs.lib.optional config.networking.enableIntel2200BGFirmware pkgs.ipw2200fw ++ pkgs.lib.optional config.networking.enableIntel3945ABGFirmware pkgs.iwlwifi3945ucode - ++ pkgs.lib.optional config.networking.enableIntel4965AGNFirmware pkgs.iwlwifi4965ucode + ++ pkgs.lib.optional config.networking.enableIntel4965AGNFirmware kernelPackages.iwlwifi4965ucode ++ pkgs.lib.optional config.networking.enableZydasZD1211Firmware pkgs.zd1211fw ++ pkgs.lib.optional config.hardware.enableGo7007 "${kernelPackages.wis_go7007}/firmware" ++ config.services.udev.addFirmware; @@ -239,9 +239,7 @@ let inherit (pkgs) writeText openssh glibc; inherit (pkgs.xorg) xauth; inherit nssModulesPath; - forwardX11 = config.services.sshd.forwardX11; - allowSFTP = config.services.sshd.allowSFTP; - permitRootLogin = config.services.sshd.permitRootLogin; + inherit (config.services.sshd) forwardX11 allowSFTP permitRootLogin gatewayPorts; }) # GNU lshd SSH2 deamon. diff --git a/upstart-jobs/fcron.nix b/upstart-jobs/fcron.nix new file mode 100644 index 00000000000..97d259c65e1 --- /dev/null +++ b/upstart-jobs/fcron.nix @@ -0,0 +1,138 @@ +{pkgs, config}: + +###### interface +let + inherit (pkgs.lib) mkOption concatStringsSep; + inherit (pkgs) writeText; + + options = { + services = { + fcron = { + enable = mkOption { + default = false; + description = ''Whether to enable the `fcron' daemon. + From its docs: "fcron does both the job of Vixie Cron and anacron, but does even more and better". + It can trigger actions even if the event has passed due to shutdown for example. + TODO: add supoprt for fcron.allow and fcron.deny + Of course on cron daemon is enough.. So if fcron works fine there should be a system option systemCron="fcron or cron" + + There are (or have been) some security issues. + I haven't yet checked wether they have been resolved. + For now you should trust the users registering crontab files. + I think gentoo has them listed. + ''; + }; + allow = mkOption { + default = []; + description = '' + Users allowed to use fcrontab and fcrondyn (one name per line, special name "all" acts for everyone) + nix adds username "root" for you. + ''; + }; + deny = mkOption { + default = []; + description = " same as allow but deny "; + }; + maxSerialJobs = mkOption { + default = 1; + description = "maximum number of serial jobs which can run simultaneously (-m)"; + }; + queuelen = mkOption { + default = ""; + description = "number of jobs the serial queue and the lavg queue can contain - empty to net set this number (-q)"; + }; + systab = mkOption { + default = ""; + description = '' + The "system" crontab contents.. + ''; + }; + }; + }; + }; +in + +###### implementation +let + # Put all the system cronjobs together. + # TODO allow using fcron only.. + #systemCronJobs = + # config.services.cron.systemCronJobs; + cfg = config.services.fcron; + ifEnabled = if cfg.enable then pkgs.lib.id else (x : []); + queuelen = if cfg.queuelen == "" then "" else "-q ${toString cfg.queuelen}"; + + # shell is set to /sh in config.. + # ${pkgs.lib.concatStrings (map (job: job + "\n") systemCronJobs)} + systemCronJobsFile = pkgs.writeText "fcron-systab" '' + SHELL=${pkgs.bash}/bin/sh + PATH=${pkgs.coreutils}/bin:${pkgs.findutils}/bin:${pkgs.gnused}/bin + ''; + + allowdeny = target: users : { + source = writeText "fcron.${target}" (concatStringsSep "\n" users); + target = "fcron.${target}"; + mode = "600"; # fcron has some security issues.. So I guess this is most safe + }; + +in + +{ + require = [ + # (import ../upstart-jobs/default.nix) # config.services.extraJobs + # (import ?) # config.time.timeZone + # (import ?) # config.environment.etc + # (import ?) # config.environment.extraPackages + # (import ?) # config.environment.cleanStart + options + ]; + + environment = { + etc = ifEnabled [ + (allowdeny "allow" (["root"] ++ cfg.allow)) + (allowdeny "deny" cfg.deny) + # see man 5 fcron.conf + { source = writeText "fcon.conf" '' + fcrontabs = /var/spool/fcron + pidfile = /var/run/fcron.pid + fifofile = /var/run/fcron.fifo + fcronallow = /etc/fcron.allow + fcrondeny = /etc/fcron.deny + shell = /bin/sh + sendmail = /var/setuid-wrappers/sendmail + editor = /var/run/current-system/sw/bin/vi + ''; + target = "fcron.conf"; + mode = "0600"; # max allowed is 644 + } + ]; + + extraPackages = ifEnabled ( + pkgs.lib.optional + (!config.environment.cleanStart) + pkgs.fcron); + }; + + services = { + extraJobs = ifEnabled [{ + name = "fcron"; + + job = '' + description "fcron daemon" + + start on startup + stop on shutdown + + env PATH=/var/run/current-system/sw/bin + + start script + ${pkgs.coreutils}/bin/mkdir -m 0700 -p /var/spool/fcron + # load system crontab file + ${pkgs.fcron}/bin/fcrontab -u systab ${writeText "systab" cfg.systab} + end script + + respawn ${pkgs.fcron}/sbin/fcron -f -m ${toString cfg.maxSerialJobs} ${queuelen} + ''; + }]; + }; +} diff --git a/upstart-jobs/lshd.nix b/upstart-jobs/lshd.nix index e2a61eed387..0a13d9ba7ee 100644 --- a/upstart-jobs/lshd.nix +++ b/upstart-jobs/lshd.nix @@ -31,6 +31,7 @@ start script end script respawn ${lsh}/sbin/lshd --daemonic \ + --password-helper="${lsh}/sbin/lsh-pam-checkpw" \ -p ${toString portNumber} \ ${if interfaces == [] then "" else (concatStrings (map (i: "--interface=\"${i}\"") diff --git a/upstart-jobs/sshd.nix b/upstart-jobs/sshd.nix index c64c4eb49a5..e9b916e81d3 100644 --- a/upstart-jobs/sshd.nix +++ b/upstart-jobs/sshd.nix @@ -1,6 +1,6 @@ { writeText, openssh, glibc, xauth , nssModulesPath -, forwardX11, allowSFTP, permitRootLogin +, forwardX11, allowSFTP, permitRootLogin, gatewayPorts }: assert permitRootLogin == "yes" || @@ -29,6 +29,7 @@ let "} PermitRootLogin ${permitRootLogin} + GatewayPorts ${gatewayPorts} ''; diff --git a/upstart-jobs/xserver.nix b/upstart-jobs/xserver.nix index 231bcd943ad..0e204282c14 100644 --- a/upstart-jobs/xserver.nix +++ b/upstart-jobs/xserver.nix @@ -183,6 +183,10 @@ let default = "0.12"; description = "Cursor speed factor for highest-speed finger motion"; }; + twoFingerScroll = mkOption { + default = false; + description = "Whether to enable two-finger drag-scrolling"; + }; }; layout = mkOption { @@ -413,6 +417,8 @@ let Option "TapButton1" "1" Option "TapButton2" "2" Option "TapButton3" "3" + Option "VertTwoFingerScroll" "${if cfg.synaptics.twoFingerScroll then "1" else "0"}" + Option "HorizTwoFingerScroll" "${if cfg.synaptics.twoFingerScroll then "1" else "0"}" EndSection '' else ""; From b92036e803fa0eaea54459f098b035203cc80cd8 Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Sun, 25 Jan 2009 15:48:25 +0000 Subject: [PATCH 02/14] Fetch the windows manager pid. svn path=/nixos/branches/fix-style/; revision=13849 --- upstart-jobs/xserver.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/upstart-jobs/xserver.nix b/upstart-jobs/xserver.nix index 0e204282c14..51004d45702 100644 --- a/upstart-jobs/xserver.nix +++ b/upstart-jobs/xserver.nix @@ -586,7 +586,7 @@ let '' else abort ("unknown window manager " + windowManager)} - + WMpid=$! ### Show a background image. # (but not if we're starting a full desktop environment that does it for us) From 08280c415f2c7e337e7e646494d919ccc39f6082 Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Sun, 25 Jan 2009 15:48:30 +0000 Subject: [PATCH 03/14] Add support for wmii. svn path=/nixos/branches/fix-style/; revision=13850 --- upstart-jobs/xserver.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/upstart-jobs/xserver.nix b/upstart-jobs/xserver.nix index 51004d45702..9064ec15310 100644 --- a/upstart-jobs/xserver.nix +++ b/upstart-jobs/xserver.nix @@ -581,6 +581,10 @@ let ${pkgs.xmonad}/bin/xmonad & '' + else if windowManager == "wmii" then '' + ${pkgs.wmiiSnap}/bin/wmii & + '' + else if windowManager == "none" then '' # The session starter will start the window manager. '' From bb56774a54f9553258c3a107bd68ca3f20e1be60 Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Sun, 25 Jan 2009 15:48:35 +0000 Subject: [PATCH 04/14] Fix hostname (inverse test). svn path=/nixos/branches/fix-style/; revision=13851 --- system/system-options.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/system-options.nix b/system/system-options.nix index 97a9e05d4f5..b1688cdda80 100644 --- a/system/system-options.nix +++ b/system/system-options.nix @@ -287,7 +287,7 @@ in # Set the host name. Don't clear it if it's not configured in the # NixOS configuration, since it may have been set by dhclient in the # meantime. - ${if config.networking.hostName == "" then + ${if config.networking.hostName != "" then ''hostname "${config.networking.hostName}"'' else '' # dhclient won't do anything if the hostname isn't empty. From 67edd3720fd84816e02ba8c18cc8d8b58bfd3284 Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Sun, 25 Jan 2009 15:48:39 +0000 Subject: [PATCH 05/14] Update argument syntax of configuration files. svn path=/nixos/branches/fix-style/; revision=13852 --- upstart-jobs/disnix.nix | 2 +- upstart-jobs/fcron.nix | 2 +- upstart-jobs/zabbix-agent.nix | 2 +- upstart-jobs/zabbix-server.nix | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/upstart-jobs/disnix.nix b/upstart-jobs/disnix.nix index b87784ec067..52699c31daf 100644 --- a/upstart-jobs/disnix.nix +++ b/upstart-jobs/disnix.nix @@ -1,5 +1,5 @@ # Disnix server -{config, pkgs}: +{config, pkgs, ...}: ###### interface let diff --git a/upstart-jobs/fcron.nix b/upstart-jobs/fcron.nix index 97d259c65e1..5dd61e669d3 100644 --- a/upstart-jobs/fcron.nix +++ b/upstart-jobs/fcron.nix @@ -1,4 +1,4 @@ -{pkgs, config}: +{pkgs, config, ...}: ###### interface let diff --git a/upstart-jobs/zabbix-agent.nix b/upstart-jobs/zabbix-agent.nix index cb3895f81f1..55a71619dcc 100644 --- a/upstart-jobs/zabbix-agent.nix +++ b/upstart-jobs/zabbix-agent.nix @@ -1,5 +1,5 @@ # Zabbix agent daemon. -{config, pkgs}: +{config, pkgs, ...}: ###### interface let diff --git a/upstart-jobs/zabbix-server.nix b/upstart-jobs/zabbix-server.nix index 07a31e7d7d7..e683b31ae61 100644 --- a/upstart-jobs/zabbix-server.nix +++ b/upstart-jobs/zabbix-server.nix @@ -1,5 +1,5 @@ # Zabbix server daemon. -{config, pkgs}: +{config, pkgs, ...}: ###### interface let From 9fa758c657ff7d8995f95ae54b9c107bec4904c8 Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Sun, 25 Jan 2009 15:48:43 +0000 Subject: [PATCH 06/14] Update the function used to merge option sets. svn path=/nixos/branches/fix-style/; revision=13853 --- system/system.nix | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/system/system.nix b/system/system.nix index 75087708b83..656625846e1 100644 --- a/system/system.nix +++ b/system/system.nix @@ -11,14 +11,11 @@ rec { systemPathList ]; - noOption = name: values: - abort "${name}: Used without option declaration."; - # Make a configuration object from which we can retrieve option # values. config = pkgs.lib.fixOptionSets - (pkgs.lib.mergeOptionSets noOption) + pkgs.lib.newMergeOptionSets pkgs configComponents; optionDeclarations = From 9cdfe5a7114d383e3cc46c9b533f75ffe6116980 Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Sun, 25 Jan 2009 15:48:48 +0000 Subject: [PATCH 07/14] Extract kernel configuration from options.nix. svn path=/nixos/branches/fix-style/; revision=13854 --- system/kernel.nix | 160 +++++++++++++++++++++++++++++++++++++++++++++ system/options.nix | 139 +-------------------------------------- 2 files changed, 162 insertions(+), 137 deletions(-) create mode 100644 system/kernel.nix diff --git a/system/kernel.nix b/system/kernel.nix new file mode 100644 index 00000000000..6fd20a820f7 --- /dev/null +++ b/system/kernel.nix @@ -0,0 +1,160 @@ +{pkgs, config, ...}: + +###### interface +let + inherit (pkgs.lib) mkOption; + + options = { + boot = { + kernelPackages = mkOption { + default = pkgs.kernelPackages; + example = pkgs.kernelPackages_2_6_25; + merge = backwardPkgsFunMerge; + description = " + This option allows you to override the Linux kernel used by + NixOS. Since things like external kernel module packages are + tied to the kernel you're using, it also overrides those. + This option is a function that takes Nixpkgs as an argument + (as a convenience), and returns an attribute set containing at + the very least an attribute kernel. + Additional attributes may be needed depending on your + configuration. For instance, if you use the NVIDIA X driver, + then it also needs to contain an attribute + nvidiaDrivers. + "; + }; + + kernelParams = mkOption { + default = [ + "selinux=0" + "apm=on" + "acpi=on" + "vga=0x317" + "console=tty1" + "splash=verbose" + ]; + description = " + The kernel parameters. If you want to add additional + parameters, it's best to set + . + "; + }; + + extraKernelParams = mkOption { + default = [ + ]; + example = [ + "debugtrace" + ]; + description = " + Additional user-defined kernel parameters. + "; + }; + + extraModulePackages = mkOption { + default = []; + # !!! example = [pkgs.aufs pkgs.nvidiaDrivers]; + description = '' + A list of additional packages supplying kernel modules. + ''; + merge = backwardPkgsFunListMerge; + }; + + kernelModules = mkOption { + default = []; + description = " + The set of kernel modules to be loaded in the second stage of + the boot process. That is, these modules are not included in + the initial ramdisk, so they'd better not be required for + mounting the root file system. Add them to + if they are. + "; + }; + + initrd = { + + kernelModules = mkOption { + default = [ + # Note: most of these (especially the SATA/PATA modules) + # shouldn't be included by default since nixos-hardware-scan + # detects them, but I'm keeping them for now for backwards + # compatibility. + + # Some SATA/PATA stuff. + "ahci" + "sata_nv" + "sata_via" + "sata_sis" + "sata_uli" + "ata_piix" + "pata_marvell" + + # Standard SCSI stuff. + "sd_mod" + "sr_mod" + + # Standard IDE stuff. + "ide_cd" + "ide_disk" + "ide_generic" + + # Filesystems. + "ext3" + + # Support USB keyboards, in case the boot fails and we only have + # a USB keyboard. + "ehci_hcd" + "ohci_hcd" + "usbhid" + + # LVM. + "dm_mod" + ]; + description = " + The set of kernel modules in the initial ramdisk used during the + boot process. This set must include all modules necessary for + mounting the root device. That is, it should include modules + for the physical device (e.g., SCSI drivers) and for the file + system (e.g., ext3). The set specified here is automatically + closed under the module dependency relation, i.e., all + dependencies of the modules list here are included + automatically. If you want to add additional + modules, it's best to set + . + "; + }; + + extraKernelModules = mkOption { + default = []; + description = " + Additional kernel modules for the initial ramdisk. These are + loaded before the modules listed in + , so they take + precedence. + "; + }; + + }; + }; + }; +in + +###### implementation +let + kernelPackages = config.boot.kernelPackages; + kernel = kernelPackages.kernel; +in + +{ + require = [ + options + ]; + + system = { + # include kernel modules. + modulesTree = [ kernel ] + # this line should be removed! + ++ pkgs.lib.optional config.hardware.enableGo7007 kernelPackages.wis_go7007 + ++ config.boot.extraModulePackages; + }; +} diff --git a/system/options.nix b/system/options.nix index fbb316dc53a..3ebb06e4d49 100644 --- a/system/options.nix +++ b/system/options.nix @@ -64,51 +64,6 @@ in "; }; - kernelPackages = mkOption { - default = pkgs.kernelPackages; - example = pkgs.kernelPackages_2_6_25; - merge = backwardPkgsFunMerge; - description = " - This option allows you to override the Linux kernel used by - NixOS. Since things like external kernel module packages are - tied to the kernel you're using, it also overrides those. - This option is a function that takes Nixpkgs as an argument - (as a convenience), and returns an attribute set containing at - the very least an attribute kernel. - Additional attributes may be needed depending on your - configuration. For instance, if you use the NVIDIA X driver, - then it also needs to contain an attribute - nvidiaDrivers. - "; - }; - - kernelParams = mkOption { - default = [ - "selinux=0" - "apm=on" - "acpi=on" - "vga=0x317" - "console=tty1" - "splash=verbose" - ]; - description = " - The kernel parameters. If you want to add additional - parameters, it's best to set - . - "; - }; - - extraKernelParams = mkOption { - default = [ - ]; - example = [ - "debugtrace" - ]; - description = " - Additional user-defined kernel parameters. - "; - }; - hardwareScan = mkOption { default = true; description = " @@ -121,89 +76,8 @@ in "; }; - extraModulePackages = mkOption { - default = []; - # !!! example = [pkgs.aufs pkgs.nvidiaDrivers]; - description = '' - A list of additional packages supplying kernel modules. - ''; - merge = backwardPkgsFunListMerge; - }; - - kernelModules = mkOption { - default = []; - description = " - The set of kernel modules to be loaded in the second stage of - the boot process. That is, these modules are not included in - the initial ramdisk, so they'd better not be required for - mounting the root file system. Add them to - if they are. - "; - }; - initrd = { - kernelModules = mkOption { - default = [ - # Note: most of these (especially the SATA/PATA modules) - # shouldn't be included by default since nixos-hardware-scan - # detects them, but I'm keeping them for now for backwards - # compatibility. - - # Some SATA/PATA stuff. - "ahci" - "sata_nv" - "sata_via" - "sata_sis" - "sata_uli" - "ata_piix" - "pata_marvell" - - # Standard SCSI stuff. - "sd_mod" - "sr_mod" - - # Standard IDE stuff. - "ide_cd" - "ide_disk" - "ide_generic" - - # Filesystems. - "ext3" - - # Support USB keyboards, in case the boot fails and we only have - # a USB keyboard. - "ehci_hcd" - "ohci_hcd" - "usbhid" - - # LVM. - "dm_mod" - ]; - description = " - The set of kernel modules in the initial ramdisk used during the - boot process. This set must include all modules necessary for - mounting the root device. That is, it should include modules - for the physical device (e.g., SCSI drivers) and for the file - system (e.g., ext3). The set specified here is automatically - closed under the module dependency relation, i.e., all - dependencies of the modules list here are included - automatically. If you want to add additional - modules, it's best to set - . - "; - }; - - extraKernelModules = mkOption { - default = []; - description = " - Additional kernel modules for the initial ramdisk. These are - loaded before the modules listed in - , so they take - precedence. - "; - }; - allowMissing = mkOption { default = false; description = '' @@ -295,17 +169,7 @@ in merge = pkgs.lib.mergeListOption; # Convert the list of path to only one path. - apply = list: pkgs.aggregateModules ( - let - kernelPackages = config.boot.kernelPackages; - kernel = kernelPackages.kernel; - in - [ kernel ] - ++ pkgs.lib.optional config.hardware.enableGo7007 kernelPackages.wis_go7007 - ++ config.boot.extraModulePackages - # should only keep this one, other have to be set by the option owners. - ++ list - ); + apply = pkgs.aggregateModules; }; sbin = { @@ -2405,6 +2269,7 @@ in require = [ # boot (is it the right place ?) + (import ../system/kernel.nix) (import ../boot/boot-stage-2.nix) (import ../installer/grub.nix) From 6086aee542c2d475c65688a9e7d65cb2b2b7d71a Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Sun, 25 Jan 2009 15:48:53 +0000 Subject: [PATCH 08/14] * The Linux kernel >= 2.6.27 provides firmware, so add it to the firmware search path. (Patch from Eelco Dolstra) svn path=/nixos/branches/fix-style/; revision=13855 --- system/kernel.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/system/kernel.nix b/system/kernel.nix index 6fd20a820f7..ec5b9a63787 100644 --- a/system/kernel.nix +++ b/system/kernel.nix @@ -157,4 +157,11 @@ in ++ pkgs.lib.optional config.hardware.enableGo7007 kernelPackages.wis_go7007 ++ config.boot.extraModulePackages; }; + + services = { + udev = { + # The Linux kernel >= 2.6.27 provides firmware + addFirmware = [ "${kernel}/lib/firmware" ]; + }; + }; } From fa3437cb35967735391ca7b4bd673b44c986b56c Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Sun, 25 Jan 2009 15:48:59 +0000 Subject: [PATCH 09/14] Remove enableIntel* and enableGo7007 options. Update nixos-hardware-scan.pl to generate files without these options. svn path=/nixos/branches/fix-style/; revision=13856 --- installer/nixos-hardware-scan.pl | 38 +++++++++++++++------- system/kernel.nix | 9 ++---- system/options.nix | 54 -------------------------------- system/system.nix | 1 - upstart-jobs/default.nix | 12 ++----- 5 files changed, 32 insertions(+), 82 deletions(-) diff --git a/installer/nixos-hardware-scan.pl b/installer/nixos-hardware-scan.pl index e3277fa035d..d21e92cd51b 100644 --- a/installer/nixos-hardware-scan.pl +++ b/installer/nixos-hardware-scan.pl @@ -4,6 +4,7 @@ use File::Spec; use File::Basename; +my @requireList = (); my @kernelModules = (); my @initrdKernelModules = (); @@ -56,8 +57,6 @@ push @kernelModules, "kvm-amd" if hasCPUFeature "svm"; # modules are auto-detected so we don't need to list them here. # However, some are needed in the initrd to boot the system. -my $enableIntel2200BGFirmware = "false"; -my $enableIntel3945ABGFirmware = "false"; my $videoDriver = "vesa"; sub pciCheck { @@ -97,11 +96,13 @@ sub pciCheck { # Can't rely on $module here, since the module may not be loaded # due to missing firmware. Ideally we would check modules.pcimap # here. - $enableIntel2200BGFirmware = "true" if $vendor eq "0x8086" && + push @requireList, "(import ./configurations/hardware/network/Intel2200BG.nix)" if + $vendor eq "0x8086" && ($device eq "0x1043" || $device eq "0x104f" || $device eq "0x4220" || $device eq "0x4221" || $device eq "0x4223" || $device eq "0x4224"); - $enableIntel3945ABGFirmware = "true" if $vendor eq "0x8086" && + push @requireList, "(import ./configurations/hardware/network/Intel3945ABG.nix)" if + $vendor eq "0x8086" && ($device eq "0x4229" || $device eq "0x4230" || $device eq "0x4222" || $device eq "0x4227"); @@ -197,14 +198,26 @@ sub toNixExpr { return $res; } +sub multiLineList { + my $indent = shift; + my $res = ""; + foreach my $s (@_) { + $res .= "\n$indent $s"; + } + $res .= "\nindent"; + return $res; +} + my $initrdKernelModules = toNixExpr(removeDups @initrdKernelModules); my $kernelModules = toNixExpr(removeDups @kernelModules); - +my $requireList = multiLineList(" ", removeDups @requireList); ## This is a generated file. Do not modify! ## Make changes to /etc/nixos/configuration.nix instead. print < Date: Sun, 25 Jan 2009 15:49:08 +0000 Subject: [PATCH 10/14] Split xserver upstart job into: - xserver configuration & job - display manager (slim) - window manager (compiz, kwm, metacity, twm, wmii, xmonad) - desktop manager (kde, gnome, xterm) Added features: - Add WM choice in slim (with F1) svn path=/nixos/branches/fix-style/; revision=13857 --- system/options.nix | 2 +- .../{xserver.nix => xserver/default.nix} | 396 ++++-------------- .../xserver/desktopManager/default.nix | 76 ++++ upstart-jobs/xserver/desktopManager/gnome.nix | 47 +++ upstart-jobs/xserver/desktopManager/kde.nix | 65 +++ upstart-jobs/xserver/desktopManager/none.nix | 14 + upstart-jobs/xserver/desktopManager/xterm.nix | 44 ++ .../xserver/displayManager/default.nix | 172 ++++++++ upstart-jobs/xserver/displayManager/slim.nix | 112 +++++ upstart-jobs/xserver/windowManager/compiz.nix | 64 +++ .../xserver/windowManager/default.nix | 61 +++ upstart-jobs/xserver/windowManager/kwm.nix | 46 ++ .../xserver/windowManager/metacity.nix | 49 +++ upstart-jobs/xserver/windowManager/none.nix | 12 + upstart-jobs/xserver/windowManager/twm.nix | 44 ++ upstart-jobs/xserver/windowManager/wmii.nix | 32 ++ upstart-jobs/xserver/windowManager/xmonad.nix | 32 ++ upstart-jobs/{ => xserver}/xserver.conf | 0 18 files changed, 948 insertions(+), 320 deletions(-) rename upstart-jobs/{xserver.nix => xserver/default.nix} (60%) create mode 100644 upstart-jobs/xserver/desktopManager/default.nix create mode 100644 upstart-jobs/xserver/desktopManager/gnome.nix create mode 100644 upstart-jobs/xserver/desktopManager/kde.nix create mode 100644 upstart-jobs/xserver/desktopManager/none.nix create mode 100644 upstart-jobs/xserver/desktopManager/xterm.nix create mode 100644 upstart-jobs/xserver/displayManager/default.nix create mode 100644 upstart-jobs/xserver/displayManager/slim.nix create mode 100644 upstart-jobs/xserver/windowManager/compiz.nix create mode 100644 upstart-jobs/xserver/windowManager/default.nix create mode 100644 upstart-jobs/xserver/windowManager/kwm.nix create mode 100644 upstart-jobs/xserver/windowManager/metacity.nix create mode 100644 upstart-jobs/xserver/windowManager/none.nix create mode 100644 upstart-jobs/xserver/windowManager/twm.nix create mode 100644 upstart-jobs/xserver/windowManager/wmii.nix create mode 100644 upstart-jobs/xserver/windowManager/xmonad.nix rename upstart-jobs/{ => xserver}/xserver.conf (100%) diff --git a/system/options.nix b/system/options.nix index f23adf9e7cf..6adb1ffb226 100644 --- a/system/options.nix +++ b/system/options.nix @@ -2246,7 +2246,7 @@ in (import ../upstart-jobs/hal.nix) (import ../upstart-jobs/gpm.nix) (import ../upstart-jobs/nagios/default.nix) - (import ../upstart-jobs/xserver.nix) + (import ../upstart-jobs/xserver/default.nix) (import ../upstart-jobs/zabbix-agent.nix) (import ../upstart-jobs/zabbix-server.nix) (import ../upstart-jobs/disnix.nix) diff --git a/upstart-jobs/xserver.nix b/upstart-jobs/xserver/default.nix similarity index 60% rename from upstart-jobs/xserver.nix rename to upstart-jobs/xserver/default.nix index 9064ec15310..0a7a70c7175 100644 --- a/upstart-jobs/xserver.nix +++ b/upstart-jobs/xserver/default.nix @@ -66,6 +66,7 @@ let "; }; +/* sessionType = mkOption { default = "gnome"; example = "xterm"; @@ -91,14 +92,6 @@ let "; }; - renderingFlag = mkOption { - default = ""; - example = "--indirect-rendering"; - description = " - Possibly pass --indierct-rendering to Compiz. - "; - }; - sessionStarter = mkOption { example = "${pkgs.xterm}/bin/xterm -ls"; description = " @@ -107,6 +100,7 @@ let is empty. "; }; +*/ startSSHAgent = mkOption { default = true; @@ -118,41 +112,6 @@ let "; }; - slim = { - - theme = mkOption { - default = null; - example = pkgs.fetchurl { - url = http://download.berlios.de/slim/slim-wave.tar.gz; - sha256 = "0ndr419i5myzcylvxb89m9grl2xyq6fbnyc3lkd711mzlmnnfxdy"; - }; - description = " - The theme for the SLiM login manager. If not specified, SLiM's - default theme is used. See for a - collection of themes. - "; - }; - - defaultUser = mkOption { - default = ""; - example = "login"; - description = " - The default user to load. If you put a username here you - get it automatically loaded into the username field, and - the focus is placed on the password. - "; - }; - - hideCursor = mkOption { - default = false; - example = true; - description = " - Hide the mouse cursor on the login screen. - "; - }; - }; - isClone = mkOption { default = true; example = false; @@ -327,7 +286,6 @@ let # Abbreviations. cfg = config.services.xserver; xorg = cfg.package; - gnome = pkgs.gnome; stdenv = pkgs.stdenv; knownVideoDrivers = { @@ -344,25 +302,9 @@ let # Get a bunch of user settings. videoDriver = cfg.videoDriver; resolutions = map (res: ''"${toString res.x}x${toString res.y}"'') (cfg.resolutions); - sessionType = cfg.sessionType; videoDriverModules = getAttr [ videoDriver ] (throw "unkown video driver : \"${videoDriver}\"") knownVideoDrivers; - sessionCmd = - if sessionType == "" then cfg.sessionStarter else - if sessionType == "xterm" then "${pkgs.xterm}/bin/xterm -ls" else - if sessionType == "gnome" then "${gnome.gnometerminal}/bin/gnome-terminal -ls" else - abort ("unknown session type ${sessionType}"); - - - windowManager = - let wm = cfg.windowManager; in - if wm != "" then wm else - if sessionType == "gnome" then "metacity" else - if sessionType == "kde" then "none" /* started by startkde */ else - "twm"; - - modules = getAttr ["modulesFirst"] [] videoDriverModules @@ -518,244 +460,7 @@ let }; - clientScript = pkgs.writeText "xclient" '' - - source /etc/profile - - exec > $HOME/.Xerrors 2>&1 - - - ### Load X defaults. - if test -e ~/.Xdefaults; then - ${xorg.xrdb}/bin/xrdb -merge ~/.Xdefaults - fi - - - ${if cfg.startSSHAgent then '' - ### Start the SSH agent. - export SSH_ASKPASS=${pkgs.x11_ssh_askpass}/libexec/x11-ssh-askpass - eval $(${pkgs.openssh}/bin/ssh-agent) - '' else ""} - - ### Allow user to override system-wide configuration - if test -f ~/.xsession; then - source ~/.xsession; - fi - - - ### Start a window manager. - - ${if windowManager == "twm" then '' - ${xorg.twm}/bin/twm & - '' - - else if windowManager == "metacity" then '' - env LD_LIBRARY_PATH=${xorg.libX11}/lib:${xorg.libXext}/lib:/usr/lib/ - # !!! Hack: load the schemas for Metacity. - GCONF_CONFIG_SOURCE=xml::~/.gconf ${gnome.GConf}/bin/gconftool-2 \ - --makefile-install-rule ${gnome.metacity}/etc/gconf/schemas/*.schemas # */ - ${gnome.metacity}/bin/metacity & - '' - - else if windowManager == "kwm" then '' - ${pkgs.kdebase}/bin/kwin & - '' - - else if windowManager == "compiz" then '' - # !!! Hack: load the schemas for Compiz. - GCONF_CONFIG_SOURCE=xml::~/.gconf ${gnome.GConf}/bin/gconftool-2 \ - --makefile-install-rule ${pkgs.compiz}/etc/gconf/schemas/*.schemas # */ - - # !!! Hack: turn on most Compiz modules. - ${gnome.GConf}/bin/gconftool-2 -t list --list-type=string \ - --set /apps/compiz/general/allscreens/options/active_plugins \ - [gconf,png,decoration,wobbly,fade,minimize,move,resize,cube,switcher,rotate,place,scale,water] - - # Start Compiz and the GTK-style window decorator. - env LD_LIBRARY_PATH=${xorg.libX11}/lib:${xorg.libXext}/lib:/usr/lib/ - ${pkgs.compiz}/bin/compiz gconf ${cfg.renderingFlag} & - ${pkgs.compiz}/bin/gtk-window-decorator --sync & - '' - - else if windowManager == "xmonad" then '' - ${pkgs.xmonad}/bin/xmonad & - '' - - else if windowManager == "wmii" then '' - ${pkgs.wmiiSnap}/bin/wmii & - '' - - else if windowManager == "none" then '' - # The session starter will start the window manager. - '' - - else abort ("unknown window manager " + windowManager)} - WMpid=$! - - ### Show a background image. - # (but not if we're starting a full desktop environment that does it for us) - ${if sessionType != "kde" then '' - - if test -e $HOME/.background-image; then - ${pkgs.feh}/bin/feh --bg-scale $HOME/.background-image - fi - - '' else ""} - - - ### Start the session. - ${if sessionType == "kde" then '' - - # Start KDE. - export KDEDIRS=$HOME/.nix-profile:/nix/var/nix/profiles/default:${pkgs.kdebase}:${pkgs.kdelibs} - export XDG_CONFIG_DIRS=${pkgs.kdebase}/etc/xdg:${pkgs.kdelibs}/etc/xdg - export XDG_DATA_DIRS=${pkgs.kdebase}/share - exec ${pkgs.kdebase}/bin/startkde - - '' else '' - - # For all other session types, we currently just start a - # terminal of the kind indicated by sessionCmd. - # !!! yes, this means that you 'log out' by killing the X server. - while ${sessionCmd}; do - sleep 1 - done - - ''} - - ''; - - - xserverArgs = [ - "-ac" - "-logverbose" - "-verbose" - "-terminate" - "-logfile" "/var/log/X.${toString cfg.display}.log" - "-config ${configFile}" - ":${toString cfg.display}" "vt${toString cfg.tty}" - "-xkbdir" "${pkgs.xkeyboard_config}/etc/X11/xkb" - ] ++ optional (!config.services.xserver.tcpEnable) "-nolisten tcp"; - - - slimConfig = pkgs.writeText "slim.cfg" '' - xauth_path ${xorg.xauth}/bin/xauth - default_xserver ${xorg.xorgserver}/bin/X - xserver_arguments ${toString xserverArgs} - login_cmd exec ${stdenv.bash}/bin/sh ${clientScript} - halt_cmd ${pkgs.upstart}/sbin/shutdown -h now - reboot_cmd ${pkgs.upstart}/sbin/shutdown -r now - ${if cfg.slim.defaultUser != "" then "default_user " + cfg.slim.defaultUser else ""} - ${if cfg.slim.hideCursor then "hidecursor true" else ""} - ''; - - - # Unpack the SLiM theme, or use the default. - slimThemesDir = - let - unpackedTheme = stdenv.mkDerivation { - name = "slim-theme"; - buildCommand = '' - ensureDir $out - cd $out - unpackFile ${cfg.slim.theme} - ln -s * default - ''; - }; - in if cfg.slim.theme == null then "${pkgs.slim}/share/slim/themes" else unpackedTheme; - - nvidiaDrivers = (config.boot.kernelPackages pkgs).nvidiaDrivers; - - oldJob = rec { - # Warning the indentation is wrong since here in order to don't produce noise in diffs. - - name = "xserver"; - - - extraPath = [ - xorg.xrandr - xorg.xrdb - xorg.setxkbmap - xorg.iceauth # required for KDE applications (it's called by dcopserver) - pkgs.feh - ] - ++ optional (windowManager == "twm") [ - xorg.twm - ] - ++ optional (windowManager == "metacity") [ - gnome.metacity - ] - ++ optional (windowManager == "compiz") [ - pkgs.compiz - ] - ++ optional (sessionType == "xterm") [ - pkgs.xterm - ] - ++ optional (sessionType == "gnome") [ - gnome.gnometerminal - gnome.GConf - gnome.gconfeditor - ] - ++ optional (sessionType == "kde") [ - pkgs.kdelibs - pkgs.kdebase - xorg.xset # used by startkde, non-essential - ] - ++ optional (videoDriver == "nvidia") [ - kernelPackages.nvidiaDrivers - ]; - - - extraEtc = - optional (sessionType == "kde") - { source = "${pkgs.xkeyboard_config}/etc/X11/xkb"; - target = "X11/xkb"; - } - ++ - optional cfg.exportConfiguration - { source = "${configFile}"; - target = "X11/xorg.conf"; - }; - - - job = '' - start on ${if cfg.autorun then "network-interfaces" else "never"} - - start script - - rm -f /var/run/opengl-driver - ${if videoDriver == "nvidia" - then '' - ln -sf ${kernelPackages.nvidiaDrivers} /var/run/opengl-driver - '' - else if cfg.driSupport - then "ln -sf ${pkgs.mesa} /var/run/opengl-driver" - else "" - } - - rm -f /var/log/slim.log - - end script - - env SLIM_CFGFILE=${slimConfig} - env SLIM_THEMESDIR=${slimThemesDir} - env FONTCONFIG_FILE=/etc/fonts/fonts.conf # !!! cleanup - env XKB_BINDIR=${xorg.xkbcomp}/bin # Needed for the Xkb extension. - - ${if videoDriver == "nvidia" - then "env LD_LIBRARY_PATH=${xorg.libX11}/lib:${xorg.libXext}/lib:${kernelPackages.nvidiaDrivers}/lib" - else "" - } - - ${if videoDriver != "nvidia" - then "env XORG_DRI_DRIVER_PATH=${pkgs.mesa}/lib/modules/dri" - else "" - } - - exec ${pkgs.slim}/bin/slim - ''; - -}; + nvidiaDrivers = (config.boot.kernelPackages pkgs).nvidiaDrivers; in @@ -763,14 +468,19 @@ mkIf cfg.enable { require = [ options + # services.xserver.*Manager + (import ./displayManager/default.nix) + (import ./windowManager/default.nix) + (import ./desktopManager/default.nix) + # services.extraJobs - (import ../upstart-jobs/default.nix) + (import ../../upstart-jobs/default.nix) # environment.etc - (import ../etc/default.nix) + (import ../../etc/default.nix) # fonts.fonts - (import ../system/fonts.nix) + (import ../../system/fonts.nix) # boot.extraModulePackages # security.extraSetuidPrograms @@ -783,29 +493,77 @@ mkIf cfg.enable { ]; }; - security = { - extraSetuidPrograms = mkIf (cfg.sessionType == "kde") [ - "kcheckpass" + environment = { + etc = mkIf cfg.exportConfiguration [ + { source = "${configFile}"; + target = "X11/xorg.conf"; + } + ]; + + extraPackages = [ + xorg.xrandr + xorg.xrdb + xorg.setxkbmap + xorg.iceauth # required for KDE applications (it's called by dcopserver) + ] + ++ optional (videoDriver == "nvidia") [ + kernelPackages.nvidiaDrivers ]; }; - environment = { - etc = [ - { source = ../etc/pam.d/kde; - target = "pam.d/kde"; - } - { source = ../etc/pam.d/slim; - target = "pam.d/slim"; - } - ] ++ oldJob.extraEtc; - - extraPackages = - oldJob.extraPath; - }; - services = { + xserver = { + displayManager = { + xserverArgs = [ + "-ac" + "-logverbose" + "-verbose" + "-terminate" + "-logfile" "/var/log/X.${toString cfg.display}.log" + "-config ${configFile}" + ":${toString cfg.display}" "vt${toString cfg.tty}" + "-xkbdir" "${pkgs.xkeyboard_config}/etc/X11/xkb" + ] ++ optional (!cfg.tcpEnable) "-nolisten tcp"; + }; + }; + extraJobs = [{ - inherit (oldJob) name job; + name = "xserver"; + job = '' + start on ${if cfg.autorun then "network-interfaces" else "never"} + + start script + + rm -f /var/run/opengl-driver + ${if videoDriver == "nvidia" + then '' + ln -sf ${kernelPackages.nvidiaDrivers} /var/run/opengl-driver + '' + else if cfg.driSupport + then "ln -sf ${pkgs.mesa} /var/run/opengl-driver" + else "" + } + + ${cfg.displayManager.job.beforeScript} + + end script + + ${cfg.displayManager.job.env} + env FONTCONFIG_FILE=/etc/fonts/fonts.conf # !!! cleanup + env XKB_BINDIR=${xorg.xkbcomp}/bin # Needed for the Xkb extension. + + ${if videoDriver == "nvidia" + then "env LD_LIBRARY_PATH=${xorg.libX11}/lib:${xorg.libXext}/lib:${kernelPackages.nvidiaDrivers}/lib" + else "" + } + + ${if videoDriver != "nvidia" + then "env XORG_DRI_DRIVER_PATH=${pkgs.mesa}/lib/modules/dri" + else "" + } + + exec ${cfg.displayManager.job.execCmd} + ''; }]; }; } diff --git a/upstart-jobs/xserver/desktopManager/default.nix b/upstart-jobs/xserver/desktopManager/default.nix new file mode 100644 index 00000000000..73b0308bea2 --- /dev/null +++ b/upstart-jobs/xserver/desktopManager/default.nix @@ -0,0 +1,76 @@ +{pkgs, config, ...}: + +let + inherit (builtins) head tail; + inherit (pkgs.lib) mkOption mkIf filter optionalString any; + cfg = config.services.xserver.desktopManager; + + needBGCond = d: ! (d ? bgSupport && d.bgSupport); +in + +{ + require = [ + (import ./kde.nix) + (import ./gnome.nix) + (import ./xterm.nix) + (import ./none.nix) + ]; + + services = { + xserver = { + displayManager = { + session = cfg.session.list; + }; + + desktopManager = { + session = mkOption { + default = []; + example = [{ + name = "kde"; + bgSupport = true; + start = "..."; + }]; + description = " + Internal option used to add some common line to desktop manager + scripts before forwarding the value to the + displayManager. + "; + apply = list: { + list = map (d: d // { + manage = "desktop"; + start = d.start + + optionalString (needBGCond d) '' + if test -e $HOME/.background-image; then + ${pkgs.feh}/bin/feh --bg-scale $HOME/.background-image + fi + ''; + }) list; + needBGPackages = [] != filter needBGCond list; + }; + }; + + + + default = mkOption { + default = "xterm"; + example = "none"; + description = " + Default desktop manager loaded if none have been chosen. + "; + merge = name: list: + let defaultDM = head list; in + if tail list != [] then + throw "Only one default desktop manager is allowed." + else if any (w: w.name == defaultDM) cfg.session.list then + defaultDM + else + throw "Default desktop manager not found."; + }; + }; + }; + }; + + environment = mkIf cfg.session.needBGPackages { + extraPackages = [ pkgs.feh ]; + }; +} diff --git a/upstart-jobs/xserver/desktopManager/gnome.nix b/upstart-jobs/xserver/desktopManager/gnome.nix new file mode 100644 index 00000000000..d6fa064ef11 --- /dev/null +++ b/upstart-jobs/xserver/desktopManager/gnome.nix @@ -0,0 +1,47 @@ +{pkgs, config, ...}: + +let + inherit (pkgs.lib) mkOption mkIf; + cfg = config.services.xserver.desktopManager.gnome; + gnome = pkgs.gnome; + + options = { services = { xserver = { desktopManager = { + + gnome = { + enable = mkOption { + default = false; + example = true; + description = "Enable a gnome terminal as a desktop manager."; + }; + }; + + }; }; }; }; +in + +mkIf cfg.enable { + require = options; + + services = { + xserver = { + + desktopManager = { + session = [{ + name = "gnome"; + start = '' + ${gnome.gnometerminal}/bin/gnome-terminal -ls & + waitPID=$! + ''; + }]; + }; + + }; + }; + + environment = { + extraPackages = [ + gnome.gnometerminal + gnome.GConf + gnome.gconfeditor + ]; + }; +} diff --git a/upstart-jobs/xserver/desktopManager/kde.nix b/upstart-jobs/xserver/desktopManager/kde.nix new file mode 100644 index 00000000000..9a241d77985 --- /dev/null +++ b/upstart-jobs/xserver/desktopManager/kde.nix @@ -0,0 +1,65 @@ +{pkgs, config, ...}: + +let + inherit (pkgs.lib) mkOption mkIf; + cfg = config.services.xserver.desktopManager.kde; + xorg = config.services.xserver.package; + + options = { services = { xserver = { desktopManager = { + + kde = { + enable = mkOption { + default = false; + example = true; + description = "Enable the kde desktop manager."; + }; + }; + + }; }; }; }; +in + +mkIf cfg.enable { + require = options; + + services = { + xserver = { + + desktopManager = { + session = [{ + name = "kde"; + start = '' + # Start KDE. + export KDEDIRS=$HOME/.nix-profile:/nix/var/nix/profiles/default:${pkgs.kdebase}:${pkgs.kdelibs} + export XDG_CONFIG_DIRS=${pkgs.kdebase}/etc/xdg:${pkgs.kdelibs}/etc/xdg + export XDG_DATA_DIRS=${pkgs.kdebase}/share + exec ${pkgs.kdebase}/bin/startkde + ''; + }]; + }; + + }; + }; + + security = { + extraSetuidPrograms = [ + "kcheckpass" + ]; + }; + + environment = { + extraPackages = [ + pkgs.kdelibs + pkgs.kdebase + xorg.xset # used by startkde, non-essential + ]; + + etc = [ + { source = ../../../etc/pam.d/kde; + target = "pam.d/kde"; + } + { source = "${pkgs.xkeyboard_config}/etc/X11/xkb"; + target = "X11/xkb"; + } + ]; + }; +} diff --git a/upstart-jobs/xserver/desktopManager/none.nix b/upstart-jobs/xserver/desktopManager/none.nix new file mode 100644 index 00000000000..a86bd5a7415 --- /dev/null +++ b/upstart-jobs/xserver/desktopManager/none.nix @@ -0,0 +1,14 @@ +{ + services = { + xserver = { + + desktopManager = { + session = [{ + name = "none"; + start = ""; + }]; + }; + + }; + }; +} diff --git a/upstart-jobs/xserver/desktopManager/xterm.nix b/upstart-jobs/xserver/desktopManager/xterm.nix new file mode 100644 index 00000000000..e8aa0d289cb --- /dev/null +++ b/upstart-jobs/xserver/desktopManager/xterm.nix @@ -0,0 +1,44 @@ +{pkgs, config, ...}: + +let + inherit (pkgs.lib) mkOption mkIf; + cfg = config.services.xserver.desktopManager.xterm; + + options = { services = { xserver = { desktopManager = { + + xterm = { + enable = mkOption { + default = false; + example = true; + description = "Enable a xterm terminal as a desktop manager."; + }; + }; + + }; }; }; }; +in + +mkIf cfg.enable { + require = options; + + services = { + xserver = { + + desktopManager = { + session = [{ + name = "xterm"; + start = '' + ${pkgs.xterm}/bin/xterm -ls & + waitPID=$! + ''; + }]; + }; + + }; + }; + + environment = { + extraPackages = [ + pkgs.xterm + ]; + }; +} diff --git a/upstart-jobs/xserver/displayManager/default.nix b/upstart-jobs/xserver/displayManager/default.nix new file mode 100644 index 00000000000..2699e34ecad --- /dev/null +++ b/upstart-jobs/xserver/displayManager/default.nix @@ -0,0 +1,172 @@ +{pkgs, config, ...}: + +let + inherit (builtins) head tail; + inherit (pkgs.lib) mkOption optionals filter concatMap concatMapStrings; + cfg = config.services.xserver; + xorg = cfg.package; + + # file provided by services.xserver.displayManager.session.script + xsession = wm: dm: pkgs.writeText "xsession" '' + + source /etc/profile + + exec > $HOME/.Xerrors 2>&1 + + + ### Load X defaults. + if test -e ~/.Xdefaults; then + ${xorg.xrdb}/bin/xrdb -merge ~/.Xdefaults + fi + + ${if cfg.startSSHAgent then '' + ### Start the SSH agent. + export SSH_ASKPASS=${pkgs.x11_ssh_askpass}/libexec/x11-ssh-askpass + eval $(${pkgs.openssh}/bin/ssh-agent) + '' else ""} + + ### Allow user to override system-wide configuration + if test -f ~/.xsession; then + source ~/.xsession; + fi + + # this script expect to have as first argument the following input + # "desktop-manager + window-manager". + arg="$1" + + # extract the window manager. + windowManager="''${arg##* + }" + : ''${windowManager:=${cfg.windowManager.default}} + # extract the desktop manager. + desktopManager="''${arg% + *}" + : ''${desktopManager:=${cfg.desktopManager.default}} + + # used to restart the xserver. + waitPID=0 + + # handle window manager starts. + case $windowManager in + ${concatMapStrings (s: " + (${s.name}) + ${s.start} + ;; + ") wm} + (*) echo "$0: Window manager '$windowManager' not found.";; + esac + + # handle desktop manager starts. + case $desktopManager in + ${concatMapStrings (s: " + (${s.name}) + ${s.start} + ;; + ") dm} + (*) echo "$0: Desktop manager '$desktopManager' not found.";; + esac + + test "$waitPID" != 0 && wait "$waitPID" + exit + ''; + +in + +{ + # list of display managers. + require = [ + (import ./slim.nix) + ]; + + services = { + xserver = { + displayManager = { + + xauthBin = mkOption { + default = "${xorg.xauth}/bin/xauth"; + description = " + Path to the xauth binary used by display managers. + "; + }; + + xserverBin = mkOption { + default = "${xorg.xorgserver}/bin/X"; + description = " + Path to the xserver binary used by display managers. + "; + }; + + xserverArgs = mkOption { + default = []; + example = [ + "-ac" + "-logverbose" + "-nolisten tcp" + ]; + description = " + List of arguments which have to be pass to when + the display manager start the xserver. + "; + apply = toString; + }; + + session = mkOption { + default = []; + example = [ + { + manage = "desktop"; + name = "xterm"; + start = " + ${pkgs.xterm}/bin/xterm -ls & + waitPID=$! + "; + } + ]; + description = '' + List of session supported with the command used to start each + session. Each session script can set the + waitPID shell variable to make this script + waiting until the end of the user session. Each script is used + to define either a windows manager or a desktop manager. These + can be differentiated by setting the attribute + manage either to "window" + or "desktop". + + The list of desktop manager and window manager should appear + inside the display manager with the desktop manager name + followed by the window manager name. + ''; + apply = list: rec { + wm = filter (s: s.manage == "window") list; + dm = filter (s: s.manage == "desktop") list; + names = concatMap (d: map (w: d.name + " + " + w.name) wm) dm; + script = xsession wm dm; + }; + }; + + job = mkOption { + default = {}; + example = { + beforeScript = '' + rm -f /var/log/slim.log + ''; + env = '' + env SLIM_CFGFILE=/etc/slim.conf + ''; + execCmd = "${pkgs.slim}/bin/slim"; + }; + + description = " + List of arguments which have to be pass to when + the display manager start the xserver. + "; + + merge = name: list: + if tail list != [] then + throw "only one display manager is allowed." + else + head list; + }; + + }; + }; + }; +} diff --git a/upstart-jobs/xserver/displayManager/slim.nix b/upstart-jobs/xserver/displayManager/slim.nix new file mode 100644 index 00000000000..8363a7a14ee --- /dev/null +++ b/upstart-jobs/xserver/displayManager/slim.nix @@ -0,0 +1,112 @@ +{pkgs, config, ...}: + +###### interface +let + inherit (pkgs.lib) mkOption; + + options = { services = { xserver = { + + slim = { + + theme = mkOption { + default = null; + example = pkgs.fetchurl { + url = http://download.berlios.de/slim/slim-wave.tar.gz; + sha256 = "0ndr419i5myzcylvxb89m9grl2xyq6fbnyc3lkd711mzlmnnfxdy"; + }; + description = " + The theme for the SLiM login manager. If not specified, SLiM's + default theme is used. See for a + collection of themes. + "; + }; + + defaultUser = mkOption { + default = ""; + example = "login"; + description = " + The default user to load. If you put a username here you + get it automatically loaded into the username field, and + the focus is placed on the password. + "; + }; + + hideCursor = mkOption { + default = false; + example = true; + description = " + Hide the mouse cursor on the login screen. + "; + }; + }; + + }; /* xserver */ }; /* services */ }; + +in + +###### implementation +let + xcfg = config.services.xserver; + dmcfg = xcfg.displayManager; + cfg = xcfg.slim; + + slimConfig = pkgs.writeText "slim.cfg" '' + xauth_path ${dmcfg.xauthBin} + default_xserver ${dmcfg.xserverBin} + xserver_arguments ${dmcfg.xserverArgs} + sessions ${pkgs.lib.concatStringsSep "," dmcfg.session.names} + login_cmd exec ${pkgs.stdenv.bash}/bin/sh ${dmcfg.session.script} "%session" + halt_cmd ${pkgs.upstart}/sbin/shutdown -h now + reboot_cmd ${pkgs.upstart}/sbin/shutdown -r now + ${if cfg.defaultUser != "" then "default_user " + cfg.defaultUser else ""} + ${if cfg.hideCursor then "hidecursor true" else ""} + ''; + + + # Unpack the SLiM theme, or use the default. + slimThemesDir = + let + unpackedTheme = pkgs.stdenv.mkDerivation { + name = "slim-theme"; + buildCommand = '' + ensureDir $out + cd $out + unpackFile ${cfg.theme} + ln -s * default + ''; + }; + in if cfg.theme == null then "${pkgs.slim}/share/slim/themes" else unpackedTheme; + +in + +{ + require = [ + options + ]; + + services = { + xserver = { + displayManager = { + job = { + beforeScript = '' + rm -f /var/log/slim.log + ''; + env = '' + env SLIM_CFGFILE=${slimConfig} + env SLIM_THEMESDIR=${slimThemesDir} + ''; + execCmd = "${pkgs.slim}/bin/slim"; + }; + }; + }; + }; + + environment = { + etc = [ + { source = ../../../etc/pam.d/slim; + target = "pam.d/slim"; + } + ]; + }; +} diff --git a/upstart-jobs/xserver/windowManager/compiz.nix b/upstart-jobs/xserver/windowManager/compiz.nix new file mode 100644 index 00000000000..e99c3adb5b4 --- /dev/null +++ b/upstart-jobs/xserver/windowManager/compiz.nix @@ -0,0 +1,64 @@ +{pkgs, config, ...}: + +let + inherit (pkgs.lib) mkOption mkIf; + cfg = config.services.xserver.windowManager.compiz; + xorg = config.services.xserver.package; + gnome = pkgs.gnome; + + options = { services = { xserver = { windowManager = { + + compiz = { + enable = mkOption { + default = false; + example = true; + description = "Enable the compiz window manager."; + }; + + + renderingFlag = mkOption { + default = ""; + example = "--indirect-rendering"; + description = " + Possibly pass --indierct-rendering to Compiz. + "; + }; + }; + + }; }; }; }; +in + +mkIf cfg.enable { + require = options; + + services = { + xserver = { + + windowManager = { + session = [{ + name = "compiz"; + start = '' + # !!! Hack: load the schemas for Compiz. + GCONF_CONFIG_SOURCE=xml::~/.gconf ${gnome.GConf}/bin/gconftool-2 \ + --makefile-install-rule ${pkgs.compiz}/etc/gconf/schemas/*.schemas # */ + + # !!! Hack: turn on most Compiz modules. + ${gnome.GConf}/bin/gconftool-2 -t list --list-type=string \ + --set /apps/compiz/general/allscreens/options/active_plugins \ + [gconf,png,decoration,wobbly,fade,minimize,move,resize,cube,switcher,rotate,place,scale,water] + + # Start Compiz and the GTK-style window decorator. + env LD_LIBRARY_PATH=${xorg.libX11}/lib:${xorg.libXext}/lib:/usr/lib/ + ${pkgs.compiz}/bin/compiz gconf ${cfg.renderingFlag} & + ${pkgs.compiz}/bin/gtk-window-decorator --sync & + ''; + }]; + }; + + }; + }; + + environment = { + extraPackages = [ pkgs.compiz ]; + }; +} diff --git a/upstart-jobs/xserver/windowManager/default.nix b/upstart-jobs/xserver/windowManager/default.nix new file mode 100644 index 00000000000..41c3ad15983 --- /dev/null +++ b/upstart-jobs/xserver/windowManager/default.nix @@ -0,0 +1,61 @@ +{pkgs, config, ...}: + +let + inherit (builtins) head tail; + inherit (pkgs.lib) mkOption any; + cfg = config.services.xserver.windowManager; +in + +{ + require = [ + (import ./compiz.nix) + (import ./kwm.nix) + (import ./metacity.nix) + (import ./none.nix) + (import ./twm.nix) + (import ./wmii.nix) + (import ./xmonad.nix) + ]; + + services = { + xserver = { + displayManager = { + session = cfg.session; + }; + + windowManager = { + session = mkOption { + default = []; + example = [{ + name = "wmii"; + start = "..."; + }]; + description = " + Internal option used to add some common line to window manager + scripts before forwarding the value to the + displayManager. + "; + apply = map (d: d // { + manage = "window"; + }); + }; + + default = mkOption { + default = "none"; + example = "wmii"; + description = " + Default window manager loaded if none have been chosen. + "; + merge = name: list: + let defaultWM = head list; in + if tail list != [] then + throw "Only one default window manager is allowed." + else if any (w: w.name == defaultWM) cfg.session then + defaultWM + else + throw "Default window manager not found."; + }; + }; + }; + }; +} diff --git a/upstart-jobs/xserver/windowManager/kwm.nix b/upstart-jobs/xserver/windowManager/kwm.nix new file mode 100644 index 00000000000..db8696c510d --- /dev/null +++ b/upstart-jobs/xserver/windowManager/kwm.nix @@ -0,0 +1,46 @@ +{pkgs, config, ...}: + +let + inherit (pkgs.lib) mkOption mkIf; + cfg = config.services.xserver.windowManager.kwm; + + option = { services = { xserver = { windowManager = { + + kwm = { + enable = mkOption { + default = false; + example = true; + description = "Enable the kwm window manager."; + }; + + }; + + }; }; }; }; +in + +mkIf cfg.enable { + require = option; + + services = { + xserver = { + + windowManager = { + session = [{ + name = "kwm"; + start = " + ${pkgs.kdebase}/bin/kwin & + waitPID=$! + "; + }]; + }; + + }; + }; + + environment = { + extraPackages = [ + pkgs.kdelibs + pkgs.kdebase + ]; + }; +} diff --git a/upstart-jobs/xserver/windowManager/metacity.nix b/upstart-jobs/xserver/windowManager/metacity.nix new file mode 100644 index 00000000000..dc1ff911d65 --- /dev/null +++ b/upstart-jobs/xserver/windowManager/metacity.nix @@ -0,0 +1,49 @@ +{pkgs, config, ...}: + +let + inherit (pkgs.lib) mkOption mkIf; + cfg = config.services.xserver.windowManager.metacity; + xorg = config.services.xserver.package; + gnome = pkgs.gnome; + + option = { services = { xserver = { windowManager = { + + metacity = { + enable = mkOption { + default = false; + example = true; + description = "Enable the metacity window manager."; + }; + + }; + + }; }; }; }; +in + +mkIf cfg.enable { + require = option; + + services = { + xserver = { + + windowManager = { + session = [{ + name = "metacity"; + start = '' + env LD_LIBRARY_PATH=${xorg.libX11}/lib:${xorg.libXext}/lib:/usr/lib/ + # !!! Hack: load the schemas for Metacity. + GCONF_CONFIG_SOURCE=xml::~/.gconf ${gnome.GConf}/bin/gconftool-2 \ + --makefile-install-rule ${gnome.metacity}/etc/gconf/schemas/*.schemas # */ + ${gnome.metacity}/bin/metacity & + waitPID=$! + ''; + }]; + }; + + }; + }; + + environment = { + extraPackages = [ gnome.metacity ]; + }; +} diff --git a/upstart-jobs/xserver/windowManager/none.nix b/upstart-jobs/xserver/windowManager/none.nix new file mode 100644 index 00000000000..84cf1d77077 --- /dev/null +++ b/upstart-jobs/xserver/windowManager/none.nix @@ -0,0 +1,12 @@ +{ + services = { + xserver = { + windowManager = { + session = [{ + name = "none"; + start = ""; + }]; + }; + }; + }; +} diff --git a/upstart-jobs/xserver/windowManager/twm.nix b/upstart-jobs/xserver/windowManager/twm.nix new file mode 100644 index 00000000000..f26be48776c --- /dev/null +++ b/upstart-jobs/xserver/windowManager/twm.nix @@ -0,0 +1,44 @@ +{pkgs, config, ...}: + +let + inherit (pkgs.lib) mkOption mkIf; + cfg = config.services.xserver.windowManager.twm; + xorg = config.services.xserver.package; + + option = { services = { xserver = { windowManager = { + + twm = { + enable = mkOption { + default = false; + example = true; + description = "Enable the twm window manager."; + }; + + }; + + }; }; }; }; +in + +mkIf cfg.enable { + require = option; + + services = { + xserver = { + + windowManager = { + session = [{ + name = "twm"; + start = " + ${xorg.twm}/bin/twm & + waitPID=$! + "; + }]; + }; + + }; + }; + + environment = { + extraPackages = [ xorg.twm ]; + }; +} diff --git a/upstart-jobs/xserver/windowManager/wmii.nix b/upstart-jobs/xserver/windowManager/wmii.nix new file mode 100644 index 00000000000..59a88f9352f --- /dev/null +++ b/upstart-jobs/xserver/windowManager/wmii.nix @@ -0,0 +1,32 @@ +{pkgs, config, ...}: + +let + inherit (pkgs.lib) mkOption mkIf; + cfg = config.services.xserver.windowManager.wmii; +in + +{ + services = { + xserver = { + + windowManager = { + wmii = { + enable = mkOption { + default = false; + example = true; + description = "Enable the wmii window manager."; + }; + }; + + session = mkIf cfg.enable [{ + name = "wmii"; + start = " + ${pkgs.wmiiSnap}/bin/wmii & + waitPID=$! + "; + }]; + }; + + }; + }; +} diff --git a/upstart-jobs/xserver/windowManager/xmonad.nix b/upstart-jobs/xserver/windowManager/xmonad.nix new file mode 100644 index 00000000000..6f73ad9edc3 --- /dev/null +++ b/upstart-jobs/xserver/windowManager/xmonad.nix @@ -0,0 +1,32 @@ +{pkgs, config, ...}: + +let + inherit (pkgs.lib) mkOption mkIf; + cfg = config.services.xserver.windowManager.xmonad; +in + +{ + services = { + xserver = { + + windowManager = { + xmonad = { + enable = mkOption { + default = false; + example = true; + description = "Enable the xmonad window manager."; + }; + }; + + session = mkIf cfg.enable [{ + name = "xmonad"; + start = " + ${pkgs.xmonad}/bin/xmonad & + waitPID=$! + "; + }]; + }; + + }; + }; +} diff --git a/upstart-jobs/xserver.conf b/upstart-jobs/xserver/xserver.conf similarity index 100% rename from upstart-jobs/xserver.conf rename to upstart-jobs/xserver/xserver.conf From 639be32a8af469492e52d3a0bf44913ca4d03e64 Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Sun, 25 Jan 2009 15:49:12 +0000 Subject: [PATCH 11/14] Remove obsolete notation. (backwardPkgsFun*) svn path=/nixos/branches/fix-style/; revision=13858 --- system/options.nix | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/system/options.nix b/system/options.nix index 6adb1ffb226..7c4b5def367 100644 --- a/system/options.nix +++ b/system/options.nix @@ -1,33 +1,7 @@ {pkgs, config, ...}: let - inherit (pkgs.lib) mkOption; - inherit (builtins) head tail; - - obsolete = what: f: name: - if builtins ? trace then - builtins.trace "${name}: Obsolete ${what}." f name - else f name; - - obsoleteMerge = - obsolete "option" pkgs.lib.mergeDefaultOption; - - # temporary modifications. - # backward here means that expression could either be a value or a - # function which expects to have a pkgs argument. - optionalPkgs = name: x: - if builtins.isFunction x - then obsolete "notation" (name: x pkgs) name - else x; - - backwardPkgsFunListMerge = name: list: - pkgs.lib.concatMap (optionalPkgs name) list; - - backwardPkgsFunMerge = name: list: - if list != [] && tail list == [] - then optionalPkgs name (head list) - else abort "${name}: Defined at least twice."; - + inherit (pkgs.lib) mkOption mergeOneOption; in { @@ -2156,7 +2130,6 @@ in extraPackages = mkOption { default = []; example = [pkgs.firefox pkgs.thunderbird]; - merge = backwardPkgsFunListMerge; description = " This option allows you to add additional packages to the system path. These packages are automatically available to all users, @@ -2173,7 +2146,7 @@ in nix = mkOption { default = pkgs.nixUnstable; example = pkgs.nixCustomFun /root/nix.tar.gz; - merge = backwardPkgsFunMerge; + merge = mergeOneOption; description = " Use non-default Nix easily. Be careful, though, not to break everything. "; From dcc981840e448b5a5ccbe5b7eb3d03170e595070 Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Sun, 25 Jan 2009 15:49:18 +0000 Subject: [PATCH 12/14] Use the mergeOneOption function instead of duplicated code. svn path=/nixos/branches/fix-style/; revision=13859 --- upstart-jobs/xserver/desktopManager/default.nix | 9 +++------ upstart-jobs/xserver/displayManager/default.nix | 9 ++------- upstart-jobs/xserver/windowManager/default.nix | 9 +++------ 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/upstart-jobs/xserver/desktopManager/default.nix b/upstart-jobs/xserver/desktopManager/default.nix index 73b0308bea2..05f82dd3e6c 100644 --- a/upstart-jobs/xserver/desktopManager/default.nix +++ b/upstart-jobs/xserver/desktopManager/default.nix @@ -1,8 +1,7 @@ {pkgs, config, ...}: let - inherit (builtins) head tail; - inherit (pkgs.lib) mkOption mkIf filter optionalString any; + inherit (pkgs.lib) mkOption mergeOneOption mkIf filter optionalString any; cfg = config.services.xserver.desktopManager; needBGCond = d: ! (d ? bgSupport && d.bgSupport); @@ -58,10 +57,8 @@ in Default desktop manager loaded if none have been chosen. "; merge = name: list: - let defaultDM = head list; in - if tail list != [] then - throw "Only one default desktop manager is allowed." - else if any (w: w.name == defaultDM) cfg.session.list then + let defaultDM = mergeOneOption name list; in + if any (w: w.name == defaultDM) cfg.session.list then defaultDM else throw "Default desktop manager not found."; diff --git a/upstart-jobs/xserver/displayManager/default.nix b/upstart-jobs/xserver/displayManager/default.nix index 2699e34ecad..12393af8f6c 100644 --- a/upstart-jobs/xserver/displayManager/default.nix +++ b/upstart-jobs/xserver/displayManager/default.nix @@ -1,8 +1,7 @@ {pkgs, config, ...}: let - inherit (builtins) head tail; - inherit (pkgs.lib) mkOption optionals filter concatMap concatMapStrings; + inherit (pkgs.lib) mkOption mergeOneOption optionals filter concatMap concatMapStrings; cfg = config.services.xserver; xorg = cfg.package; @@ -159,11 +158,7 @@ in the display manager start the xserver. "; - merge = name: list: - if tail list != [] then - throw "only one display manager is allowed." - else - head list; + merge = mergeOneOption; }; }; diff --git a/upstart-jobs/xserver/windowManager/default.nix b/upstart-jobs/xserver/windowManager/default.nix index 41c3ad15983..14f06b62b03 100644 --- a/upstart-jobs/xserver/windowManager/default.nix +++ b/upstart-jobs/xserver/windowManager/default.nix @@ -1,8 +1,7 @@ {pkgs, config, ...}: let - inherit (builtins) head tail; - inherit (pkgs.lib) mkOption any; + inherit (pkgs.lib) mkOption mergeOneOption any; cfg = config.services.xserver.windowManager; in @@ -47,10 +46,8 @@ in Default window manager loaded if none have been chosen. "; merge = name: list: - let defaultWM = head list; in - if tail list != [] then - throw "Only one default window manager is allowed." - else if any (w: w.name == defaultWM) cfg.session then + let defaultWM = mergeOneOption name list; in + if any (w: w.name == defaultWM) cfg.session then defaultWM else throw "Default window manager not found."; From ecc761543ced38cdef4d521e1af14966a23b00c7 Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Sun, 25 Jan 2009 15:49:23 +0000 Subject: [PATCH 13/14] Remove name argument of merge functions. svn path=/nixos/branches/fix-style/; revision=13860 --- upstart-jobs/xserver/desktopManager/default.nix | 4 ++-- upstart-jobs/xserver/windowManager/default.nix | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/upstart-jobs/xserver/desktopManager/default.nix b/upstart-jobs/xserver/desktopManager/default.nix index 05f82dd3e6c..ab1271e69ae 100644 --- a/upstart-jobs/xserver/desktopManager/default.nix +++ b/upstart-jobs/xserver/desktopManager/default.nix @@ -56,8 +56,8 @@ in description = " Default desktop manager loaded if none have been chosen. "; - merge = name: list: - let defaultDM = mergeOneOption name list; in + merge = list: + let defaultDM = mergeOneOption list; in if any (w: w.name == defaultDM) cfg.session.list then defaultDM else diff --git a/upstart-jobs/xserver/windowManager/default.nix b/upstart-jobs/xserver/windowManager/default.nix index 14f06b62b03..cb5a1b674e0 100644 --- a/upstart-jobs/xserver/windowManager/default.nix +++ b/upstart-jobs/xserver/windowManager/default.nix @@ -45,8 +45,8 @@ in description = " Default window manager loaded if none have been chosen. "; - merge = name: list: - let defaultWM = mergeOneOption name list; in + merge = list: + let defaultWM = mergeOneOption list; in if any (w: w.name == defaultWM) cfg.session then defaultWM else From 1c1c1e0b15fcda5bcda9eed1f21c57cd3d503992 Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Sun, 25 Jan 2009 15:49:27 +0000 Subject: [PATCH 14/14] Add a section to help user to extend NixOS. svn path=/nixos/branches/fix-style/; revision=13861 --- doc/manual/development.xml | 224 +++++++++++++++++++++++++++++++++++++ 1 file changed, 224 insertions(+) diff --git a/doc/manual/development.xml b/doc/manual/development.xml index f4d68526c5e..e79114d1785 100644 --- a/doc/manual/development.xml +++ b/doc/manual/development.xml @@ -7,6 +7,230 @@ NixOS. +
+ +Extending NixOS + +A unique syntax is used to express all system, hardware, computer and + service configurations. This syntax helps for reading and writing new + configuration files. It is coming with some extra strategies defined in + NixPkgs which are used to merge and evaluate all configuration files. + + A configuration file is the same as your own computer + configuration. + +Usual configuration file + +{pkgs, config, ...}: + +###### interface +let + inherit (pkgs.lib) mkOption; + + options = { + services = { + locate = { + + enable = mkOption { + default = false; + example = true; + description = '' + If enabled, NixOS will periodically update the database of + files used by the locate command. + ''; + }; + + period = mkOption { + default = "15 02 * * *"; + description = '' + This option defines (in the format used by cron) when the + locate database is updated. + The default is to update at 02:15 (at night) every day. + ''; + }; + + }; + + }; + }; +in + +###### implementation +let + cfg = config.services.locate; + inherit (pkgs.lib) mkIf mkThenElse; + + locatedb = "/var/cache/locatedb"; + logfile = "/var/log/updatedb"; + cmd = "root updatedb --localuser=nobody --output=${locatedb} > ${logfile}"; +in + +mkIf cfg.enable { + require = [ + options + + # config.services.cron + (import ../../upstart-jobs/cron.nix) + ]; + + services = { + cron = { + systemCronJobs = mkThenElse { + thenPart = "${cfg.period} root ${cmd}"; + elsePart = ""; + }; + }; + }; +} + + + shows the configuration + file for the locate service which uses cron to update the + database at some dates which can be defined by the user. This nix + expression is coming + from upstart-jobs/cron/locate.nix. It shows a simple + example of a service that can be either distributed on many computer that + are using the same configuration or to shared with the community. This + file is divided in two with the interface and the implementation. Both + the interface and the implementation declare a configuration + set. + + + + + + This line declares the arguments of the configuration file. You + can omit this line if there is no reference to pkgs + and config inside the configuration file. + + The argument pkgs refers to NixPkgs and allow + you to access all attributes contained inside it. In this + example pkgs is used to retrieve common functions to + ease the writing of configuration files + like mkOption, mkIf + and mkThenElse. + + The argument config corresponds to the whole + NixOS configuration. This is a set which is build by merging all + configuration files imported to set up the system. Thus all options + declared are contained inside this variable. In this + example config is used to retrieve the status of + the enable flag. The important point of this + argument is that it contains either the result of the merge of different + settings or the default value, therefore you cannot assume + that is always false + because it may have been defined in another configuration file. + + + + + + This line is used to import a function that is useful for + writing this configuration file. + + + + + + The variable options is + a configuration set which is only used to declare + options with the function mkOption imported + from pkgs/lib/default.nix. Options may contained + any attribute but only the following have a special + meaning: default, example, + description, merge + and apply. + + The merge attribute is used to merge all values + defined in all configuration files and this function return a value + which has the same type as the default value. If the merge function is + not defined, then a default function + (pkgs.lib.mergeDefaultOption) is used to merge + values. The merge attribute is a function which + expect two arguments: the location of the option and the list of values + which have to be merged. + + The apply attribute is a function used to + process the option. Thus the value return + by would be + the result of the apply function called with either + the default value or the result of + the merge function. + + + + + + This line is a common trick used to reduce the amount of + writing. In this case cfg is just a sugar over + + + + + + + This line is used to declare a special IF + statement. If you had put a usual IF statement + here, with the same condition, then you will get an infinite loop. The + reason is that your condition ask for the value of the + option but in order to + get this value you have to evaluate all configuration sets including the + configuration set contained inside your file. + + To remove this extra complexity, mkIf has been + introduced to get rid of possible infinite loop and to factor your + writing. + + + + + + The attribute require is the only special + option that exists. It is used to embed all option declarations that + are required by your configuration file and it is also used to provide + the options that you are declaring. + + This attribute is processed + with pkgs.lib.uniqFlatten to collect all + configuration files that are used by your system and it avoid the + insertion of duplicated elements by comparing the configuration set codes. + + Currently, the file configuration.nix + implicitly embeds system/options.nix. If you need + a special configuration file, then you will have to add similar lines + to your computer configuration. + + + + + + As mkIf does not need + any then part or else part, + then you can specify one on each option definition with the + function mkThenElse. + + To avoid a lot of mkThenElse with empty + else part, a sugar has been added to infer the + corresponding empty-value of your option when the + function mkThenElse is not used. + + If your then part + and else part are identical, then you should use + the function mkAlways to ignore the condition. + + If you need to add another condition, then you can add mkIf to on + the appropriate location. Thus the then part will + only be used if all conditions declared with mkIf + are satisfied. + + + + + + + +
+
Building specific parts of NixOS