Last active
March 4, 2026 13:16
-
-
Save DavidArsene/67cade0eb2629d875712c6283ae1557d to your computer and use it in GitHub Desktop.
Wrap a nixpkgs flake input to always have allowUnfree enabled.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| Wrap a nixpkgs flake input to always have allowUnfree enabled. | |
| Usage: | |
| inputs = { | |
| nixpkgs.url = "git+https://gist.github.com/DavidArsene/67cade0eb2629d875712c6283ae1557d"; | |
| nixpkgs.inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; | |
| }; | |
| */ | |
| { | |
| outputs = | |
| { self, nixpkgs }: | |
| let | |
| lib = nixpkgs.lib; | |
| forAllSystems = lib.genAttrs lib.systems.flakeExposed; | |
| betterDefaultConfig = { | |
| allowAliases = false; | |
| allowUnfree = true; | |
| allowVariants = false; | |
| warnUndeclaredOptions = true; | |
| }; | |
| in | |
| nixpkgs | |
| // { | |
| lib = lib.extend ( | |
| final: prev: { | |
| nixosSystem = | |
| args: | |
| prev.nixosSystem ( | |
| args | |
| // { | |
| modules = args.modules ++ [ nixpkgs.nixosModules.readOnlyPkgs ]; | |
| #? Usually, lib.nixosSystem doesn't go through legacyPackages, | |
| #? relying on modules/misc/nixpkgs.nix instead. This is the root | |
| #? cause of why nixpkgs.config is not applied to other nixpkgs | |
| #? instances. Also, this is the only place `system` is required, | |
| #? it gets set to pkgs.stdenv.hostPlatform by read-only.nix | |
| pkgs = self.legacyPackages.${args.system}; | |
| system = null; | |
| } | |
| ); | |
| } | |
| ); | |
| legacyPackages = forAllSystems ( | |
| system: | |
| import (nixpkgs + /pkgs/top-level) { | |
| # no builtins.currentSystem | |
| localSystem = { inherit system; }; | |
| config = | |
| let | |
| date = nixpkgs.lastModifiedDate; | |
| substr = start: len: lib.substring start len date; | |
| pretty = "${substr 0 4}/${substr 4 2}/${substr 6 2}"; | |
| in | |
| builtins.trace '' | |
| new nixpkgs instance created: | |
| system = ${system} | |
| src = ${nixpkgs} | |
| modified = ${pretty} | |
| '' betterDefaultConfig; | |
| } | |
| ); | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment