nixosConfigurations: move input forwarding to inline module

Inspired by https://jade.fyi/blog/flakes-arent-real/, this is better for
composability:
>  it also doesn't work outside of the flake that's actually invoking nixpkgs.lib.nixosSystem. The latter is the much more sinister part, and the reason I would strongly recommend inline modules with closures instead of specialArgs: they break flake composition.

For now, the `system` remains a specialArg, until I decide what to do
with that.
This commit is contained in:
Trolli Schmittlauch 2024-01-20 12:25:32 +01:00
parent 4a43774913
commit 9ad1049f4a
7 changed files with 20 additions and 8 deletions

View file

@ -1,6 +1,7 @@
{ config, pkgs, lib, inputs, ... }: { config, pkgs, lib, ... }:
let let
inputs = config.inputInjection.flake-inputs;
unstable = inputs.nixos-unstable; unstable = inputs.nixos-unstable;
in in

View file

@ -31,13 +31,24 @@
# FIXME: allow different systems # FIXME: allow different systems
systems = flake-utils.lib.system; systems = flake-utils.lib.system;
# necessary to make the top-level inputs available to system configuration # necessary to make the top-level inputs available to system configuration
# inspired by https://jade.fyi/blog/flakes-arent-real/
inputInjection = {pkgs, lib, ...}: {
options.inputInjection = lib.mkOption {
type = with lib.types; attrsOf unspecified;
default = {};
};
config.inputInjection = {
flake-inputs = inputs;
};
};
defaultModules = system: [ defaultModules = system: [
{ _module.args = { inherit inputs system; }; } inputInjection
]; ];
mkSystem = system: extraModules: mkSystem = system: extraModules:
nixpkgs.lib.nixosSystem rec { nixpkgs.lib.nixosSystem rec {
modules = (defaultModules system) ++ extraModules; modules = (defaultModules system) ++ extraModules;
inherit system; inherit system;
specialArgs = {inherit system;};
}; };
mkHomeManager = confName: user: system: # unfortunately, home-manager configs are still system-specific mkHomeManager = confName: user: system: # unfortunately, home-manager configs are still system-specific
# FIXME: this is thus still linux-x86_64 specific # FIXME: this is thus still linux-x86_64 specific

View file

@ -1,6 +1,6 @@
{ config, lib, pkgs, inputs, system, ...}: { config, lib, pkgs, system, ...}:
let let
unstable = inputs.nixos-unstable.legacyPackages.${system}; unstable = config.inputInjection.flake-inputs.nixos-unstable.legacyPackages.${system};
in in
{ {
imports = [ imports = [

View file

@ -1,4 +1,4 @@
{ config, lib, pkgs, inputs, ...}: { config, lib, pkgs, ...}:
{ {
imports = [ imports = [
../../common ../../common

View file

@ -1,4 +1,4 @@
{ config, lib, pkgs, modulesPath, inputs, ... }: { config, lib, pkgs, modulesPath, ... }:
{ {

View file

@ -1,4 +1,4 @@
{ config, lib, pkgs, inputs, ...}: { config, lib, pkgs, ...}:
{ {
boot.loader.efi.canTouchEfiVariables = true; boot.loader.efi.canTouchEfiVariables = true;

View file

@ -1,4 +1,4 @@
{ config, lib, pkgs, inputs, ...}: { config, lib, pkgs, ...}:
let let
fsOptions = [ "noatime" "ssd" "space_cache" "compress=zstd" ]; fsOptions = [ "noatime" "ssd" "space_cache" "compress=zstd" ];
in in