diff --git a/flake.lock b/flake.lock index d9fb2a6..0fa8fc9 100644 --- a/flake.lock +++ b/flake.lock @@ -2,7 +2,9 @@ "nodes": { "davids-dotfiles-private": { "inputs": { - "flake-utils": "flake-utils", + "flake-utils": [ + "flake-utils" + ], "home-manager": "home-manager", "nixpkgs": [ "nixpkgs" @@ -186,6 +188,7 @@ "root": { "inputs": { "davids-dotfiles-private": "davids-dotfiles-private", + "flake-utils": "flake-utils", "home-manager": "home-manager_2", "nix-darwin": "nix-darwin", "nixpkgs": "nixpkgs", diff --git a/flake.nix b/flake.nix index e9b19dc..74b349b 100644 --- a/flake.nix +++ b/flake.nix @@ -7,10 +7,12 @@ rec { nix-darwin.inputs.nixpkgs.follows = "nixpkgs"; home-manager.url = "github:nix-community/home-manager"; home-manager.inputs.nixpkgs.follows = "nixpkgs"; + flake-utils.url = "github:numtide/flake-utils"; poetry2nix.url = "github:nix-community/poetry2nix"; poetry2nix.inputs.nixpkgs.follows = "nixpkgs"; davids-dotfiles-private.url = "github:dszakallas/davids-dotfiles-private"; davids-dotfiles-private.inputs.nixpkgs.follows = "nixpkgs"; + davids-dotfiles-private.inputs.flake-utils.follows = "flake-utils"; davids-dotfiles-private.inputs.poetry2nix.follows = "poetry2nix"; }; @@ -37,6 +39,7 @@ rec { home-manager, davids-dotfiles-private, poetry2nix, + flake-utils, ... }: let @@ -75,6 +78,16 @@ rec { systemModules = importChildren ./modules/system; homeModules = importChildren ./modules/home; users = importChildren ./users; + packages = ( + flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + packages = lib.callPackageDirWith ./pkgs (inputs // pkgs); + in + packages + ) + ); }; darwinConfigurations = { Jellyfish = mkDarwin { diff --git a/lib/default.nix b/lib/default.nix index 37d36db..f0384b3 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,6 +1,6 @@ { lib, ... }: with lib; -{ +rec { # List immediate subdirectories of a directory subDirs = d: @@ -21,4 +21,42 @@ with lib; ${content} ${comment-char} +end ${name} ''; + + # Return the list of importable names in a directory. + # Importable name is either + # - a regular file with the nix extension + # - or a directory containing default.nix. + importables = + root: + let + children = builtins.readDir root; + in + (builtins.attrNames ( + lib.attrsets.filterAttrs ( + n: t: + (t == "regular" && (builtins.match ".+\\.nix$" n) != null) + || (t == "directory" && builtins.pathExists (root + "/${n}/default.nix")) + ) children + )); + + # Like callPackageWith but for a while directory. + # The directory should contain nix files, or directories containing default.nix files that define packages. + # The packages are imported with their file basename as the attribute name. + callPackageDirWith = + root: ins: + let + callPkg = lib.callPackageWith all; + outs = builtins.listToAttrs ( + builtins.map (f: { + name = + let + m = (builtins.match "(.+)\\.nix$" f); + in + if m != null then builtins.head m else f; + value = callPkg (root + ("/" + f)) { }; + }) (importables root) + ); + all = ins // outs; + in + outs; } diff --git a/modules/home/default/default.nix b/modules/home/default/default.nix index 11045df..4d700a9 100644 --- a/modules/home/default/default.nix +++ b/modules/home/default/default.nix @@ -119,16 +119,6 @@ in type = types.submodule { options = { enable = mkEnableOption "Enable Spacemacs management"; - rev = mkOption { - default = "11aaddf3ad7e5e3dd3b494d56221efe7b882fd72"; - type = types.str; - description = "Spacemacs revision to check out"; - }; - hash = mkOption { - default = "sha256-uozaV6igLIufvFzPrbt9En1VStDZDkSRRyxH62elK+8="; - type = types.str; - description = "Content hash"; - }; }; }; }; @@ -136,18 +126,14 @@ in }; config = mkIf config.davids.emacs.enable ( let - spacemacs = pkgs.fetchFromGitHub { - owner = "syl20bnr"; - repo = "spacemacs"; - rev = config.davids.emacs.spacemacs.rev; - hash = config.davids.emacs.spacemacs.hash; - }; + spacemacs = davids-dotfiles.packages.spacemacs.${system}; loadSpacemacsInit = f: '' - (setq spacemacs-start-directory "~/.emacs.d/") - (load-file (concat "${spacemacs.out}/" "${f}")) + (setq spacemacs-start-directory "${spacemacs.out}/share/spacemacs/") + (load-file (concat spacemacs-start-directory "${f}")) ''; in { + home.packages = [ spacemacs ]; home.file.".files/bin/ect" = { text = '' #!/bin/sh diff --git a/pkgs/spacemacs/default.nix b/pkgs/spacemacs/default.nix new file mode 100644 index 0000000..7a94f0a --- /dev/null +++ b/pkgs/spacemacs/default.nix @@ -0,0 +1,24 @@ +{ + stdenvNoCC, + fetchFromGitHub, + ... +}: +stdenvNoCC.mkDerivation { + pname = "spacemacs"; + version = "2024-01-20-develop"; + src = fetchFromGitHub { + owner = "syl20bnr"; + repo = "spacemacs"; + rev = "11aaddf3ad7e5e3dd3b494d56221efe7b882fd72"; + hash = "sha256-uozaV6igLIufvFzPrbt9En1VStDZDkSRRyxH62elK+8="; + }; + + patches = [ + ./elpa-in-userdir.diff + ]; + + installPhase = '' + mkdir -p $out/share/spacemacs + cp -r * .lock $out/share/spacemacs + ''; +} diff --git a/pkgs/spacemacs/elpa-in-userdir.diff b/pkgs/spacemacs/elpa-in-userdir.diff new file mode 100644 index 0000000..ee80844 --- /dev/null +++ b/pkgs/spacemacs/elpa-in-userdir.diff @@ -0,0 +1,13 @@ +diff --git a/core/core-configuration-layer.el b/core/core-configuration-layer.el +index 42224cff9..2ba1aa0d4 100644 +--- a/core/core-configuration-layer.el ++++ b/core/core-configuration-layer.el +@@ -136,7 +136,7 @@ subdirectory of ROOT is used." + "Hook executed at the end of configuration loading.") + + (defconst configuration-layer--elpa-root-directory +- (concat spacemacs-start-directory "elpa/") ++ (concat user-emacs-directory "elpa/") + "Spacemacs ELPA root directory.") + + (defconst configuration-layer--rollback-root-directory