diff --git a/config.nix b/config.nix index e971e3b5..9a250617 100644 --- a/config.nix +++ b/config.nix @@ -51,6 +51,8 @@ let environment.etc."tmux.conf".text = '' source-file ${config.system.build.setTmuxOptions} + bind 0 set status + set -g status-bg black set -g status-fg white ''; @@ -65,9 +67,10 @@ let bindkey -e setopt autocd - export PROMPT='%B%(?..[%?] )%b> ' + export PROMPT='%B%(?..[%?] )%b⇒ ' export RPROMPT='%F{green}%~%f' + export PATH=/var/run/current-system/sw/bin:/var/run/current-system/sw/bin''${PATH:+:$PATH} export PATH=/nix/var/nix/profiles/default/bin:/nix/var/nix/profiles/default/sbin''${PATH:+:$PATH} export PATH=$HOME/.nix-profile/bin:$HOME/.nix-profile/bin''${PATH:+:$PATH} @@ -76,10 +79,10 @@ let nixdarwin-rebuild () { case $1 in - "build") nix-build --no-out-link "" -A nixdarwin.toplevel ;; + "build") nix-build --no-out-link '' -A nixdarwin.toplevel ;; "repl") nix-repl "$HOME/.nixpkgs/config.nix" ;; - "shell") nix-shell "" -p nixdarwin.toplevel --run "zsh -l" ;; - "switch") nix-env -f "" -iA nixdarwin.toplevel && exec zsh -l ;; + "shell") nix-shell '' -p nixdarwin.toplevel --run "zsh -l" ;; + "switch") nix-env -f '' -iA nixdarwin.toplevel && nix-shell '' -A nixdarwin.toplevel --run 'sudo $out/activate' && exec zsh -l ;; "") return 1 ;; esac } diff --git a/modules/system.nix b/modules/system.nix index a0d27620..49820593 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 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 + ''; }; };