From eb13a9a552f9e50a66faba985521ba8e3483c447 Mon Sep 17 00:00:00 2001 From: Kleidi Bujari Date: Tue, 17 Dec 2024 23:03:27 -0500 Subject: Push configuration out of flake Projects are not necessarily all exported by the system flake, and should freely support other derivations. The new "mod" directory will be used for most projects, and it can be imported by machine configurations. That said, the tooling around flakes is pretty good and will still be used until the dependency is lessened. --- flake.nix | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 67 insertions(+), 17 deletions(-) (limited to 'flake.nix') diff --git a/flake.nix b/flake.nix index f036610..ca20bf3 100644 --- a/flake.nix +++ b/flake.nix @@ -4,32 +4,82 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11"; - flake-parts.url = "github:hercules-ci/flake-parts"; - flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs"; - disko.url = "github:nix-community/disko/v1.6.1"; disko.inputs.nixpkgs.follows = "nixpkgs"; sops-nix.url = "github:Mic92/sops-nix"; sops-nix.inputs.nixpkgs.follows = "nixpkgs"; - - sshKeys = { - url = "https://github.com/kbujari.keys"; - flake = false; - }; }; - outputs = { flake-parts, ... } @ inputs: - flake-parts.lib.mkFlake { inherit inputs; } { - systems = [ "x86_64-linux" "aarch64-linux" ]; + outputs = { self, nixpkgs, ... } @ inputs: + let + inherit (builtins) + attrNames + filter + listToAttrs + map + readDir + ; - imports = [ - ./machines/flake-module.nix - ./modules/flake-module.nix - ]; + inherit (nixpkgs.lib) + nixosSystem + ; - perSystem = { pkgs, ... }: { - formatter = pkgs.nixpkgs-fmt; + readTree = import ./mod/nix/readTree { }; + + # Recursively converts subdirectories under ./mod into an attrset + # that can be passed to other parts of the depot. + readDepot = depotArgs: readTree { + args = depotArgs; + path = ./mod; }; + + # Named arguments to be made available to any nix expression in + # the depot module. + depot = readTree.fix (self: readDepot { + depot = self; + + # x86_64-linux is hardcoded as the package arch only for the + # mod directory. This workaround keeps the flake pure, + # at the expense of only supporting one system. This can + # be circumvented by retrieving the system during evaluation, + # but flakes disallow this by design. + # + # This monorepo currently depends on functionality from flakes, + # but this may change in the future, perhaps shifting to an + # impure base with certain packages exposed from the flake in a + # pure way. + # + # In practice, this means that any configuration or package + # exposed from the depot flake that makes use of internal + # derivations is limited to x86_64-linux. For now this is fine, + # but ideally any architecture supported by nix should be + # allowed to evaluate projects hosted here. + pkgs = nixpkgs.legacyPackages."x86_64-linux"; + + # Expose lib attribute to modules. + lib = nixpkgs.lib; + }); + + machines = filter (m: m != "iso" && m != "xnet") + (attrNames (readDir ./machines)); + in + { + inherit depot; + + nixosModules.xnet.imports = + [ ./machines/xnet inputs.disko.nixosModules.disko ]; + + nixosConfigurations = listToAttrs ( + map + (name: { + inherit name; + value = nixosSystem { + system = "x86_64-linux"; + specialArgs = { inherit inputs depot; }; + modules = [ ./machines/${name} self.nixosModules.xnet ]; + }; + }) + machines); }; } -- cgit v1.3.1