From 9a1bea70d5728a19ee0a090dc0bcdeb73f09b7a4 Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Sun, 17 Nov 2024 02:33:37 +1100 Subject: [PATCH] installer: move creating default configuration to README --- .github/workflows/test.yml | 20 ++++++++------------ README.md | 25 ++++++------------------- modules/examples/simple.nix | 5 ++--- pkgs/darwin-installer/default.nix | 25 +++---------------------- 4 files changed, 19 insertions(+), 56 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 92d06d4d..90bd6fdd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -49,17 +49,15 @@ jobs: run: | export NIX_PATH=$HOME/.nix-defexpr/channels - # We run nix-darwin twice to test that it can create darwin-configuration correctly for us - # but we expect it to fail setting up /etc/nix/nix.conf - nix-shell -A installer || true + mkdir -p ~/.config/nix-darwin + cp modules/examples/simple.nix ~/.config/nix-darwin/configuration.nix nixConfHash=$(shasum -a 256 /etc/nix/nix.conf | cut -d ' ' -f 1) /usr/bin/sed -i.bak \ "s/# programs.fish.enable = true;/nix.settings.access-tokens = [ \"github.com=\${{ secrets.GITHUB_TOKEN }}\" ]; environment.etc.\"nix\/nix.conf\".knownSha256Hashes = [ \"$nixConfHash\" ];/" \ - ~/.nixpkgs/darwin-configuration.nix + ~/.config/nix-darwin/configuration.nix - nix-shell -A installer - nix-shell -A installer.check + nix-shell -A installer -I darwin-config=$HOME/.config/nix-darwin/configuration.nix - name: Build and activate default derivation run: | . /etc/static/bashrc @@ -97,17 +95,15 @@ jobs: run: | export NIX_PATH=$HOME/.nix-defexpr/channels - # We run nix-darwin twice to test that it can create darwin-configuration correctly for us - # but we expect it to fail setting up /etc/nix/nix.conf - nix-shell -A installer || true + mkdir -p ~/.config/nix-darwin + cp modules/examples/simple.nix ~/.config/nix-darwin/configuration.nix nixConfHash=$(shasum -a 256 /etc/nix/nix.conf | cut -d ' ' -f 1) /usr/bin/sed -i.bak \ "s/# programs.fish.enable = true;/nix.settings.access-tokens = [ \"github.com=\${{ secrets.GITHUB_TOKEN }}\" ]; environment.etc.\"nix\/nix.conf\".knownSha256Hashes = [ \"$nixConfHash\" ];/" \ - ~/.nixpkgs/darwin-configuration.nix + ~/.config/nix-darwin/configuration.nix - nix-shell -A installer - nix-shell -A installer.check + nix-shell -A installer -I darwin-config=$HOME/.config/nix-darwin/configuration.nix - name: Build and activate default derivation run: | . /etc/static/bashrc diff --git a/README.md b/README.md index 3bbaf5cb..bfc825e9 100644 --- a/README.md +++ b/README.md @@ -115,14 +115,18 @@ nix-darwin.lib.darwinSystem {
Channels -### Installing +### Step 1. Creating `configuration.nix` + +Copy the [simple](./modules/examples/simple.nix) example to `~/.config/nix-darwin/configuration.nix`. + +### Step 2. Installing `nix-darwin` ```bash nix-build https://github.com/LnL7/nix-darwin/archive/master.tar.gz -A installer ./result/bin/darwin-installer ``` -### Updating +### Step 3. Updating `nix-darwin` The installer will configure a channel for this repository. @@ -133,23 +137,6 @@ darwin-rebuild changelog > NOTE: If you are using Nix as a daemon service the channel for that will be owned by root. > Use `sudo -i nix-channel --update darwin` instead. - -### Example configuration - -Configuration lives in `~/.nixpkgs/darwin-configuration.nix`. Check out -[modules/examples](https://github.com/LnL7/nix-darwin/tree/master/modules/examples) for some example configurations. - -```nix -{ pkgs, ... }: -{ - # List packages installed in system profile. To search by name, run: - # $ nix-env -qaP | grep wget - environment.systemPackages = - [ pkgs.vim - ]; -} -``` -
## Documentation diff --git a/modules/examples/simple.nix b/modules/examples/simple.nix index 8d769a2c..5771ec60 100644 --- a/modules/examples/simple.nix +++ b/modules/examples/simple.nix @@ -7,9 +7,8 @@ [ pkgs.vim ]; - # Use a custom configuration.nix location. - # $ darwin-rebuild switch -I darwin-config=$HOME/.config/nixpkgs/darwin/configuration.nix - # environment.darwinConfig = "$HOME/.config/nixpkgs/darwin/configuration.nix"; + # Use custom location for configuration.nix. + environment.darwinConfig = "$HOME/.config/nix-darwin/configuration.nix"; # Enable alternative shell support in nix-darwin. # programs.fish.enable = true; diff --git a/pkgs/darwin-installer/default.nix b/pkgs/darwin-installer/default.nix index 78ca3c88..0eed5187 100644 --- a/pkgs/darwin-installer/default.nix +++ b/pkgs/darwin-installer/default.nix @@ -47,25 +47,6 @@ stdenv.mkDerivation { echo >&2 "Installing nix-darwin..." echo >&2 - config="$HOME/.nixpkgs/darwin-configuration.nix" - if ! test -f "$config"; then - echo "copying example configuration.nix" >&2 - mkdir -p "$HOME/.nixpkgs" - cp "${../../modules/examples/simple.nix}" "$config" - chmod u+w "$config" - fi - - # Skip when stdin is not a tty, eg. - # $ yes | darwin-installer - if test -t 0; then - read -p "Would you like to edit the default configuration.nix before starting? [y/N] " i - case "$i" in - y|Y) - PATH=$_PATH ''${EDITOR:-nano} "$config" - ;; - esac - fi - i=y darwinPath=$(NIX_PATH=$HOME/.nix-defexpr/channels nix-instantiate --eval -E '' 2> /dev/null) || true if ! test -e "$darwinPath"; then @@ -81,13 +62,13 @@ stdenv.mkDerivation { fi export NIX_PATH=${nixPath} - system=$(nix-build '' -I "darwin-config=$config" -A system --no-out-link --show-trace) + system=$(nix-build '' -A system --no-out-link --show-trace) export PATH=$system/sw/bin:$PATH - darwin-rebuild "$action" -I "darwin-config=$config" + darwin-rebuild "$action" echo >&2 - echo >&2 " Open '$config' to get started." + echo >&2 " Installation complete." echo >&2 " See the README for more information: https://github.com/LnL7/nix-darwin/blob/master/README.md" echo >&2 echo >&2 " Please log out and log in again to make sure nix-darwin is properly loaded."