From dfcb303eef8a59f1e2f451fd15745a63acd89b02 Mon Sep 17 00:00:00 2001 From: xenia Date: Fri, 6 Jun 2025 00:24:26 -0400 Subject: [PATCH] flake: rework the nixpkgs init code --- flake.nix | 70 ++++++++++++++++++++++++++++--------------------- lib/overlay.nix | 3 +++ overlay.nix | 4 +-- 3 files changed, 44 insertions(+), 33 deletions(-) create mode 100644 lib/overlay.nix diff --git a/flake.nix b/flake.nix index 797fafe..e60be8d 100644 --- a/flake.nix +++ b/flake.nix @@ -22,6 +22,10 @@ (import "${lix-module}/overlay.nix" { inherit lix; }) ]; forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed; + libVersionInfoOverlay = import "${nixpkgs}/lib/flake-version-info.nix" nixpkgs; + # this is taken from upstream. if upstream changes, the code here needs to be updated to match + addLibVersionInfo = lib: lib.extend libVersionInfoOverlay; + lib-base = addLibVersionInfo (import "${nixpkgs}/lib"); in { # we don't just use nix.registry.whatever.flake = self # the reason for this is to be able to handle a flake.lock containing an entry for this @@ -42,8 +46,41 @@ # the nix path entry for self meta.path-entry = "dragnpkgs-unstable=flake:dragnpkgs-unstable"; - lib = nixpkgs.lib.extend (final: prev: { - licenses = prev.licenses // { fyptl = import ./lib/licenses/fyptl.nix; }; + lib = (lib-base.extend (import ./lib/overlay.nix)).extend (final: prev: { + # initializes regular upstream nixpkgs with the given arguments + nixpkgs-custom = { system, ... } @ args: ( + (import "${nixpkgs}" args).extend (final: prev: { + lib = addLibVersionInfo prev.lib; + }) + ); + + # initializes dragnpkgs with its overlays and default config using the given arguments + dragnpkgs-custom = { system, ... } @ args: let + unsafeConf = if builtins.hasAttr "extraBuiltins" builtins then ( + let conf = builtins.extraBuiltins; in + if builtins.isAttrs conf then conf else {} + ) else {}; + possiblyCommitCrimes = + if + builtins.hasAttr "dragnpkgs" unsafeConf && + builtins.isAttrs unsafeConf.dragnpkgs && + builtins.hasAttr "possiblyCommitCrimes" unsafeConf.dragnpkgs && + builtins.isBool unsafeConf.dragnpkgs.possiblyCommitCrimes + then + unsafeConf.dragnpkgs.possiblyCommitCrimes + else + false; + in + final.nixpkgs-custom (args // { + overlays = overlays ++ (args.overlays or []); + config = (args.config or {}) // { + allowlistedLicenses = (final.optionals + possiblyCommitCrimes + [ final.licenses.fyptl ]) ++ (args.config.allowlistedLicenses or []); + }; + }); + + nixos = import "${nixpkgs}/nixos/lib" { lib = final; }; nixosSystem = args: import "${nixpkgs}/nixos/lib/eval-config.nix" ( @@ -192,36 +229,9 @@ }); legacyPackages = forAllSystems (system: - let - unsafeConf = if builtins.hasAttr "extraBuiltins" builtins then ( - let conf = builtins.extraBuiltins; in - if builtins.isAttrs conf then conf else {} - ) else {}; - possiblyCommitCrimes = - if - builtins.hasAttr "dragnpkgs" unsafeConf && - builtins.isAttrs unsafeConf.dragnpkgs && - builtins.hasAttr "possiblyCommitCrimes" unsafeConf.dragnpkgs && - builtins.isBool unsafeConf.dragnpkgs.possiblyCommitCrimes - then - unsafeConf.dragnpkgs.possiblyCommitCrimes - else - false; - in - nixpkgs.legacyPackages.${system}.appendOverlays (overlays ++ - [(final: prev: { - stdenv = prev.stdenv.override { - config = prev.config // { - allowlistedLicenses = final.lib.optionals - possiblyCommitCrimes - [ final.lib.licenses.fyptl ]; - }; - }; - })]) + self.lib.dragnpkgs-custom { inherit system; } ); - nixosModules = nixpkgs.nixosModules; - templates = { default = { path = ./templates/default; diff --git a/lib/overlay.nix b/lib/overlay.nix new file mode 100644 index 0000000..1d12fb9 --- /dev/null +++ b/lib/overlay.nix @@ -0,0 +1,3 @@ +final: prev: { + licenses = prev.licenses // { fyptl = import ./licenses/fyptl.nix; }; +} diff --git a/overlay.nix b/overlay.nix index d94c7a1..864abe0 100644 --- a/overlay.nix +++ b/overlay.nix @@ -1,7 +1,5 @@ final: prev: { - lib = prev.lib.extend (lfinal: lprev: { - licenses = lprev.licenses // { fyptl = import ./lib/licenses/fyptl.nix; }; - }); + lib = prev.lib.extend (import ./lib/overlay.nix); fetchFromSteam = prev.callPackage ./lib/fetchsteam {}; fetchb4 = prev.callPackage ./lib/fetchb4 {};