From 2c8a291ae9d15e45e442c2497c9214a8480c9860 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Sat, 15 May 2021 10:04:44 +0200 Subject: [PATCH] Make flake inputs available as module argument This moves a bunch of stuff out of flake.nix into the modules they belong to. This removes complexity from flake.nix and gives the project a more organised structure. Sadly, it is not possible to import modules from a flake outside of flake.nix, since that leads to an infinite recursion (`config` has to be evaluated before `config._modules.args.inputs` is available but `config` depends on an import from `config._modules.args.inputs`). Therefore, the `extraModules` argument in `machines/default.nix` has to be used for that (it now has access to all flake inputs). --- flake.nix | 60 ++++++++------------------------------------ machines/default.nix | 8 +++--- modules/nix.nix | 23 ++++++++++++++++- 3 files changed, 36 insertions(+), 55 deletions(-) diff --git a/flake.nix b/flake.nix index 4bb6f67..8248ce6 100644 --- a/flake.nix +++ b/flake.nix @@ -46,20 +46,12 @@ outputs = { self - , AriaNg - , aria2_exporter - , bang-evaluator , flake-utils - , home-manager - , infinisilSystem , krops , nix-pre-commit-hooks - , nixos-hardware , nixpkgs - , nixpkgs-overlay - , nixpkgs-unstable - , sops-nix - }: flake-utils.lib.eachDefaultSystem + , ... + }@inputs: flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; @@ -164,42 +156,10 @@ modules = [ (./machines + "/${hostname}/configuration.nix") - home-manager.nixosModules.home-manager - sops-nix.nixosModules.sops - - aria2_exporter.nixosModules.aria2_exporter - bang-evaluator.nixosModules.bang-evaluator - - # NIX_PATH for legacy tooling and flake registry pinning { - nix = { - nixPath = [ - "nixpkgs=${nixpkgs}" - ]; - registry = { - nixpkgs.flake = nixpkgs; - nixpkgs-unstable.flake = nixpkgs-unstable; - }; - }; + _module.args.inputs = inputs; } - # overlays - ({ config, ... }: { - nixpkgs.overlays = [ - self.overlay - nixpkgs-overlay.overlay - (final: prev: { - unstable = import nixpkgs-unstable { - inherit system; - config = config.nixpkgs.config; - overlays = config.nixpkgs.overlays; - }; - }) - - AriaNg.overlay - ]; - }) - # deployment settings ({ lib, ... }: { options.deployment = { @@ -221,12 +181,14 @@ unlockOverV4; }; }) - ] ++ extraModules; + ] ++ (with inputs; [ + home-manager.nixosModules.home-manager + sops-nix.nixosModules.sops + + aria2_exporter.nixosModules.aria2_exporter + bang-evaluator.nixosModules.bang-evaluator + ]) ++ extraModules; }) - (import ./machines { - inherit - infinisilSystem - nixos-hardware; - }); + (import ./machines inputs); }; } diff --git a/machines/default.nix b/machines/default.nix index 4a92c9d..a96f093 100644 --- a/machines/default.nix +++ b/machines/default.nix @@ -1,8 +1,6 @@ -{ infinisilSystem -, nixos-hardware -}: +{ ... }@inputs: let - hardware = nixos-hardware.nixosModules; + hardware = inputs.nixos-hardware.nixosModules; in { nunotaba = { @@ -22,7 +20,7 @@ in vueko = { system = "x86_64-linux"; extraModules = [ - "${infinisilSystem}/config/new-modules/murmur.nix" + "${inputs.infinisilSystem}/config/new-modules/murmur.nix" ]; targetHost = "vueko.sbruder.de"; diff --git a/modules/nix.nix b/modules/nix.nix index c43a2e0..291d80c 100644 --- a/modules/nix.nix +++ b/modules/nix.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: +{ config, inputs, lib, pkgs, ... }: let # Adapted from https://nixos.wiki/wiki/Overlays overlaysCompat = pkgs.writeTextFile { @@ -30,7 +30,13 @@ in # nix with flake support package = pkgs.nixUnstable; + registry = with inputs; { + nixpkgs.flake = nixpkgs; + nixpkgs-unstable.flake = nixpkgs-unstable; + }; + nixPath = [ + "nixpkgs=${inputs.nixpkgs}" "nixpkgs-overlays=${overlaysCompat}" ]; # Make sudoers trusted nix users @@ -61,4 +67,19 @@ in daemonNiceLevel = 10; daemonIONiceLevel = 5; # 0-7 }; + + nixpkgs.overlays = with inputs; [ + self.overlay + nixpkgs-overlay.overlay + (final: prev: { + unstable = import nixpkgs-unstable { + inherit (config.nixpkgs) + config + overlays + system; + }; + }) + + AriaNg.overlay + ]; }