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 = outputs =
{ self { self
, AriaNg
, aria2_exporter
, bang-evaluator
, flake-utils , flake-utils
, home-manager
, infinisilSystem
, krops , krops
, nix-pre-commit-hooks , nix-pre-commit-hooks
, nixos-hardware
, nixpkgs , nixpkgs
, nixpkgs-overlay , ...
, nixpkgs-unstable }@inputs: flake-utils.lib.eachDefaultSystem
, sops-nix
}: flake-utils.lib.eachDefaultSystem
(system: (system:
let let
pkgs = nixpkgs.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system};
@ -164,42 +156,10 @@
modules = [ modules = [
(./machines + "/${hostname}/configuration.nix") (./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 = { _module.args.inputs = inputs;
nixPath = [
"nixpkgs=${nixpkgs}"
];
registry = {
nixpkgs.flake = nixpkgs;
nixpkgs-unstable.flake = nixpkgs-unstable;
};
};
} }
# 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 # deployment settings
({ lib, ... }: { ({ lib, ... }: {
options.deployment = { options.deployment = {
@ -221,12 +181,14 @@
unlockOverV4; 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 { (import ./machines inputs);
inherit
infinisilSystem
nixos-hardware;
});
}; };
} }

View file

@ -1,8 +1,6 @@
{ infinisilSystem { ... }@inputs:
, nixos-hardware
}:
let let
hardware = nixos-hardware.nixosModules; hardware = inputs.nixos-hardware.nixosModules;
in in
{ {
nunotaba = { nunotaba = {
@ -22,7 +20,7 @@ in
vueko = { vueko = {
system = "x86_64-linux"; system = "x86_64-linux";
extraModules = [ extraModules = [
"${infinisilSystem}/config/new-modules/murmur.nix" "${inputs.infinisilSystem}/config/new-modules/murmur.nix"
]; ];
targetHost = "vueko.sbruder.de"; targetHost = "vueko.sbruder.de";

View file

@ -1,4 +1,4 @@
{ config, lib, pkgs, ... }: { config, inputs, lib, pkgs, ... }:
let let
# Adapted from https://nixos.wiki/wiki/Overlays # Adapted from https://nixos.wiki/wiki/Overlays
overlaysCompat = pkgs.writeTextFile { overlaysCompat = pkgs.writeTextFile {
@ -30,7 +30,13 @@ in
# nix with flake support # nix with flake support
package = pkgs.nixUnstable; package = pkgs.nixUnstable;
registry = with inputs; {
nixpkgs.flake = nixpkgs;
nixpkgs-unstable.flake = nixpkgs-unstable;
};
nixPath = [ nixPath = [
"nixpkgs=${inputs.nixpkgs}"
"nixpkgs-overlays=${overlaysCompat}" "nixpkgs-overlays=${overlaysCompat}"
]; ];
# Make sudoers trusted nix users # Make sudoers trusted nix users
@ -61,4 +67,19 @@ in
daemonNiceLevel = 10; daemonNiceLevel = 10;
daemonIONiceLevel = 5; # 0-7 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
];
} }