From d33e0c4a657af5cf6a13ea5df1850ed528d29bca Mon Sep 17 00:00:00 2001 From: Adam Woods Date: Fri, 1 Mar 2024 17:09:54 +1100 Subject: [PATCH] feat: add option to enable zsh via nix-machine configuration (#1) --- .github/workflows/ci.yaml | 4 +++- configuration/home-manager/default.nix | 2 +- configuration/home-manager/zsh.nix | 8 ++++++++ configuration/nix-darwin/default.nix | 10 ++++++++-- configuration/nix-darwin/zsh.nix | 10 ++++++++++ configuration/options.nix | 8 ++++++++ templates/minimal/flake.nix | 5 +---- 7 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 configuration/home-manager/zsh.nix create mode 100644 configuration/nix-darwin/zsh.nix diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d4ddbcd..4ee7651 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -29,12 +29,14 @@ jobs: cd ${{ matrix.template }} # Substitute in the build runner's configuration. + nix run nixpkgs#sd 'nix-machine.url = "github:squirmy/nix-machine"' 'nix-machine.url = "github:squirmy/nix-machine/${{ github.sha }}"' flake.nix nix run nixpkgs#sd 'username = "username"' 'username = "runner"' flake.nix nix run nixpkgs#sd 'homeDirectory = "/Users/username"' 'homeDirectory = "/Users/runner"' flake.nix nix run nixpkgs#sd 'nixpkgs.hostPlatform = "aarch64-darwin"' 'nixpkgs.hostPlatform = "x86_64-darwin"' flake.nix sudo -i mv /etc/nix/nix.conf /etc/nix/nix.conf.before-nix-darwin - + sudo -i mv /etc/shells /etc/shells.before-nix-darwin + nix run nix-darwin --extra-experimental-features "nix-command flakes" -- switch --flake .#hostname source /etc/zshenv diff --git a/configuration/home-manager/default.nix b/configuration/home-manager/default.nix index fe4e7ed..7d798f6 100644 --- a/configuration/home-manager/default.nix +++ b/configuration/home-manager/default.nix @@ -3,7 +3,7 @@ config, ... }: { - imports = [./trampoline]; + imports = [./trampoline ./zsh.nix]; # It is occasionally necessary for Home Manager to change configuration # defaults in a way that is incompatible with stateful data. diff --git a/configuration/home-manager/zsh.nix b/configuration/home-manager/zsh.nix new file mode 100644 index 0000000..952fd53 --- /dev/null +++ b/configuration/home-manager/zsh.nix @@ -0,0 +1,8 @@ +{ + lib, + config, + ... +}: +lib.mkIf config.nix-machine.shells.zsh.enable { + programs.zsh.enable = true; +} diff --git a/configuration/nix-darwin/default.nix b/configuration/nix-darwin/default.nix index 0d3eff0..6ce56da 100644 --- a/configuration/nix-darwin/default.nix +++ b/configuration/nix-darwin/default.nix @@ -1,5 +1,9 @@ -{config, ...}: { - imports = [./nix.nix ./nixpkgs.nix]; +{ + config, + pkgs, + ... +}: { + imports = [./nix.nix ./nixpkgs.nix ./zsh.nix]; # Set the user's name & home directory. This should be # in sync with home manager. @@ -7,4 +11,6 @@ name = config.nix-machine.username; home = config.nix-machine.homeDirectory; }; + + environment.shells = [pkgs.bashInteractive]; } diff --git a/configuration/nix-darwin/zsh.nix b/configuration/nix-darwin/zsh.nix new file mode 100644 index 0000000..c01bfbd --- /dev/null +++ b/configuration/nix-darwin/zsh.nix @@ -0,0 +1,10 @@ +{ + lib, + config, + pkgs, + ... +}: +lib.mkIf config.nix-machine.shells.zsh.enable { + programs.zsh.enable = true; + environment.shells = [pkgs.zsh]; +} diff --git a/configuration/options.nix b/configuration/options.nix index 64549b0..204ee26 100644 --- a/configuration/options.nix +++ b/configuration/options.nix @@ -1,4 +1,8 @@ {lib, ...}: let + shellsOptions = { + zsh.enable = lib.options.mkEnableOption "zsh"; + }; + configurationOptions = { nixpkgs.hostPlatform = lib.mkOption { type = lib.types.str; @@ -22,6 +26,10 @@ homeDirectory = lib.mkOption { type = lib.types.str; }; + shells = lib.mkOption { + type = lib.types.submodule {options = shellsOptions;}; + default = {}; + }; }; in { options.nix-machine = lib.mkOption { diff --git a/templates/minimal/flake.nix b/templates/minimal/flake.nix index 5c5021c..6a305ce 100644 --- a/templates/minimal/flake.nix +++ b/templates/minimal/flake.nix @@ -19,6 +19,7 @@ username = "username"; homeDirectory = "/Users/username"; nixpkgs.hostPlatform = "aarch64-darwin"; + shells.zsh.enable = true; }; }; @@ -27,8 +28,6 @@ # https://daiderd.com/nix-darwin/manual/index.html nixDarwin = {...}: { security.pam.enableSudoTouchIdAuth = true; - - programs.zsh.enable = true; }; # configuration to apply to home-manager @@ -37,8 +36,6 @@ home.packages = [ pkgs.fortune ]; - - programs.zsh.enable = true; }; }; };