{ config, inputs, lib, pkgs, ... }: let shellType = config.my.shell.type; packages = builtins.attrValues { inherit (pkgs) nixfmt-rfc-style # formatting cachix # binary cache management nixd # language server for Nix deadnix # detext unused/uneeded dependencies statix # linter for Nix expressions ; }; in { options = { my.dev.nix = { enable = lib.mkEnableOption "Install Nix tooling globally"; users = lib.mkOption { type = lib.types.either lib.types.str (lib.types.listOf lib.types.str); default = config.my.toggleUsers.dev; merge = inputs.self.lib.mergeUsersOption lib; description = "Users to install Nix packages for"; }; }; devShells.nix = lib.mkOption { type = lib.types.package; default = pkgs.mkShell { inherit packages; name = "nix-dev-shell"; shellHook = '' echo "❄️ Nix dev environment" ''; }; description = "Nix/NixOS development shell with formatter, linter, LSP, and Cachix"; }; }; config = lib.mkIf config.my.dev.nix.enable { users.users = inputs.self.lib.mkUserAttrs lib config.my.dev.nix.users { inherit packages; }; home-manager.users = inputs.self.lib.mkHomeManagerUsers lib config.my.dev.nix.users (_user: { programs.${shellType}.shellAliases = inputs.self.lib.mergeAliases inputs.self.lib.commonAliases { nixformat = '' deadnix -e && \ nix run nixpkgs#nixfmt-tree && \ statix fix ''; nix-push-cache = '' nix build $NH_FLAKE#nixosConfigurations.${config.networking.hostName}.config.system.build.toplevel \ --print-out-paths --fallback --max-jobs 100 --cores 0 | nix run nixpkgs#attic-client -- push lan:nixos --stdin ''; }; }); }; }