diff --git a/devShells.nix b/devShells.nix index b15cbe1..8a7e0f7 100644 --- a/devShells.nix +++ b/devShells.nix @@ -4,7 +4,7 @@ { self, ... }: { - perSystem = { pkgs, ... }: + perSystem = { pkgs, config, ... }: { pre-commit.check.enable = true; pre-commit.devShell = self.devShells.default; @@ -23,7 +23,11 @@ devShells = { - default = pkgs.mkShell { }; + default = pkgs.mkShell { + shellHook = '' + ${config.pre-commit.installationScript} + ''; + }; # # # $ nix develop github:r17x/nixpkgs#node18 diff --git a/flake.lock b/flake.lock index 46ccfe7..850f143 100644 --- a/flake.lock +++ b/flake.lock @@ -20,6 +20,27 @@ "type": "github" } }, + "dvt": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "utils": "utils" + }, + "locked": { + "lastModified": 1715803922, + "narHash": "sha256-GGzZJGrw43C3RycwIJ4QyMtfuwtNoAwjZl4YazNV8mQ=", + "owner": "efishery", + "repo": "dvt", + "rev": "12ec2687fee9d83a488708909ce0904514990929", + "type": "github" + }, + "original": { + "owner": "efishery", + "repo": "dvt", + "type": "github" + } + }, "fenix": { "inputs": { "nixpkgs": [ @@ -354,6 +375,7 @@ "root": { "inputs": { "darwin": "darwin", + "dvt": "dvt", "home": "home", "luafun": "luafun", "master": "master", @@ -466,6 +488,21 @@ "type": "github" } }, + "utils": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "vimPlugins_chatgpt-nvim": { "flake": false, "locked": { diff --git a/flake.nix b/flake.nix index 2b3460e..9893fdc 100644 --- a/flake.nix +++ b/flake.nix @@ -13,7 +13,6 @@ ./overlays ./modules/parts ./hosts - ./users ]; }; @@ -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_" diff --git a/home/shells.nix b/home/shells.nix index 0fdc743..467fceb 100644 --- a/home/shells.nix +++ b/home/shells.nix @@ -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; diff --git a/hosts/default.nix b/hosts/default.nix index 8fa12c4..4afd353 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -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 = { }; + }; } diff --git a/lib/mkFlake2VimPlugin.nix b/lib/mkFlake2VimPlugin.nix index ce83931..17b49eb 100644 --- a/lib/mkFlake2VimPlugin.nix +++ b/lib/mkFlake2VimPlugin.nix @@ -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; diff --git a/modules/parts/darwin.nix b/modules/parts/darwin.nix deleted file mode 100644 index dffed3d..0000000 --- a/modules/parts/darwin.nix +++ /dev/null @@ -1,63 +0,0 @@ -{ config, lib, inputs, withSystem, ... }: - -let - inherit lib; - inherit (lib) types; - - cfg = config.parts.darwinConfigurations; - configurations = builtins.mapAttrs (_: value: value._darwin) cfg; - - darwinOpts = { config, name, ... }: { - options = { - system = lib.mkOption { - type = types.enum [ "aarch64-darwin" "x86_64-darwin" ]; - description = "System architecture for the configuration."; - }; - - stateVersion = lib.mkOption { - type = types.int; - description = "nix-darwin state version, changing this value DOES NOT update your system."; - }; - - modules = lib.mkOption { - type = types.listOf types.unspecified; - description = "List of nix-darwin modules to include in the configuration."; - }; - - _darwin = lib.mkOption { - type = types.unspecified; - readOnly = true; - description = "Composed nix-darwin configuration."; - }; - }; - - config._darwin = withSystem config.system (ctx: - inputs.darwin.lib.darwinSystem { - inherit inputs; - inherit (ctx) system; - - modules = config.modules ++ [ - # Composed home-manager configuration. - inputs.home.darwinModules.home-manager - - ({ pkgs, ... }: { - inherit (ctx) nix; - nixpkgs = removeAttrs ctx.nixpkgs [ "hostPlatform" ]; - _module.args = ctx.extraModuleArgs; - networking.hostName = name; - networking.computerName = name; - system.stateVersion = config.stateVersion; - environment.systemPackages = ctx.basePackagesFor pkgs; - }) - ]; - } - ); - }; -in -{ - options.parts.darwinConfigurations = lib.mkOption { - type = types.attrsOf (types.submodule darwinOpts); - }; - - config.flake.darwinConfigurations = configurations; -} diff --git a/modules/parts/default.nix b/modules/parts/default.nix index e862262..b6daa21 100644 --- a/modules/parts/default.nix +++ b/modules/parts/default.nix @@ -1,10 +1,7 @@ { self, inputs, ... }: { - imports = [ - ./home.nix - ./darwin.nix - ]; + imports = [ ]; perSystem = { lib, pkgs, system, inputs', ... }: { formatter = inputs.nixpkgs-fmt.defaultPackage.${system}; @@ -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 diff --git a/modules/parts/home.nix b/modules/parts/home.nix deleted file mode 100644 index 6325d9d..0000000 --- a/modules/parts/home.nix +++ /dev/null @@ -1,78 +0,0 @@ -{ config, lib, inputs, withSystem, ... }: - -let - inherit lib; - inherit (lib) types; - - cfg = config.parts.homeConfigurations; - configurations = builtins.mapAttrs (_: value: value._home) cfg; - - homeOpts = opts@{ config, lib, name, ... }: { - options = { - system = lib.mkOption { - type = types.enum [ - "aarch64-darwin" - "aarch64-linux" - "x86_64-darwin" - "x86_64-linux" - ]; - - description = "System architecture for the configuration."; - }; - - stateVersion = lib.mkOption { - type = types.str; - description = "home-manager state version, changing this value DOES NOT update your config."; - }; - - modules = lib.mkOption { - type = types.listOf types.unspecified; - description = "List of home-manager modules to include in the configuration."; - }; - - _home = lib.mkOption { - type = types.unspecified; - readOnly = true; - description = "Composed home-manager configuration."; - }; - }; - - config._home = withSystem config.system (ctx: - inputs.home.lib.homeManagerConfiguration { - # Default nixpkgs for home.nix - pkgs = inputs.nixpkgs.legacyPackages.${ctx.system}; - - modules = config.modules ++ [ - inputs.nix-index-database.hmModules.nix-index - - ({ config, lib, pkgs, ... }: { - _module.args = ctx.extraModuleArgs; - nixpkgs = removeAttrs ctx.nixpkgs [ "hostPlatform" ]; - - home = { - username = builtins.elemAt (lib.strings.split "@" name) 0; - inherit (opts.config) stateVersion; - - packages = builtins.attrValues { - inherit (pkgs) - hello; - }; - - homeDirectory = lib.mkMerge [ - (lib.mkIf pkgs.stdenv.isDarwin "/Users/${config.home.username}") - (lib.mkIf pkgs.stdenv.isLinux "/home/${config.home.username}") - ]; - }; - }) - ]; - } - ); - }; -in -{ - options.parts.homeConfigurations = lib.mkOption { - type = types.attrsOf (types.submodule homeOpts); - }; - - config.flake.homeConfigurations = configurations; -} diff --git a/overlays/default.nix b/overlays/default.nix index 20e6a2b..a86ea74 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -1,5 +1,38 @@ -_: +{ inputs, ... }: { - flake.overlays.default = final: prev: { }; + flake.overlays.default = final: prev: { + luajitPackages = prev.luajitPackages // { + luafun = prev.luajitPackages.buildLuarocksPackage { + pname = "fun"; + version = "scm-1"; + + src = inputs.luafun; + + disabled = (prev.luajitPackages.luaOlder "5.1") || (prev.luajitPackages.luaAtLeast "5.4"); + propagatedBuildInputs = [ prev.lua ]; + + meta = { + homepage = "https://luafun.github.io/"; + description = "High-performance functional programming library for Lua"; + license.fullName = "MIT/X11"; + }; + }; + }; + tree-sitter-grammars = prev.tree-sitter-grammars // { + tree-sitter-rescript = + prev.tree-sitter.buildGrammar { + version = inputs.ts-rescript.lastModifiedDate; + language = "rescript"; + generate = true; + src = inputs.ts-rescript; + }; + }; + vimPlugins = prev.vimPlugins.extend (_: _: { } // + (import ../lib/mkFlake2VimPlugin.nix inputs { pkgs = prev; }) + ); + } + // (import ./mac-pkgs final prev) + // (inputs.dvt.overlay final prev) + ; } diff --git a/overlays/vimUtils.nix b/overlays/vimUtils.nix index 34168f5..ea0ebdc 100644 --- a/overlays/vimUtils.nix +++ b/overlays/vimUtils.nix @@ -2,7 +2,7 @@ _final: prev: let buildVimPluginFromFlakeInput = inputs: name: - prev.vimUtils.buildVimPluginFrom2Nix { + prev.vimUtils.buildVimPlugin { pname = name; version = inputs.${name}.lastModifiedDate; src = inputs.${name}; diff --git a/modules/user.nix b/shared/user.nix similarity index 80% rename from modules/user.nix rename to shared/user.nix index a912cc5..499c2db 100644 --- a/modules/user.nix +++ b/shared/user.nix @@ -6,19 +6,19 @@ in options = { users.primaryUser = { username = mkOption { - type = with types; nullOr string; + type = with types; nullOr str; default = null; }; fullName = mkOption { - type = with types; nullOr string; + type = with types; nullOr str; default = null; }; email = mkOption { - type = with types; nullOr string; + type = with types; nullOr str; default = null; }; nixConfigDirectory = mkOption { - type = with types; nullOr string; + type = with types; nullOr str; default = null; }; within.neovim.enable = mkOption {