From 9e59fd06afed1332912c91db9d8f827d4f3e734e Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Tue, 18 Jun 2024 10:16:26 +0200 Subject: [PATCH] overlays/selfExpr: allow providing options --- pkgs/overlays/selfExpr.nix | 42 +++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/pkgs/overlays/selfExpr.nix b/pkgs/overlays/selfExpr.nix index 391f32c..1be552e 100644 --- a/pkgs/overlays/selfExpr.nix +++ b/pkgs/overlays/selfExpr.nix @@ -1,21 +1,43 @@ { nixpkgsPath ? }: +let + defaultNixpkgsPath = nixpkgsPath; +in + self: super: { selfExpr = let config = builtins.removeAttrs self.config [ "_undeclared" ]; configJson = builtins.toJSON config; - in - self.writeTextFile { - name = "nixpkgs-self"; - destination = "/default.nix"; - text = '' + + getSelfExpr = { + useConfig ? true, + nixpkgsPath ? defaultNixpkgsPath, + ... + }: let + configText = '' + config = (builtins.fromJSON ''' + ${configJson} + ''') // args.config or {}; + ''; + + removedAttrNames = self.lib.optional useConfig "config"; + removedAttrNamesText = builtins.toJSON removedAttrNames; + in '' { ... } @ args: import ${builtins.toString nixpkgsPath} { - config = (builtins.fromJSON ''' - ${configJson} - ''') // args.config or {}; - } // builtins.removeAttrs args [ "config" ] + ${self.lib.optionalString useConfig configText} + } // builtins.removeAttrs args (builtins.fromJSON ''' + ${removedAttrNamesText} + ''') ''; - }; + + mkNixpkgsChannel = args: self.writeTextFile { + name = args.name or "nixpkgs-self"; + destination = "/default.nix"; + text = getSelfExpr args; + } // { + __functor = _: args: mkNixpkgsChannel args; + }; + in mkNixpkgsChannel {}; }