| 
									
										
										
										
											2009-01-02 16:06:46 +00:00
										 |  |  | # generate the script used to activate the configuration. | 
					
						
							| 
									
										
										
										
											2014-04-14 16:26:48 +02:00
										 |  |  | { config, lib, pkgs, ... }: | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-14 16:26:48 +02:00
										 |  |  | with lib; | 
					
						
							| 
									
										
										
										
											2009-01-02 16:06:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | let | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-20 01:35:46 +00:00
										 |  |  |   addAttributeName = mapAttrs (a: v: v // { | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  |     text = ''
 | 
					
						
							|  |  |  |       #### Activation script snippet ${a}: | 
					
						
							|  |  |  |       ${v.text} | 
					
						
							| 
									
										
										
										
											2009-05-27 09:40:55 +00:00
										 |  |  |     '';
 | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2009-05-27 09:40:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-14 19:00:39 +03:00
										 |  |  |   path = map getBin | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  |     [ pkgs.coreutils pkgs.gnugrep pkgs.findutils | 
					
						
							|  |  |  |       pkgs.glibc # needed for getent | 
					
						
							|  |  |  |       pkgs.shadow | 
					
						
							|  |  |  |       pkgs.nettools # needed for hostname | 
					
						
							| 
									
										
										
										
											2009-05-27 09:40:55 +00:00
										 |  |  |     ]; | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  | in | 
					
						
							| 
									
										
										
										
											2009-05-27 09:40:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-27 09:40:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  |   ###### interface | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  |   options = { | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  |     system.activationScripts = mkOption { | 
					
						
							|  |  |  |       default = {}; | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-04 18:53:26 +12:00
										 |  |  |       example = literalExample ''
 | 
					
						
							|  |  |  |         { stdio = { | 
					
						
							|  |  |  |             text = '''
 | 
					
						
							|  |  |  |               # Needed by some programs. | 
					
						
							|  |  |  |               ln -sfn /proc/self/fd /dev/fd | 
					
						
							|  |  |  |               ln -sfn /proc/self/fd/0 /dev/stdin | 
					
						
							|  |  |  |               ln -sfn /proc/self/fd/1 /dev/stdout | 
					
						
							|  |  |  |               ln -sfn /proc/self/fd/2 /dev/stderr | 
					
						
							|  |  |  |             ''';
 | 
					
						
							|  |  |  |             deps = []; | 
					
						
							|  |  |  |           }; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       '';
 | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  |       description = ''
 | 
					
						
							| 
									
										
										
										
											2013-10-23 16:59:15 +02:00
										 |  |  |         A set of shell script fragments that are executed when a NixOS | 
					
						
							|  |  |  |         system configuration is activated.  Examples are updating | 
					
						
							|  |  |  |         /etc, creating accounts, and so on.  Since these are executed | 
					
						
							|  |  |  |         every time you boot the system or run | 
					
						
							|  |  |  |         <command>nixos-rebuild</command>, it's important that they are | 
					
						
							|  |  |  |         idempotent and fast. | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  |       '';
 | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-28 00:56:22 +01:00
										 |  |  |       type = types.attrsOf types.unspecified; # FIXME | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  |       apply = set: { | 
					
						
							| 
									
										
										
										
											2010-09-13 18:19:15 +00:00
										 |  |  |         script = | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  |           ''
 | 
					
						
							|  |  |  |             #! ${pkgs.stdenv.shell} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-13 18:19:15 +00:00
										 |  |  |             systemConfig=@out@ | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  |             export PATH=/empty | 
					
						
							|  |  |  |             for i in ${toString path}; do | 
					
						
							| 
									
										
										
										
											2012-03-22 10:17:10 +00:00
										 |  |  |                 PATH=$PATH:$i/bin:$i/sbin | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  |             done | 
					
						
							| 
									
										
										
										
											2010-09-13 18:19:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-15 01:57:36 +02:00
										 |  |  |             _status=0 | 
					
						
							|  |  |  |             trap "_status=1" ERR | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-22 10:17:10 +00:00
										 |  |  |             # Ensure a consistent umask. | 
					
						
							|  |  |  |             umask 0022 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  |             ${ | 
					
						
							|  |  |  |               let | 
					
						
							| 
									
										
										
										
											2013-11-12 13:48:19 +01:00
										 |  |  |                 set' = mapAttrs (n: v: if isString v then noDepEntry v else v) set; | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  |                 withHeadlines = addAttributeName set'; | 
					
						
							|  |  |  |               in textClosureMap id (withHeadlines) (attrNames withHeadlines) | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             # Make this configuration the current configuration. | 
					
						
							|  |  |  |             # The readlink is there to ensure that when $systemConfig = /system | 
					
						
							| 
									
										
										
										
											2012-07-16 11:27:59 -04:00
										 |  |  |             # (which is a symlink to the store), /run/current-system is still | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  |             # used as a garbage collection root. | 
					
						
							| 
									
										
										
										
											2012-07-16 11:27:59 -04:00
										 |  |  |             ln -sfn "$(readlink -f "$systemConfig")" /run/current-system | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             # Prevent the current configuration from being garbage-collected. | 
					
						
							| 
									
										
										
										
											2012-07-16 11:27:59 -04:00
										 |  |  |             ln -sfn /run/current-system /nix/var/nix/gcroots/current-system | 
					
						
							| 
									
										
										
										
											2014-08-15 01:57:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             exit $_status | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  |           '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-19 18:11:36 +01:00
										 |  |  |     environment.usrbinenv = mkOption { | 
					
						
							|  |  |  |       default = "${pkgs.coreutils}/bin/env"; | 
					
						
							|  |  |  |       example = literalExample ''
 | 
					
						
							|  |  |  |         "''${pkgs.busybox}/bin/env" | 
					
						
							|  |  |  |       '';
 | 
					
						
							|  |  |  |       type = types.nullOr types.path; | 
					
						
							|  |  |  |       visible = false; | 
					
						
							|  |  |  |       description = ''
 | 
					
						
							|  |  |  |         The env(1) executable that is linked system-wide to | 
					
						
							|  |  |  |         <literal>/usr/bin/env</literal>. | 
					
						
							|  |  |  |       '';
 | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2009-05-27 09:40:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  |   ###### implementation | 
					
						
							| 
									
										
										
										
											2009-05-27 09:40:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  |   config = { | 
					
						
							| 
									
										
										
										
											2009-05-27 09:40:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  |     system.activationScripts.stdio = | 
					
						
							|  |  |  |       ''
 | 
					
						
							|  |  |  |         # Needed by some programs. | 
					
						
							|  |  |  |         ln -sfn /proc/self/fd /dev/fd | 
					
						
							|  |  |  |         ln -sfn /proc/self/fd/0 /dev/stdin | 
					
						
							|  |  |  |         ln -sfn /proc/self/fd/1 /dev/stdout | 
					
						
							|  |  |  |         ln -sfn /proc/self/fd/2 /dev/stderr | 
					
						
							|  |  |  |       '';
 | 
					
						
							| 
									
										
										
										
											2009-05-27 09:40:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  |     system.activationScripts.var = | 
					
						
							|  |  |  |       ''
 | 
					
						
							|  |  |  |         # Various log/runtime directories. | 
					
						
							| 
									
										
										
										
											2009-05-27 09:40:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-09 00:50:05 +02:00
										 |  |  |         mkdir -m 0755 -p /run/nix/current-load # for distributed builds | 
					
						
							|  |  |  |         mkdir -m 0700 -p /run/nix/remote-stores | 
					
						
							| 
									
										
										
										
											2009-05-27 09:40:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  |         mkdir -m 0755 -p /var/log | 
					
						
							| 
									
										
										
										
											2009-05-27 09:40:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-31 13:26:06 +01:00
										 |  |  |         touch /var/log/wtmp /var/log/lastlog # must exist | 
					
						
							|  |  |  |         chmod 644 /var/log/wtmp /var/log/lastlog | 
					
						
							| 
									
										
										
										
											2009-05-27 09:40:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  |         mkdir -m 1777 -p /var/tmp | 
					
						
							| 
									
										
										
										
											2009-09-26 10:27:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  |         # Empty, read-only home directory of many system accounts. | 
					
						
							|  |  |  |         mkdir -m 0555 -p /var/empty | 
					
						
							|  |  |  |       '';
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-19 18:11:36 +01:00
										 |  |  |     system.activationScripts.usrbinenv = if config.environment.usrbinenv != null | 
					
						
							|  |  |  |       then ''
 | 
					
						
							| 
									
										
										
										
											2012-03-12 10:41:39 +00:00
										 |  |  |         mkdir -m 0755 -p /usr/bin | 
					
						
							| 
									
										
										
										
											2016-01-19 18:11:36 +01:00
										 |  |  |         ln -sfn ${config.environment.usrbinenv} /usr/bin/.env.tmp | 
					
						
							| 
									
										
										
										
											2012-03-12 10:41:39 +00:00
										 |  |  |         mv /usr/bin/.env.tmp /usr/bin/env # atomically replace /usr/bin/env | 
					
						
							| 
									
										
										
										
											2016-01-19 18:11:36 +01:00
										 |  |  |       ''
 | 
					
						
							|  |  |  |       else ''
 | 
					
						
							|  |  |  |         rm -f /usr/bin/env | 
					
						
							|  |  |  |         rmdir --ignore-fail-on-non-empty /usr/bin /usr | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  |       '';
 | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-17 19:33:55 +00:00
										 |  |  |     system.activationScripts.tmpfs = | 
					
						
							|  |  |  |       ''
 | 
					
						
							| 
									
										
										
										
											2013-01-02 18:23:19 +01:00
										 |  |  |         ${pkgs.utillinux}/bin/mount -o "remount,size=${config.boot.devSize}" none /dev | 
					
						
							|  |  |  |         ${pkgs.utillinux}/bin/mount -o "remount,size=${config.boot.devShmSize}" none /dev/shm | 
					
						
							|  |  |  |         ${pkgs.utillinux}/bin/mount -o "remount,size=${config.boot.runSize}" none /run | 
					
						
							| 
									
										
										
										
											2012-05-17 19:33:55 +00:00
										 |  |  |       '';
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-27 09:40:55 +00:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-02 16:06:46 +00:00
										 |  |  | } |