Skip to content

Commit

Permalink
feat: add option to enable zsh via nix-machine configuration (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
squirmy authored Mar 1, 2024
1 parent c39398a commit d33e0c4
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion configuration/home-manager/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions configuration/home-manager/zsh.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
lib,
config,
...
}:
lib.mkIf config.nix-machine.shells.zsh.enable {
programs.zsh.enable = true;
}
10 changes: 8 additions & 2 deletions configuration/nix-darwin/default.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{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.
users.users.${config.nix-machine.username} = {
name = config.nix-machine.username;
home = config.nix-machine.homeDirectory;
};

environment.shells = [pkgs.bashInteractive];
}
10 changes: 10 additions & 0 deletions configuration/nix-darwin/zsh.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
lib,
config,
pkgs,
...
}:
lib.mkIf config.nix-machine.shells.zsh.enable {
programs.zsh.enable = true;
environment.shells = [pkgs.zsh];
}
8 changes: 8 additions & 0 deletions configuration/options.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{lib, ...}: let
shellsOptions = {
zsh.enable = lib.options.mkEnableOption "zsh";
};

configurationOptions = {
nixpkgs.hostPlatform = lib.mkOption {
type = lib.types.str;
Expand All @@ -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 {
Expand Down
5 changes: 1 addition & 4 deletions templates/minimal/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
username = "username";
homeDirectory = "/Users/username";
nixpkgs.hostPlatform = "aarch64-darwin";
shells.zsh.enable = true;
};
};

Expand All @@ -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
Expand All @@ -37,8 +36,6 @@
home.packages = [
pkgs.fortune
];

programs.zsh.enable = true;
};
};
};
Expand Down

0 comments on commit d33e0c4

Please sign in to comment.