From 9e4fdb00e3abce13502df6620d2cd050ffb493b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Mon, 12 Feb 2024 10:10:32 +0100 Subject: [PATCH] feat(flake): add module for overlays --- flake.nix | 45 ---------- modules/nixpkgs.nix | 60 +++++++++++++ modules/profiles/base.nix | 90 ++++++++++++++++++++ modules/programs/hyprland/default.nix | 3 + modules/programs/nvim/default.nix | 28 ++++-- modules/programs/nvim/plugins/coding.nix | 21 ++++- modules/programs/nvim/plugins/treesitter.nix | 2 +- modules/programs/nvim/plugins/ui.nix | 13 ++- overlays/builders.nix | 62 -------------- overlays/default.nix | 4 - overlays/fixes.nix | 16 ---- overlays/lib.nix | 5 -- overlays/packages.nix | 10 --- overlays/vimPlugins.nix | 63 -------------- overlays/wayland.nix | 25 ------ 15 files changed, 201 insertions(+), 246 deletions(-) create mode 100644 modules/nixpkgs.nix delete mode 100644 overlays/builders.nix delete mode 100644 overlays/default.nix delete mode 100644 overlays/fixes.nix delete mode 100644 overlays/lib.nix delete mode 100644 overlays/packages.nix delete mode 100644 overlays/vimPlugins.nix delete mode 100644 overlays/wayland.nix diff --git a/flake.nix b/flake.nix index 575b264..1e01e37 100644 --- a/flake.nix +++ b/flake.nix @@ -62,31 +62,6 @@ }; outputs = inputs@{ self, flake-parts, ... }: - let - defaultOverlays = [ - inputs.hypr-contrib.overlays.default - self.overlays.default - ]; - - finalOverlays = defaultOverlays ++ [ - ( - _: prev: { - master = import inputs.master { - inherit (prev) system; - overlays = defaultOverlays; - }; - stable = import inputs.stable { - inherit (prev) system; - overlays = defaultOverlays; - }; - nur = import inputs.nur { - pkgs = prev; - nurpkgs = prev; - }; - } - ) - ]; - in flake-parts.lib.mkFlake { inherit inputs; } { imports = [ inputs.pre-commit-hooks.flakeModule @@ -95,12 +70,6 @@ systems = [ "x86_64-linux" ]; perSystem = { config, self', inputs', pkgs, system, ... }: { - _module.args.pkgs = - import inputs.nixpkgs { - inherit system; - overlays = finalOverlays; - }; - devshells.default = { devshell.startup.pre-commit-hook.text = config.pre-commit.installationScript; commands = [ @@ -155,20 +124,12 @@ legacyPackages = pkgs; - packages = - self.lib.filterAttrs (_: self.lib.isDerivation) - (self.overlays.default pkgs pkgs); }; flake = { lib = inputs.nixpkgs.lib.extend (self: _: { my = import ./lib { lib = self; }; }); - overlays.default = import ./overlays { - inherit inputs; - inherit (self) lib; - }; - nixosConfigurations = self.lib.my.mapModules (path: self.lib.nixosSystem { inherit (self) lib; @@ -178,12 +139,6 @@ modules = [ ./modules - { - nixpkgs = { - overlays = finalOverlays; - config.allowUnfree = true; - }; - } { home-manager = { useGlobalPkgs = true; diff --git a/modules/nixpkgs.nix b/modules/nixpkgs.nix new file mode 100644 index 0000000..db8228e --- /dev/null +++ b/modules/nixpkgs.nix @@ -0,0 +1,60 @@ +{ config, lib, ... }: + +with lib; +let + cfg = config.my.nixpkgs; + + overlayType = mkOptionType { + name = "nixpkgs-overlay"; + description = "nixpkgs overlay"; + check = lib.isFunction; + merge = lib.mergeOneOption; + }; +in +{ + options.my.nixpkgs = { + overlays = mkOption { + default = [ ]; + type = types.listOf overlayType; + example = literalExpression + '' + [ + (self: super: { + openssh = super.openssh.override { + hpnSupport = true; + kerberos = self.libkrb5; + }; + }) + ] + ''; + }; + channels = mkOption { + default = { }; + example = literalExpression '' + { + stable = inputs.nixpkgs-stable; + } + ''; + type = with types; attrsOf package; + }; + overlaysForAllChannels = mkEnableOption "apply overlays for all channels"; + }; + + config.nixpkgs = { + overlays = + let + channelOverlays = _: prev: + mapAttrs + (_: value: + import value { + inherit (prev) system; + overlays = optional cfg.overlaysForAllChannels cfg.overlays; + } + ) + cfg.channels; + in + cfg.overlays ++ [ channelOverlays ]; + + config.allowUnfree = true; + }; +} diff --git a/modules/profiles/base.nix b/modules/profiles/base.nix index f7abc2e..a811050 100644 --- a/modules/profiles/base.nix +++ b/modules/profiles/base.nix @@ -1,6 +1,7 @@ { config , lib , pkgs +, inputs , ... }: @@ -88,6 +89,95 @@ in time.timeZone = "Europe/Berlin"; my = { + nixpkgs = { + overlays = [ + (_: prev: + { + nur = import inputs.nur { + pkgs = prev; + nurpkgs = prev; + }; + } + ) + ( + final: _: + + with final.lib; + rec { + fishFile = + { name + , destination + , content + , checkPhase ? null + }: + final.writeTextFile { + inherit name destination; + executable = true; + allowSubstitutes = true; + preferLocalBuild = false; + text = '' + #!${getExe final.fish} + + ${content} + ''; + + checkPhase = + if checkPhase == null then '' + runHook preCheck + ${getExe final.fish} -n "$target" + runHook postCheck + '' + else checkPhase; + }; + + writeFishApplication = + { name + , text + , completions ? null + , runtimeInputs ? [ ] + , checkPhase ? null + }: + let + runtimeHeader = optionalString (runtimeInputs != [ ]) + ''export PATH="${makeBinPath runtimeInputs}:$PATH"''; + + script = fishFile { + inherit checkPhase; + name = "${name}_script"; + destination = "/bin/${name}"; + content = concatLines [ runtimeHeader text ]; + }; + completions_file = fishFile { + inherit checkPhase; + name = "${name}_completions"; + destination = "/share/fish/vendor_completions.d/${name}.fish"; + content = concatLines [ runtimeHeader completions ]; + }; + in + final.symlinkJoin { + inherit name; + paths = [ + script + ] ++ optional (completions != null) completions_file; + }; + } + ) + ( + _: prev: { + xorg = prev.xorg // { + lndir = prev.xorg.lndir.overrideAttrs (_: { + meta.mainProgram = "lndir"; + }); + }; + } + ) + ]; + channels = { + master = inputs.master; + stable = inputs.stable; + }; + }; + bin.enable = true; shell = { abbreviations = { diff --git a/modules/programs/hyprland/default.nix b/modules/programs/hyprland/default.nix index 87de8c1..1593b71 100644 --- a/modules/programs/hyprland/default.nix +++ b/modules/programs/hyprland/default.nix @@ -43,6 +43,9 @@ in config = mkIf cfg.enable { my = { + nixpkgs.overlays = [ + inputs.hypr-contrib.overlays.default + ]; programs = { wallpaper.enable = true; kitty.enable = true; diff --git a/modules/programs/nvim/default.nix b/modules/programs/nvim/default.nix index 721b184..5c4840f 100644 --- a/modules/programs/nvim/default.nix +++ b/modules/programs/nvim/default.nix @@ -10,15 +10,27 @@ in options.my.programs.nvim.enable = mkEnableOption "nvim"; config = mkIf cfg.enable { - home-manager.users.moritz = { - home.packages = with pkgs; [ - ( - if config.my.programs.hyprland.enable - then neovide-hyprland - else neovide - ) - ]; + my.nixpkgs.overlays = [ + ( + _: prev: + with lib.my; + { + vimPlugins = prev.vimPlugins // { + nvim-treesitter = prev.vimPlugins.nvim-treesitter.overrideAttrs (_: { + version = mkVersionInput inputs.nvim-treesitter; + src = inputs.nvim-treesitter; + }); + # HACK: to fix error in nixpkgs version of nvim-lspconfig + nvim-lspconfig = prev.vimPlugins.nvim-lspconfig.overrideAttrs (_: { + version = mkVersionInput inputs.nvim-lspconfig; + src = inputs.nvim-lspconfig; + }); + }; + } + ) + ]; + home-manager.users.moritz = { programs.neovim = { enable = true; package = inputs.neovim-nightly-overlay.packages.${pkgs.system}.default; diff --git a/modules/programs/nvim/plugins/coding.nix b/modules/programs/nvim/plugins/coding.nix index 358f578..068f751 100644 --- a/modules/programs/nvim/plugins/coding.nix +++ b/modules/programs/nvim/plugins/coding.nix @@ -1,4 +1,4 @@ -{ pkgs, lib, ... }: +{ pkgs, lib, inputs, ... }: with builtins; { @@ -115,7 +115,10 @@ with builtins; conf = readFile ./lua/nvim-lspconfig.lua; dependencies = [ { - plugin = null-ls-nvim; + plugin = pkgs.vimPlugins.null-ls-nvim.overrideAttrs (_: { + version = lib.my.mkVersionInput inputs.none-ls-nvim; + src = inputs.none-ls-nvim; + }); conf = readFile ./lua/null-ls-nvim.lua; dependencies = [ { plugin = which-key-nvim; } @@ -144,7 +147,13 @@ with builtins; { plugin = dressing-nvim; } ]; } - { plugin = actions-preview-nvim; } + { + plugin = pkgs.vimUtils.buildVimPlugin { + pname = "actions-preview-nvim"; + version = lib.my.mkVersionInput inputs.actions-preview-nvim; + src = inputs.actions-preview-nvim; + }; + } ]; } { @@ -325,7 +334,11 @@ with builtins; ]; } { - plugin = nvim-puppeteer; + plugin = pkgs.vimUtils.buildVimPlugin { + pname = "nvim-puppeteer"; + version = lib.my.mkVersionInput inputs.nvim-puppeteer; + src = inputs.nvim-puppeteer; + }; lazy = false; # NOTE: plugin lazy-loads itself. } { diff --git a/modules/programs/nvim/plugins/treesitter.nix b/modules/programs/nvim/plugins/treesitter.nix index 1fc7cae..31196bd 100644 --- a/modules/programs/nvim/plugins/treesitter.nix +++ b/modules/programs/nvim/plugins/treesitter.nix @@ -1,4 +1,4 @@ -{ pkgs, config, ... }: +{ pkgs, ... }: with builtins; { diff --git a/modules/programs/nvim/plugins/ui.nix b/modules/programs/nvim/plugins/ui.nix index 92e5fd5..90b87f2 100644 --- a/modules/programs/nvim/plugins/ui.nix +++ b/modules/programs/nvim/plugins/ui.nix @@ -1,4 +1,4 @@ -{ pkgs, ... }: +{ pkgs, lib, inputs, ... }: with builtins; { @@ -21,12 +21,19 @@ with builtins; opts = { }; } { - plugin = statuscol-nvim; + plugin = pkgs.vimPlugins.statuscol-nvim.overrideAttrs (_: { + version = lib.my.mkVersionInput inputs.statuscol-nvim; + src = inputs.statuscol-nvim; + }); event = [ "VeryLazy" ]; conf = readFile ./lua/statuscol-nvim.lua; } { - plugin = smartcolumn-nvim; + plugin = pkgs.vimUtils.buildVimPlugin { + pname = "smartcolumn-nvim"; + version = lib.my.mkVersionInput inputs.smartcolumn-nvim; + src = inputs.smartcolumn-nvim; + }; event = [ "BufReadPost" "BufNewFile" ]; opts = { colorcolumn = "120"; diff --git a/overlays/builders.nix b/overlays/builders.nix deleted file mode 100644 index 359a4af..0000000 --- a/overlays/builders.nix +++ /dev/null @@ -1,62 +0,0 @@ -_: - -final: _: -with final.lib; -rec { - fishFile = - { name - , destination - , content - , checkPhase ? null - }: - final.writeTextFile { - inherit name destination; - executable = true; - allowSubstitutes = true; - preferLocalBuild = false; - text = '' - #!${getExe final.fish} - - ${content} - ''; - - checkPhase = - if checkPhase == null then '' - runHook preCheck - ${getExe final.fish} -n "$target" - runHook postCheck - '' - else checkPhase; - }; - - writeFishApplication = - { name - , text - , completions ? null - , runtimeInputs ? [ ] - , checkPhase ? null - }: - let - runtimeHeader = optionalString (runtimeInputs != [ ]) - ''export PATH="${makeBinPath runtimeInputs}:$PATH"''; - - script = fishFile { - inherit checkPhase; - name = "${name}_script"; - destination = "/bin/${name}"; - content = concatLines [ runtimeHeader text ]; - }; - completions_file = fishFile { - inherit checkPhase; - name = "${name}_completions"; - destination = "/share/fish/vendor_completions.d/${name}.fish"; - content = concatLines [ runtimeHeader completions ]; - }; - in - final.symlinkJoin { - inherit name; - paths = [ - script - ] ++ optional (completions != null) completions_file; - }; -} diff --git a/overlays/default.nix b/overlays/default.nix deleted file mode 100644 index 6713493..0000000 --- a/overlays/default.nix +++ /dev/null @@ -1,4 +0,0 @@ -{ lib, ... }@args: - -lib.composeManyExtensions - (lib.my.mapModules' (file: import file args) ./.) diff --git a/overlays/fixes.nix b/overlays/fixes.nix deleted file mode 100644 index 8bfb9ba..0000000 --- a/overlays/fixes.nix +++ /dev/null @@ -1,16 +0,0 @@ -{ lib, ... }: - -final: prev: { - # python-poetry/poetry#5929 - poetry = final.symlinkJoin { - name = "poetry"; - paths = [ prev.poetry ]; - postBuild = - let - regex = "s/'([a-z]*[[:blank:]][a-z]*)''/\1'/g"; - in - '' - ${lib.getExe final.gnused} -i -E "${regex}" "$out/share/fish/vendor_completions.d/poetry.fish" - ''; - }; -} diff --git a/overlays/lib.nix b/overlays/lib.nix deleted file mode 100644 index 0d1a251..0000000 --- a/overlays/lib.nix +++ /dev/null @@ -1,5 +0,0 @@ -{ lib, ... }: - -_: _: { - inherit lib; -} diff --git a/overlays/packages.nix b/overlays/packages.nix deleted file mode 100644 index e40443b..0000000 --- a/overlays/packages.nix +++ /dev/null @@ -1,10 +0,0 @@ -_: - -_: prev: -{ - xorg = prev.xorg // { - lndir = prev.xorg.lndir.overrideAttrs (_: { - meta.mainProgram = "lndir"; - }); - }; -} diff --git a/overlays/vimPlugins.nix b/overlays/vimPlugins.nix deleted file mode 100644 index c40a045..0000000 --- a/overlays/vimPlugins.nix +++ /dev/null @@ -1,63 +0,0 @@ -{ inputs, lib }: - -_: prev: -with lib.my; -{ - vimPlugins = prev.vimPlugins // { - smartcolumn-nvim = prev.vimUtils.buildVimPlugin { - pname = "smartcolumn-nvim"; - version = mkVersionInput inputs.smartcolumn-nvim; - src = inputs.smartcolumn-nvim; - }; - - telekasten-nvim = prev.vimUtils.buildVimPlugin { - pname = "telekasten-nvim"; - version = mkVersionInput inputs.telekasten-nvim; - src = inputs.telekasten-nvim; - }; - - actions-preview-nvim = prev.vimUtils.buildVimPlugin { - pname = "actions-preview-nvim"; - version = mkVersionInput inputs.actions-preview-nvim; - src = inputs.actions-preview-nvim; - }; - - nvim-treesitter = prev.vimPlugins.nvim-treesitter.overrideAttrs (_: { - version = mkVersionInput inputs.nvim-treesitter; - src = inputs.nvim-treesitter; - }); - - statuscol-nvim = prev.vimPlugins.statuscol-nvim.overrideAttrs (_: { - version = mkVersionInput inputs.statuscol-nvim; - src = inputs.statuscol-nvim; - }); - - # HACK: to fix error in nixpkgs version of nvim-lspconfig - nvim-lspconfig = prev.vimPlugins.nvim-lspconfig.overrideAttrs (_: { - version = mkVersionInput inputs.nvim-lspconfig; - src = inputs.nvim-lspconfig; - }); - - nvim-puppeteer = prev.vimUtils.buildVimPlugin { - pname = "nvim-puppeteer"; - version = mkVersionInput inputs.nvim-puppeteer; - src = inputs.nvim-puppeteer; - }; - - null-ls-nvim = prev.vimPlugins.null-ls-nvim.overrideAttrs (_: { - version = mkVersionInput inputs.none-ls-nvim; - src = inputs.none-ls-nvim; - }); - - neotest-python = prev.vimPlugins.neotest-python.overrideAttrs (_: { - version = mkVersionInput inputs.neotest-python; - src = inputs.neotest-python; - }); - - gen-nvim = prev.vimUtils.buildVimPlugin { - pname = "gen-nvim"; - version = mkVersionInput inputs.gen-nvim; - src = inputs.gen-nvim; - }; - }; -} diff --git a/overlays/wayland.nix b/overlays/wayland.nix deleted file mode 100644 index dc0f140..0000000 --- a/overlays/wayland.nix +++ /dev/null @@ -1,25 +0,0 @@ -_: - -final: prev: { - neovide-hyprland = final.symlinkJoin { - name = "neovide-hyprland-${final.neovide.version}"; - paths = [ final.neovide ]; - nativeBuildInputs = [ final.makeWrapper ]; - postBuild = '' - rm $out/bin/neovide - makeWrapper ${final.neovide}/bin/neovide $out/bin/neovide --set WINIT_UNIX_BACKEND x11 - ''; - meta = final.neovide.meta // { - mainProgram = "neovide"; - }; - }; - logseq-wayland = prev.symlinkJoin { - name = "logseq-wayland"; - paths = [ prev.logseq ]; - nativeBuildInputs = [ prev.makeWrapper ]; - postBuild = '' - wrapProgram $out/bin/logseq \ - --add-flags "--socket=wayland --enable-features=UseOzonePlatform --ozone-platform=wayland" - ''; - }; -}