Skip to content

Commit

Permalink
refactor: make legacy darwinConfigurations running well
Browse files Browse the repository at this point in the history
  • Loading branch information
r17x committed May 23, 2024
1 parent f43d20a commit 9bdd083
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 192 deletions.
8 changes: 6 additions & 2 deletions devShells.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{ self, ... }:

{
perSystem = { pkgs, ... }:
perSystem = { pkgs, config, ... }:
{
pre-commit.check.enable = true;
pre-commit.devShell = self.devShells.default;
Expand All @@ -23,7 +23,11 @@


devShells = {
default = pkgs.mkShell { };
default = pkgs.mkShell {
shellHook = ''
${config.pre-commit.installationScript}
'';
};
#
#
# $ nix develop github:r17x/nixpkgs#node18
Expand Down
37 changes: 37 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
./overlays
./modules/parts
./hosts
./users
];
};

Expand Down Expand Up @@ -53,6 +52,9 @@
# utilities
precommit.url = "github:cachix/pre-commit-hooks.nix";
precommit.inputs.nixpkgs.follows = "nixpkgs";
# dvt
dvt.url = "github:efishery/dvt";
dvt.inputs.nixpkgs.follows = "nixpkgs";

# vimPlugins from flake inputs
# prefix "vimPlugins_"
Expand Down
2 changes: 1 addition & 1 deletion home/shells.nix
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ in
{
home = with pkgs;{
sessionVariables = {
OPENAI_API_KEY = "$(cat ${config.sops.secrets.openai_api_key.path})";
# OPENAI_API_KEY = "$(cat ${config.sops.secrets.openai_api_key.path})";
};

inherit shellAliases;
Expand Down
123 changes: 91 additions & 32 deletions hosts/default.nix
Original file line number Diff line number Diff line change
@@ -1,40 +1,99 @@
{ ... }:
{ self, withSystem, inputs, ... }:

let
sharedModules = [
../shared/darwin/gpg.nix
../shared/darwin/homebrew.nix
../shared/darwin/network.nix
../shared/darwin/packages.nix
../shared/darwin/system.nix
];
inherit (inputs.nixpkgs.lib) attrValues;

mkDarwin = name: { system ? "aarch64-darwin", user ? self.users.default, stateVersion ? 4, homeManagerStateVersion ? "23.05", modules ? [ ] }: withSystem system (ctx:
inputs.darwin.lib.darwinSystem {
inherit inputs;
inherit (ctx) system;

modules = attrValues self.commonModules
++ attrValues self.darwinModules
++ [
# Composed home-manager configuration.
inputs.home.darwinModules.home-manager
({ pkgs, ... }: {
inherit (ctx) nix;
_module.args = ctx.extraModuleArgs;
nixpkgs = removeAttrs ctx.nixpkgs [ "hostPlatform" ];
system.stateVersion = stateVersion;
users.primaryUser = user;
networking.hostName = name;
networking.computerName = name;
environment.systemPackages = ctx.basePackagesFor pkgs;
# `home-manager` config
users.users.${user.username} = {
home = "/Users/${user.username}";
shell = pkgs.fish;
};
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.${user.username} = {
imports = attrValues self.homeManagerModules ++ [ inputs.sops.homeManagerModule ];
home.stateVersion = homeManagerStateVersion;
home.user-info = user;
home.packages = [ pkgs.sops ];
sops.gnupg.home = "~/.gnupg";
sops.gnupg.sshKeyPaths = [ ];
sops.defaultSopsFile = ../secrets/secret.yaml;
# git diff integrations
programs.git.extraConfig.diff.sopsdiffer.textconv = "sops -d";
};
})
] ++ modules;
}
);

mkDarwinConfigurations = configurations: builtins.mapAttrs (name: opt: mkDarwin name opt) configurations;
in

{
# nix-darwin configurations
parts.darwinConfigurations = {
# Apple M1
eR17x = {
system = "aarch64-darwin";
stateVersion = 4;
modules = sharedModules;
flake.users = {
default = rec {
username = "r17";
fullName = "Rin";
email = "hi@rin.rocks";
nixConfigDirectory = "/Users/${username}/.config/nixpkgs";
within = {
neovim.enable = true;
gpg.enable = true;
pass.enable = true;
};
};
};

# NixOS configurations
# parts.nixosConfigurations = {
# linuxBased = {
# system = "x86_64-linux";
# stateVersion = "23.05";

# modules = [];
# };
# wsl2 = {
# system = "x86_64-linux";
# stateVersion = "22.05"; # only change this if you know what you are doing.
# wsl = true;

# modules = [ ];
# };
#};
flake.commonModules = {
system-shells = import ../shared/shells.nix;
users-primaryUser = import ../shared/user.nix;
programs-nix-index = import ../shared/nix-index.nix;
};
flake.darwinModules = {
system-darwin = import ../shared/darwin/system.nix;
system-darwin-packages = import ../shared/darwin/packages.nix;
system-darwin-gpg = import ../shared/darwin/gpg.nix;
system-darwin-window-manager = import ../shared/darwin/mouseless.nix;
system-darwin-homebrew = import ../shared/darwin/homebrew.nix;
system-darwin-network = import ../shared/darwin/network.nix;
};
# `home-manager` modules
flake.homeManagerModules = {
r17-alacritty = import ../home/alacritty.nix;
r17-activation = import ../home/activation.nix;
r17-packages = import ../home/packages.nix;
r17-shell = import ../home/shells.nix;
r17-git = import ../home/git.nix;
r17-tmux = import ../home/tmux.nix;
r17-neovim = import ../home/neovim.nix;
gpg = import ../home/gpg.nix;
pass = import ../home/pass.nix;
home-user-info = { lib, ... }: {
options.home.user-info =
(self.commonModules.users-primaryUser { inherit lib; }).options.users.primaryUser;
};
};
# nix-darwin configurations
flake.darwinConfigurations = mkDarwinConfigurations {
eR17 = { };
eR17x = { };
};
}
2 changes: 1 addition & 1 deletion lib/mkFlake2VimPlugin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ inputs:
}:

let
builder = src: pkgs.vimUtils.buildVimPluginFrom2Nix rec {
builder = src: pkgs.vimUtils.buildVimPlugin rec {
inherit src;
pname = src.name;
version = src.lastModifiedDate;
Expand Down
63 changes: 0 additions & 63 deletions modules/parts/darwin.nix

This file was deleted.

9 changes: 2 additions & 7 deletions modules/parts/default.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{ self, inputs, ... }:

{
imports = [
./home.nix
./darwin.nix
];
imports = [ ];

perSystem = { lib, pkgs, system, inputs', ... }: {
formatter = inputs.nixpkgs-fmt.defaultPackage.${system};
Expand All @@ -29,9 +26,7 @@

hostPlatform = system;

overlays = lib.mkForce [
self.overlays.default
];
overlays = lib.mkForce [ self.overlays.default ];
};

# Extra arguments passed to the module system for nix-darwin, NixOS, and home-manager
Expand Down
Loading

0 comments on commit 9bdd083

Please sign in to comment.