From 9ad1049f4add342a1e901008a65b7213f0529588 Mon Sep 17 00:00:00 2001 From: Trolli Schmittlauch Date: Sat, 20 Jan 2024 12:25:32 +0100 Subject: [PATCH] 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. --- common/default.nix | 3 ++- flake.nix | 13 ++++++++++++- hosts/framenix/default.nix | 4 ++-- hosts/thinknix/default.nix | 2 +- hosts/thinknix/hardware-configuration.nix | 2 +- hosts/thinknix/secureboot.nix | 2 +- hosts/thinknix/storage.nix | 2 +- 7 files changed, 20 insertions(+), 8 deletions(-) diff --git a/common/default.nix b/common/default.nix index a5a7119..986348b 100644 --- a/common/default.nix +++ b/common/default.nix @@ -1,6 +1,7 @@ -{ config, pkgs, lib, inputs, ... }: +{ config, pkgs, lib, ... }: let + inputs = config.inputInjection.flake-inputs; unstable = inputs.nixos-unstable; in diff --git a/flake.nix b/flake.nix index 9d0937f..4bac461 100644 --- a/flake.nix +++ b/flake.nix @@ -31,13 +31,24 @@ # FIXME: allow different systems systems = flake-utils.lib.system; # 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: [ - { _module.args = { inherit inputs system; }; } + inputInjection ]; mkSystem = system: extraModules: nixpkgs.lib.nixosSystem rec { modules = (defaultModules system) ++ extraModules; inherit system; + specialArgs = {inherit system;}; }; mkHomeManager = confName: user: system: # unfortunately, home-manager configs are still system-specific # FIXME: this is thus still linux-x86_64 specific diff --git a/hosts/framenix/default.nix b/hosts/framenix/default.nix index 121c298..6902321 100644 --- a/hosts/framenix/default.nix +++ b/hosts/framenix/default.nix @@ -1,6 +1,6 @@ -{ config, lib, pkgs, inputs, system, ...}: +{ config, lib, pkgs, system, ...}: let - unstable = inputs.nixos-unstable.legacyPackages.${system}; + unstable = config.inputInjection.flake-inputs.nixos-unstable.legacyPackages.${system}; in { imports = [ diff --git a/hosts/thinknix/default.nix b/hosts/thinknix/default.nix index 8451bc0..ff1a2ff 100644 --- a/hosts/thinknix/default.nix +++ b/hosts/thinknix/default.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, inputs, ...}: +{ config, lib, pkgs, ...}: { imports = [ ../../common diff --git a/hosts/thinknix/hardware-configuration.nix b/hosts/thinknix/hardware-configuration.nix index f3e821a..18c7846 100644 --- a/hosts/thinknix/hardware-configuration.nix +++ b/hosts/thinknix/hardware-configuration.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, modulesPath, inputs, ... }: +{ config, lib, pkgs, modulesPath, ... }: { diff --git a/hosts/thinknix/secureboot.nix b/hosts/thinknix/secureboot.nix index 6e20c35..41eb516 100644 --- a/hosts/thinknix/secureboot.nix +++ b/hosts/thinknix/secureboot.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, inputs, ...}: +{ config, lib, pkgs, ...}: { boot.loader.efi.canTouchEfiVariables = true; diff --git a/hosts/thinknix/storage.nix b/hosts/thinknix/storage.nix index 358370f..55b9a0a 100644 --- a/hosts/thinknix/storage.nix +++ b/hosts/thinknix/storage.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, inputs, ...}: +{ config, lib, pkgs, ...}: let fsOptions = [ "noatime" "ssd" "space_cache" "compress=zstd" ]; in