From 51e8fafec62d6c45dd634267a62328a9e5441e22 Mon Sep 17 00:00:00 2001 From: reo101 Date: Sun, 4 Aug 2024 03:10:58 +0300 Subject: [PATCH] feat(overlays)!: redefine in terms of `createThings` --- flake.nix | 9 +- modules/flake/overlays/default.nix | 65 ++++++++++++++ overlays/README.md | 5 ++ overlays/default.nix | 87 ------------------- overlays/modifications/default.nix | 75 ++++++++++++++++ .../offline-mode-prism-launcher.diff | 0 6 files changed, 149 insertions(+), 92 deletions(-) create mode 100644 modules/flake/overlays/default.nix create mode 100644 overlays/README.md delete mode 100644 overlays/default.nix create mode 100644 overlays/modifications/default.nix rename overlays/{ => modifications}/offline-mode-prism-launcher.diff (100%) diff --git a/flake.nix b/flake.nix index 680e12a..1c52a79 100644 --- a/flake.nix +++ b/flake.nix @@ -20,6 +20,7 @@ ./modules/flake/deploy ./modules/flake/topology ./modules/flake/packages + ./modules/flake/overlays ]; perSystem = { lib, pkgs, system, ... }: { @@ -49,15 +50,13 @@ # Automatic packages, see `./modules/flake/packages/default.nix` autoPackages.enable = true; + # Automatic overlays, see `./modules/flake/overlays/default.nix` + autoOverlays.enable = true; + # Templates templates = import ./templates { inherit inputs; }; - - # Overlays - overlays = import ./overlays { - inherit inputs; - }; }; }); diff --git a/modules/flake/overlays/default.nix b/modules/flake/overlays/default.nix new file mode 100644 index 0000000..ae9cb21 --- /dev/null +++ b/modules/flake/overlays/default.nix @@ -0,0 +1,65 @@ +{ lib, config, self, inputs, ... }: + +let + inherit (config.lib) + createThings; +in +let + createOverlays = baseDir: + createThings { + inherit baseDir; + thingType = "overlay"; + }; +in +{ + options = let + inherit (lib) types; + in { + flake.autoOverlays = lib.mkOption { + description = '' + Automagically generate overlays from walking directories with Nix files + ''; + type = types.submodule (submodule: { + options = { + enable = lib.mkEnableOption "Automatic overlays extraction"; + dir = lib.mkOption { + description = '' + Base directory of the contained overlays + ''; + type = types.path; + default = "${self}/overlays"; + defaultText = ''''${self}/overlays''; + }; + result = lib.mkOption { + description = '' + The resulting automatic overlays + ''; + type = types.attrsOf types.unspecified; + readOnly = true; + internal = true; + default = + lib.optionalAttrs + config.flake.autoOverlays.enable + (createOverlays config.flake.autoOverlays.dir); + }; + }; + }); + default = {}; + }; + }; + + config = { + flake = let + overlays = + lib.pipe + config.flake.autoOverlays.result + [ + (lib.mapAttrs + (name: overlay: + overlay)) + ]; + in { + inherit overlays; + }; + }; +} diff --git a/overlays/README.md b/overlays/README.md new file mode 100644 index 0000000..3afce3a --- /dev/null +++ b/overlays/README.md @@ -0,0 +1,5 @@ +Add your reusable overlays to this directory () + +These are considered overlays: +- files, ending in `.nix` (excluding `default.nix`) +- directories, containing `default.nix` diff --git a/overlays/default.nix b/overlays/default.nix deleted file mode 100644 index 3d449b3..0000000 --- a/overlays/default.nix +++ /dev/null @@ -1,87 +0,0 @@ -# This file defines overlays -{ inputs, ... }: -{ - # This one brings our custom packages - # BUG: causes infinite recursion - # additions = final: prev: inputs.self.packages.${prev.system}; - - # This one contains whatever you want to overlay - # You can change versions, add patches, set compilation flags, anything really. - # https://nixos.wiki/wiki/Overlays - modifications = final: prev: { - # example = prev.example.overrideAttrs (oldAttrs: rec { - # ... - # }); - - lib = prev.lib // { - maintainers = { - reo101 = { - name = "Pavel Atanasov"; - email = "pavel.atanasov2001@gmail.com"; - github = "reo101"; - githubId = "37866329"; - keys = [ - { - fingerprint = "8A29 0250 C775 7813 1DD1 DC57 7275 0ABE E181 26D0"; - } - ]; - }; - }; - }; - - nix-monitored = inputs.nix-monitored.packages.${prev.system}.default.override { - nix = prev.nix; - nix-output-monitor = prev.nix-output-monitor; - }; - - nixVersions = prev.nixVersions // { - monitored = - final.lib.flip final.lib.concatMapAttrs prev.nixVersions (version: package: - final.lib.optionalAttrs - (final.lib.and - (final.lib.all (prefix: ! final.lib.hasPrefix prefix version) - # TODO: smarter filtering of deprecated and non-packages - [ - "nix_2_4" - "nix_2_5" - "nix_2_6" - "nix_2_7" - "nix_2_8" - "nix_2_9" - "nix_2_10" - "nix_2_11" - "nix_2_12" - "nix_2_13" - "nix_2_14" - "nix_2_15" - "nix_2_16" - "nix_2_17" - "unstable" - ]) - (final.lib.isDerivation package)) - { - # NOTE: `lib.getBin` is needed, otherwise the `-dev` output is chosen - "${version}" = final.lib.getBin (inputs.nix-monitored.packages.${final.system}.default.override { - nix = package; - nix-output-monitor = prev.nix-output-monitor; - }); - } - ); - }; - - river = prev.river.overrideAttrs (oldAttrs: rec { - xwaylandSupport = true; - }); - - discord = prev.discord.override { - withOpenASAR = true; - withVencord = true; - }; - - prismlauncher = prev.prismlauncher.overrideAttrs (oldAttrs: { - patches = (oldAttrs.patches or [ ]) ++ [ - ./offline-mode-prism-launcher.diff - ]; - }); - }; -} diff --git a/overlays/modifications/default.nix b/overlays/modifications/default.nix new file mode 100644 index 0000000..1281a8e --- /dev/null +++ b/overlays/modifications/default.nix @@ -0,0 +1,75 @@ +{ inputs, ... }: + +final: prev: +{ + lib = prev.lib // { + maintainers = { + reo101 = { + name = "Pavel Atanasov"; + email = "pavel.atanasov2001@gmail.com"; + github = "reo101"; + githubId = "37866329"; + keys = [ + { + fingerprint = "8A29 0250 C775 7813 1DD1 DC57 7275 0ABE E181 26D0"; + } + ]; + }; + }; + }; + + nix-monitored = inputs.nix-monitored.packages.${prev.system}.default.override { + nix = prev.nix; + nix-output-monitor = prev.nix-output-monitor; + }; + + nixVersions = prev.nixVersions // { + monitored = + final.lib.flip final.lib.concatMapAttrs prev.nixVersions (version: package: + final.lib.optionalAttrs + (final.lib.and + (final.lib.all (prefix: ! final.lib.hasPrefix prefix version) + # TODO: smarter filtering of deprecated and non-packages + [ + "nix_2_4" + "nix_2_5" + "nix_2_6" + "nix_2_7" + "nix_2_8" + "nix_2_9" + "nix_2_10" + "nix_2_11" + "nix_2_12" + "nix_2_13" + "nix_2_14" + "nix_2_15" + "nix_2_16" + "nix_2_17" + "unstable" + ]) + (final.lib.isDerivation package)) + { + # NOTE: `lib.getBin` is needed, otherwise the `-dev` output is chosen + "${version}" = final.lib.getBin (inputs.nix-monitored.packages.${final.system}.default.override { + nix = package; + nix-output-monitor = prev.nix-output-monitor; + }); + } + ); + }; + + river = prev.river.overrideAttrs (oldAttrs: rec { + xwaylandSupport = true; + }); + + discord = prev.discord.override { + withOpenASAR = true; + withVencord = true; + }; + + prismlauncher = prev.prismlauncher.overrideAttrs (oldAttrs: { + patches = (oldAttrs.patches or [ ]) ++ [ + ./offline-mode-prism-launcher.diff + ]; + }); +} diff --git a/overlays/offline-mode-prism-launcher.diff b/overlays/modifications/offline-mode-prism-launcher.diff similarity index 100% rename from overlays/offline-mode-prism-launcher.diff rename to overlays/modifications/offline-mode-prism-launcher.diff