diff options
| author | Daiderd Jordan <daiderd@gmail.com> | 2016-10-29 22:40:55 +0200 |
|---|---|---|
| committer | Daiderd Jordan <daiderd@gmail.com> | 2016-10-29 22:41:03 +0200 |
| commit | f81d86d2cb8cdb7c2b0f4c1f6a881f43b68a663d (patch) | |
| tree | bbf7a10c7a66574a6b50e5ecd87efc685acd93c7 /modules | |
| parent | 23a0eefe2de6a03de7842c185426d97ca57c0329 (diff) | |
global current-system
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/system.nix | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/modules/system.nix b/modules/system.nix index a0d2762..4982059 100644 --- a/modules/system.nix +++ b/modules/system.nix @@ -26,6 +26,11 @@ in { ''; }; + system.nixdarwinLabel = mkOption { + type = types.str; + default = "16.09"; + }; + # Used by <nixos/modules/system/etc/etc.nix> system.activationScripts = mkOption { internal = true; }; @@ -33,9 +38,43 @@ in { config = { - system.build.toplevel = pkgs.buildEnv { - name = "nixdarwin-system"; - paths = [ cfg.path cfg.build.etc ]; + system.activationScripts.script = '' + #! ${pkgs.stdenv.shell} + + systemConfig=@out@ + + # Make this configuration the current configuration. + # The readlink is there to ensure that when $systemConfig = /system + # (which is a symlink to the store), /run/current-system is still + # used as a garbage collection root. + ln -sfn "$(readlink -f "$systemConfig")" /run/current-system + + # Prevent the current configuration from being garbage-collected. + ln -sfn /run/current-system /nix/var/nix/gcroots/current-system + + ''; + + system.build.toplevel = pkgs.stdenvNoCC.mkDerivation { + name = "nixdarwin-system-${cfg.nixdarwinLabel}"; + preferLocalBuild = true; + + activationScript = config.system.activationScripts.script; + inherit (cfg) nixdarwinLabel; + + buildCommand = '' + mkdir $out + + ln -s ${cfg.build.etc}/etc $out/etc + ln -s ${cfg.path} $out/sw + + echo "$activationScript" > $out/activate + substituteInPlace $out/activate --subst-var out + chmod u+x $out/activate + unset activationScript + + echo -n "$nixdarwinLabel" > $out/nixdarwin-version + echo -n "$system" > $out/system + ''; }; }; |
