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).
This commit is contained in:
Simon Bruder 2021-05-15 10:04:44 +02:00
parent 531060668a
commit 2c8a291ae9
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC
3 changed files with 36 additions and 55 deletions

View file

@ -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);
};
}

View file

@ -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";

View file

@ -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
];
}