Reorganize imports to prevent infinite recursions

This commit is contained in:
Fabian Hauser 2025-03-25 12:49:03 +02:00
parent ee6b756d3c
commit ff0ce9d94c
18 changed files with 136 additions and 89 deletions

View file

@ -4,23 +4,17 @@
pkgs, pkgs,
deployPkgs, deployPkgs,
... ...
}: }@inputs:
{ {
${system} = { ${system} = {
# Check project formatting # TODO: Check project formatting
format = pkgs.runCommand "nixfmt-check" { } ''
set -euo pipefail
cd ${self}
${self.formatter.${system}}/bin/formatter . --check
mkdir $out
'';
nixos-modules = pkgs.callPackage ./nixos-modules { nixos-modules = pkgs.callPackage ./nixos-modules {
inherit (self.lib) getSubDirs isFolderWithFile; inherit (self.lib) getSubDirs isFolderWithFile;
}; };
#TODO(#29): Integration/System tests nixos-configurations = import ./nixos-configurations inputs;
# Import deploy-rs tests # Import deploy-rs tests
} // (deployPkgs.deploy-rs.lib.deployChecks self.deploy); } // (deployPkgs.deploy-rs.lib.deployChecks self.deploy);

View file

@ -0,0 +1,4 @@
{ self, pkgs, ... }:
pkgs.linkFarmFromDrvs "all" (
pkgs.lib.mapAttrsToList (n: v: v.config.system.build.toplevel) self.nixosConfigurations
)

View file

@ -0,0 +1,5 @@
{ self, pkgs, ... }:
let
inherit (pkgs.lib) attrValues;
in
pkgs.linkFarmFromDrvs "all" (attrValues self.packages)

View file

@ -1,6 +1,5 @@
{ {
deployPkgs, deployPkgs,
pkgs,
self, self,
system, system,
... ...

9
flake.lock generated
View file

@ -111,10 +111,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1737552783, "lastModified": 1742849713,
"narHash": "sha256-pJ2lp36L3++a5HtdN7ULcVpdB4j7yo90TDayWuAO+T8=", "narHash": "sha256-EH3vvMdalGxxvYt3tZI4K4RKT/YAh7XejYYrf/jZ0N8=",
"rev": "33cf80043c64ddd6882268430454e3cbe98b692b", "ref": "refs/heads/main",
"revCount": 11, "rev": "f79080b8802eec4463bb4a25c64f82f73e6e31db",
"revCount": 12,
"type": "git", "type": "git",
"url": "file:./private" "url": "file:./private"
}, },

View file

@ -23,7 +23,12 @@
}; };
outputs = outputs =
{ nixpkgs-nixos-unstable, deploy-rs, ... }@inputs: {
self,
nixpkgs-nixos-unstable,
deploy-rs,
...
}@inputs:
let let
system = "x86_64-linux"; system = "x86_64-linux";
# Packages for development and build process # Packages for development and build process
@ -40,22 +45,79 @@
}) })
]; ];
}; };
importParams = inputs // { importParams = {
inherit pkgs; inherit (inputs)
inherit deployPkgs; deploy-rs
inherit system; disko
nixpkgs-nixos-stable
sops-nix
private
;
inherit pkgs deployPkgs system;
flakeSelf = self;
}; };
in in
{ {
checks = import ./checks/default.nix importParams; checks = import ./checks/default.nix (
deploy = import ./deploy/default.nix importParams; importParams
devShells = import ./dev-shells/default.nix importParams; // {
formatter.${system} = pkgs.writeShellScriptBin "formatter" '' self = {
${pkgs.findutils}/bin/find $1 -type f -name '*.nix' -exec ${pkgs.nixfmt-rfc-style}/bin/nixfmt ''${@:2} {} + inherit (self)
''; lib
nixosConfigurations = import ./nixos-configurations/default.nix importParams; packages
nixosModules = import ./nixos-modules/default.nix importParams; nixosModules
packages = import ./packages/default.nix importParams; nixosConfigurations
lib = import ./lib/default.nix importParams; deploy
;
};
}
);
deploy = import ./deploy/default.nix (
importParams
// {
self = {
inherit (self)
lib
packages
nixosModules
nixosConfigurations
;
};
}
);
devShells = import ./dev-shells/default.nix (
importParams
// {
self = {
inherit (self) lib packages;
};
}
);
formatter.${system} = pkgs.nixfmt-tree;
nixosConfigurations = import ./nixos-configurations/default.nix (
importParams
// {
self = {
inherit (self) lib packages nixosModules;
};
}
);
nixosModules = import ./nixos-modules/default.nix (
importParams
// {
self = {
inherit (self) lib packages;
};
}
);
packages = import ./packages/default.nix (
importParams
// {
self = {
inherit (self) lib packages;
};
}
);
lib = import ./lib/default.nix { inherit pkgs; };
}; };
} }

View file

@ -7,27 +7,23 @@
... ...
}@inputs: }@inputs:
let let
inherit (pkgs.lib) genAttrs;
inherit (nixpkgs-nixos-stable.lib) nixosSystem;
configs = self.lib.foldersWithNix ./.; configs = self.lib.foldersWithNix ./.;
in in
pkgs.lib.genAttrs configs ( genAttrs configs (
config: config:
nixpkgs-nixos-stable.lib.nixosSystem { nixosSystem {
system = "x86_64-linux"; system = "x86_64-linux";
specialArgs = { specialArgs = {
inherit inputs; inherit inputs;
}; };
modules = [ modules = [
self.nixosModules.default
./${config}/default.nix
disko.nixosModules.disko disko.nixosModules.disko
sops-nix.nixosModules.sops sops-nix.nixosModules.sops
( self.nixosModules.default
{ ... }: ./${config}/default.nix
{ ./secrets.nix
system.extraSystemBuilderCmds = "ln -s ${self} $out/nixos-configuration";
imports = [ ./secrets.nix ];
}
)
]; ];
} }
) )

