diff --git a/default.nix b/default.nix index ec5f16df..c5376a11 100644 --- a/default.nix +++ b/default.nix @@ -11,7 +11,7 @@ let ./modules/system/defaults ./modules/system/etc.nix ./modules/system/launchd.nix - ./modules/nix/nix-tools.nix + ./modules/nix/nix-darwin.nix ./modules/nix/nixpkgs.nix ./modules/environment ./modules/launchd diff --git a/modules/nix/nix-darwin.nix b/modules/nix/nix-darwin.nix new file mode 100644 index 00000000..787c5fa1 --- /dev/null +++ b/modules/nix/nix-darwin.nix @@ -0,0 +1,41 @@ +{ config, pkgs, ... }: + +let + + inherit (pkgs) stdenv; + + writeProgram = name: env: src: + pkgs.substituteAll ({ + inherit name src; + dir = "bin"; + isExecutable = true; + } // env); + + darwin-option = writeProgram "darwin-option" + { + inherit (config.system) profile; + inherit (stdenv) shell; + } + ../../pkgs/nix-tools/darwin-option.sh; + + darwin-rebuild = writeProgram "darwin-rebuild" + { + inherit (config.system) profile; + inherit (stdenv) shell; + path = "${pkgs.coreutils}/bin:${config.environment.systemPath}"; + } + ../../pkgs/nix-tools/darwin-rebuild.sh; + +in + +{ + config = { + + environment.systemPackages = + [ # Include nix-tools by default + darwin-option + darwin-rebuild + ]; + + }; +} diff --git a/modules/nix/nix-tools.nix b/modules/nix/nix-tools.nix deleted file mode 100644 index 580244dd..00000000 --- a/modules/nix/nix-tools.nix +++ /dev/null @@ -1,19 +0,0 @@ -{ config, pkgs, ... }: - -let - - tools = pkgs.callPackage ../../pkgs/nix-tools {}; - -in - -{ - config = { - - environment.systemPackages = - [ # Include nix-tools by default - tools.darwin-option - tools.darwin-rebuild - ]; - - }; -} diff --git a/modules/system/activation-scripts.nix b/modules/system/activation-scripts.nix index 3948fccf..2695e54f 100644 --- a/modules/system/activation-scripts.nix +++ b/modules/system/activation-scripts.nix @@ -38,6 +38,9 @@ in system.activationScripts.script.text = '' #! ${stdenv.shell} + set -e + set -o pipefail + export PATH=${pkgs.coreutils}/bin:${config.environment.systemPath}:$PATH systemConfig=@out@ diff --git a/pkgs/nix-tools/darwin-option.sh b/pkgs/nix-tools/darwin-option.sh new file mode 100755 index 00000000..798317b7 --- /dev/null +++ b/pkgs/nix-tools/darwin-option.sh @@ -0,0 +1,12 @@ +#! @shell@ +set -e +set -o pipefail +export PATH=@path@:$PATH + + +showSyntax() { + echo "$0: not implemented" >&2 + exit 1 +} + +showSyntax diff --git a/pkgs/nix-tools/darwin-rebuild.sh b/pkgs/nix-tools/darwin-rebuild.sh new file mode 100644 index 00000000..898adcae --- /dev/null +++ b/pkgs/nix-tools/darwin-rebuild.sh @@ -0,0 +1,42 @@ +#! @shell@ +set -e +set -o pipefail +export PATH=@path@:$PATH + + +showSyntax() { + exec man darwin-rebuild + exit 1 +} + +# Parse the command line. +origArgs=("$@") +action= + +while [ "$#" -gt 0 ]; do + i="$1"; shift 1 + case "$i" in + --help) + showSyntax + ;; + switch|build) + action="$i" + ;; + *) + echo "$0: unknown option \`$i'" + exit 1 + ;; + esac +done + +if [ -z "$action" ]; then showSyntax; fi + +echo "building the system configuration..." >&2 +if [ "$action" = switch -o "$action" = build ]; then + systemConfig="$(nix-build '' --no-out-link -A system)" +fi + +if [ "$action" = switch ]; then + sudo nix-env -p @profile@ --set $systemConfig + sudo $systemConfig/activate +fi diff --git a/pkgs/nix-tools/default.nix b/pkgs/nix-tools/default.nix deleted file mode 100644 index a6dd4fad..00000000 --- a/pkgs/nix-tools/default.nix +++ /dev/null @@ -1,56 +0,0 @@ -{ stdenv, writeScriptBin, coreutils, nix }: - -{ - darwin-option = writeScriptBin "darwin-option" '' - #! ${stdenv.shell} - set -e - - echo "$0: not implemented" >&2 - exit 1 - ''; - - darwin-rebuild = writeScriptBin "darwin-rebuild" '' - #! ${stdenv.shell} - set -e - - showSyntax() { - exec man darwin-rebuild - exit 1 - } - - # Parse the command line. - origArgs=("$@") - action= - profile=/nix/var/nix/profiles/system - - while [ "$#" -gt 0 ]; do - i="$1"; shift 1 - case "$i" in - --help) - showSyntax - ;; - switch|build) - action="$i" - ;; - *) - echo "$0: unknown option \`$i'" - exit 1 - ;; - esac - done - - if [ -z "$action" ]; then showSyntax; fi - - export PATH=${coreutils}/bin:$PATH - - echo "building the system configuration..." >&2 - if [ "$action" = switch -o "$action" = build ]; then - systemConfig="$(nix-build '' --no-out-link -A system)" - fi - - if [ "$action" = switch ]; then - sudo nix-env -p "$profile" --set $systemConfig - sudo $systemConfig/activate - fi - ''; -}