From 2f84ce13c41715a85eb71dbebd929ef00a4a02ab Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Fri, 10 Feb 2023 19:40:13 +0200 Subject: [PATCH] flake.nix: modularize (pt 1) --- flake.nix | 77 ++++++++++------------------------------ flake/apps.nix | 21 +++++++++++ flake/legacyPackages.nix | 19 ++++++++++ flake/packages.nix | 65 +++++++++++++++++++++++++++++++++ 4 files changed, 124 insertions(+), 58 deletions(-) create mode 100644 flake/apps.nix create mode 100644 flake/legacyPackages.nix create mode 100644 flake/packages.nix diff --git a/flake.nix b/flake.nix index 2483c76..7f79390 100644 --- a/flake.nix +++ b/flake.nix @@ -23,81 +23,42 @@ flake-parts.lib.mkFlake {inherit inputs;} { systems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"]; + imports = [ + # add lib to module args + {_module.args = {inherit (nixpkgs) lib;};} + ./flake/apps.nix + ./flake/legacyPackages.nix + ./flake/packages.nix + ]; + flake = { lib = { inherit (import ./lib/stdlib-extended.nix nixpkgs.lib) nvim; inherit neovimConfiguration; }; + nixosModules.default = { + imports = [./lib/hm-module.nix]; + nixpkgs.overlays = [ + inputs.tidalcycles.overlays.default + inputs.self.overlays.default + ]; + }; + overlays.default = final: prev: { inherit neovimConfiguration; neovim-nix = buildPkg prev [nixConfig]; neovim-maximal = buildPkg prev [maximalConfig]; neovim-tidal = buildPkg prev [tidalConfig]; }; - - nixosModules.hm-module = { - imports = [ - ./lib/hm.nix - # {nixpkgs.overlays = [inputs.self.overlays.default];} what? - ]; - }; }; perSystem = { - system, - self', + config, + pkgs, ... }: { - legacyPackages = import nixpkgs { - inherit system; - overlays = [ - inputs.tidalcycles.overlays.default - (final: prev: { - rnix-lsp = inputs.rnix-lsp.defaultPackage.${system}; - nil = inputs.nil.packages.${system}.default; - }) - ]; - }; - - apps = - { - nix.program = lib.getExe self'.packages.nix; - maximal.program = lib.getExe self'.packages.maximal; - default = self'.apps.nix; - } - // ( - if !(builtins.elem system ["aarch64-darwin" "x86_64-darwin"]) - then { - tidal.program = lib.getExe self'.packages.tidal; - } - else {} - ); - - devShells.default = self'.legacyPackages.mkShell {nativeBuildInputs = [self'.packages.nix];}; - - packages = let - docs = import ./docs { - pkgs = self'.legacyPackages; - nmdSrc = inputs.nmd; - }; - in - { - # Documentation - docs = docs.manual.html; - docs-html = docs.manual.html; - docs-manpages = docs.manPages; - docs-json = docs.options.json; - - # Available Configurations - nix = buildPkg self'.legacyPackages [nixConfig]; - maximal = buildPkg self'.legacyPackages [maximalConfig]; - } - // ( - if !(builtins.elem system ["aarch64-darwin" "x86_64-darwin"]) - then {tidal = buildPkg self'.legacyPackages [tidalConfig];} - else {} - ); + devShells.default = pkgs.mkShell {nativeBuildInputs = [config.packages.nix];}; }; }; diff --git a/flake/apps.nix b/flake/apps.nix new file mode 100644 index 0000000..6b53adf --- /dev/null +++ b/flake/apps.nix @@ -0,0 +1,21 @@ +{lib, ...}: { + perSystem = { + system, + config, + ... + }: { + apps = + { + nix.program = lib.getExe config.packages.nix; + maximal.program = lib.getExe config.packages.maximal; + default = config.apps.nix; + } + // ( + if !(builtins.elem system ["aarch64-darwin" "x86_64-darwin"]) + then { + tidal.program = lib.getExe config.packages.tidal; + } + else {} + ); + }; +} diff --git a/flake/legacyPackages.nix b/flake/legacyPackages.nix new file mode 100644 index 0000000..d6fb73c --- /dev/null +++ b/flake/legacyPackages.nix @@ -0,0 +1,19 @@ +{inputs, ...}: { + perSystem = { + system, + inputs', + ... + }: { + legacyPackages = import inputs.nixpkgs { + inherit system; + overlays = [ + inputs.tidalcycles.overlays.default + inputs.self.overlays.default + (_: _: { + rnix-lsp = inputs'.rnix-lsp.defaultPackage; + nil = inputs'.nil.packages.default; + }) + ]; + }; + }; +} diff --git a/flake/packages.nix b/flake/packages.nix new file mode 100644 index 0000000..1aff130 --- /dev/null +++ b/flake/packages.nix @@ -0,0 +1,65 @@ +{inputs, ...}: { + # imports = [ + # inputs.flake-parts.flakeModules.easyOverlay + # ]; + + perSystem = { + system, + pkgs, + config, + ... + }: let + # inherit (import ../extra.nix inputs) neovimConfiguration mainConfig; + + # tidalConfig = { + # config.vim.tidal.enable = true; + # }; + + # buildPkg = pkgs: modules: + # (neovimConfiguration { + # inherit pkgs modules; + # }) + # .neovim; + + # nixConfig = mainConfig false; + # maximalConfig = mainConfig true; + in { + # overlayAttrs = + # { + # inherit neovimConfiguration; + # neovim-nix = config.packages.nix; + # neovim-maximal = config.packages.maximal; + # } + # // ( + # if !(builtins.elem system ["aarch64-darwin" "x86_64-darwin"]) + # then {neovim-tidal = config.packages.tidal;} + # else {} + # ); + + packages = let + docs = import ../docs { + inherit pkgs; + nmdSrc = inputs.nmd; + }; + in + { + # Documentation + docs = docs.manual.html; + docs-html = docs.manual.html; + docs-manpages = docs.manPages; + docs-json = docs.options.json; + + # nvim configs + # nix = buildPkg pkgs [nixConfig]; + # maximal = buildPkg pkgs [maximalConfig]; + nix = config.legacyPackages.neovim-nix; + maximal = config.legacyPackages.neovim-maximal; + } + // ( + if !(builtins.elem system ["aarch64-darwin" "x86_64-darwin"]) + # then {tidal = buildPkg pkgs [tidalConfig];} + then {tidal = config.legacyPackages.neovim-tidal;} + else {} + ); + }; +}