From 88f348a2c9d3593bc0b0aafaa5d73d7d56ac1f41 Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Mon, 17 Jun 2024 07:24:06 +0200 Subject: [PATCH] pkgs/overlays: create, move unstable there also in unstable: use nixpkgs option to define if unstable nixpkgs expressions should be from nixos or nixpkgs channel (default true, use nixos channel) --- nix-os/unstable-packages.nix | 37 ++++++++++-------------------------- pkgs/overlays/unstable.nix | 36 +++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 27 deletions(-) create mode 100644 pkgs/overlays/unstable.nix diff --git a/nix-os/unstable-packages.nix b/nix-os/unstable-packages.nix index 27e0727..4c41240 100644 --- a/nix-os/unstable-packages.nix +++ b/nix-os/unstable-packages.nix @@ -1,37 +1,20 @@ {config, pkgs, lib, ...}: let - nixos-unstable-exprs = builtins.fetchTarball https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz; - nixos-unstable = import nixos-unstable-exprs { - inherit (config.nixpkgs) config localSystem crossSystem; - overlays = if config.unstable.usePkgsOverlays then config.pkgs.overlays else []; - }; - nixos-unstable-version = builtins.concatStringsSep "." [ - (builtins.readFile "${builtins.toString nixos-unstable-exprs}/.version") - (builtins.readFile "${builtins.toString nixos-unstable-exprs}/.version-suffix") - ]; + cfg = config.unstable; + unstableOverlay = import ../pkgs/overlays/unstable.nix; in { options.unstable = { enable = lib.mkEnableOption (lib.mkDoc '' use of unstable packages in configuration. You can use `unstablePkgs` in configuration modules '') // { default = true; }; - usePkgsOverlays = lib.mkEnableOption (lib.mkDoc '' - use overlays from `nixpkgs.overlays` - ''); - pkgs = lib.mkOption { - default = if config.unstable.enable then nixos-unstable else pkgs; - description = lib.mkDoc '' - acts like pkgs, but it has unstable packages if `unstable.enable` is enabled. - You can also use `unstablePkgs` in module arguments. - ''; - visible = true; - readOnly = true; - type = lib.types.pkgs; - }; }; - config._module.args.unstablePkgs = config.unstable.pkgs; - config.system.extraSystemBuilderCmds = lib.mkIf config.unstable.enable '' - echo ${nixos-unstable-version} > $out/nixos-unstable-version - ''; -} \ No newline at end of file + config = { + _module.args.unstablePkgs = if config.unstable.enable then pkgs.unstable else pkgs; + nixpkgs.overlays = lib.mkIf cfg.enable [ unstableOverlay ]; + system.extraSystemBuilderCmds = lib.mkIf config.unstable.enable '' + echo ${pkgs.unstableVersion} > $out/nixos-unstable-version + ''; + }; +} diff --git a/pkgs/overlays/unstable.nix b/pkgs/overlays/unstable.nix new file mode 100644 index 0000000..9aa8f2c --- /dev/null +++ b/pkgs/overlays/unstable.nix @@ -0,0 +1,36 @@ +self: super: + +let + nixos = self.config.nixos or true; + useUnstable = self.config.useUnstable or true; + + unstablePkgsExprs = if nixos + then builtins.fetchTarball "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz" + else builtins.fetchTarball "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz"; + + # Compiled nixpkgs expression eg expressions from a nix channel + nixpkgsVersion = builtins.concatStringsSep "." [ + (builtins.readFile "${unstablePkgsExprs}/.version") + (builtins.readFile "${unstablePkgsExprs}/.version-suffix") + ]; + + nixpkgsRevision = (builtins.readFile "${unstablePkgsExprs}/.git-revision"); + unstablePkgsForNixpkgs = nixpkgs: import unstablePkgsExprs { + # localSystem -> pkgs.stdenv.hostPlatform or pkgs.stdenv.hostPlatform ??? + localSystem = nixpkgs.stdenv.hostPlatform; + # crossSystem -> nixpkgs.stdenv.targetPlatform + crossSystem = nixpkgs.stdenv.targetPlatform; + # config -> pkgs.config + config = nixpkgs.config; + # overlays -> partial of pkgs.overlays + overlays = nixpkgs.overlays; + # crossOverlays -> partial of pkgs.overlays + # crossOverlays are merged to overlays, not sure what issues that might raise. + # ignoring. + }; +in +{ + unstable = if useUnstable then unstablePkgsForNixpkgs self else self; + unstableVersion = self.lib.optionalString useUnstable nixpkgsVersion; + unstableRevision = self.lib.optionalString useUnstable nixpkgsRevision; +}