View file

@ -1,8 +1,7 @@
{ config, pkgs, ... }: { config, ... }:
{ {
qois.nixpkgs-cache = { qois.nixpkgs-cache = {
enable = true; enable = true;
hostname = "nixpkgs-cache.qo.is";
dnsResolvers = [ config.qois.meta.network.virtual.lindberg-vms-nat.hosts.lindberg.v4.ip ]; dnsResolvers = [ config.qois.meta.network.virtual.lindberg-vms-nat.hosts.lindberg.v4.ip ];
}; };
} }

View file

@ -1,8 +1,9 @@
inputs: { { private, self, ... }:
{
default = default =
{ config, pkgs, ... }: { ... }:
{ {
imports = (inputs.self.lib.loadSubmodulesFrom ./.) ++ [ inputs.private.nixosModules.default ]; imports = (self.lib.loadSubmodulesFrom ./.) ++ [ private.nixosModules.default ];
}; };
} }

View file

@ -16,6 +16,7 @@ with lib;
hostname = mkOption { hostname = mkOption {
type = types.str; type = types.str;
example = "mycache.myhost.org"; example = "mycache.myhost.org";
default = "nixpkgs-cache.qo.is";
description = "Hostname, under which the cache is served"; description = "Hostname, under which the cache is served";
}; };

View file

@ -57,7 +57,7 @@
settings = settings =
let let
substituters = [ substituters = [
"https://${inputs.self.nixosConfigurations.lindberg-build.config.qois.nixpkgs-cache.hostname}?priority=39" "https://${config.qois.nixpkgs-cache.hostname}?priority=39"
"https://cache.nixos.org?priority=40" "https://cache.nixos.org?priority=40"
"https://attic.qo.is/qois-infrastructure" "https://attic.qo.is/qois-infrastructure"
]; ];

View file

@ -7,6 +7,5 @@
}: }:
{ {
nixpkgs.overlays = [ (import ../../overlays) ];
nix.nixPath = options.nix.nixPath.default; nix.nixPath = options.nix.nixPath.default;
} }

View file

@ -1,5 +0,0 @@
self: super: {
lib = (super.lib or { }) // {
qois = import ../lib { lib = self.lib; };
};
}

View file

@ -1,37 +1,28 @@
{ {
self, self,
flakeSelf,
system, system,
private,
pkgs, pkgs,
... ...
}: }:
with pkgs.lib; let
inherit (self.lib) foldersWithNix;
inherit (pkgs.lib)
path
genAttrs
;
in
{ {
${system} = ${system} = genAttrs (foldersWithNix ./.) (
let name:
packages = pipe (self.lib.foldersWithNix ./.) [ pkgs.callPackage (path.append ./. "./${name}/default.nix") {
(map (name: { inherit
inherit name; self
path = path.append ./. "./${name}/default.nix"; flakeSelf
})) system
(map ( private
{ name, path }: ;
{ }
inherit name; );
value = pkgs.callPackage path {
inherit self;
inherit system;
};
}
))
listToAttrs
];
in
packages
// {
default =
let
nixosConfigs = mapAttrsToList (n: v: v.config.system.build.toplevel) self.nixosConfigurations;
in
pkgs.linkFarmFromDrvs "all" (nixosConfigs ++ (attrValues packages));
};
} }

View file

@ -1,6 +1,6 @@
{ {
deploy-rs, deploy-rs,
self, flakeSelf,
writeShellApplication, writeShellApplication,
... ...
}: }:
@ -9,6 +9,6 @@ writeShellApplication {
meta.description = "Deploy configuration to specificed targets."; meta.description = "Deploy configuration to specificed targets.";
runtimeInputs = [ deploy-rs ]; runtimeInputs = [ deploy-rs ];
text = '' text = ''
deploy --interactive --targets "''${@:-${self}}" deploy --interactive --targets "''${@:-${flakeSelf}}"
''; '';
} }

View file

@ -3,12 +3,12 @@
mdbook-plantuml, mdbook-plantuml,
mdbook, mdbook,
plantuml, plantuml,
self, flakeSelf,
stdenv, stdenv,
... ...
}: }:
let let
version = self.rev or self.dirtyRev; version = flakeSelf.rev or flakeSelf.dirtyRev;
in in
stdenv.mkDerivation { stdenv.mkDerivation {
inherit version; inherit version;
@ -19,6 +19,6 @@ stdenv.mkDerivation {
mdbook-plantuml mdbook-plantuml
plantuml plantuml
]; ];
src = self; src = flakeSelf;
buildPhase = "mdbook build --dest-dir $out"; buildPhase = "mdbook build --dest-dir $out";
} }

View file

@ -3,7 +3,7 @@
gnupg, gnupg,
lib, lib,
runCommand, runCommand,
self, private,
ssh-to-age, ssh-to-age,
writeText, writeText,
... ...
@ -13,7 +13,7 @@ let
metaHostConfigs = import ../../defaults/meta/hosts.nix { }; metaHostConfigs = import ../../defaults/meta/hosts.nix { };
userPgpKeys = userPgpKeys =
let let
keysFolder = "${self.inputs.private}/sops_keys"; keysFolder = "${private}/sops_keys";
gpgFingerprintsFile = gpgFingerprintsFile =
runCommand "userPgpKeys" runCommand "userPgpKeys"
{ {

@ -1 +1 @@
Subproject commit 33cf80043c64ddd6882268430454e3cbe98b692b Subproject commit f79080b8802eec4463bb4a25c64f82f73e6e31db