diff options
| author | Kleidi Bujari <mail@4kb.net> | 2024-12-17 23:03:27 -0500 |
|---|---|---|
| committer | Kleidi Bujari <mail@4kb.net> | 2024-12-17 23:03:27 -0500 |
| commit | eb13a9a552f9e50a66faba985521ba8e3483c447 (patch) | |
| tree | 209193a91b0db20fb1bb30007e72e321f0293696 /flake.nix | |
| parent | f5ed731abbc38d765333b005b9815a5f6d3e59c2 (diff) | |
| download | depot-eb13a9a552f9e50a66faba985521ba8e3483c447.tar.gz depot-eb13a9a552f9e50a66faba985521ba8e3483c447.tar.bz2 depot-eb13a9a552f9e50a66faba985521ba8e3483c447.zip | |
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.
Diffstat (limited to 'flake.nix')
| -rw-r--r-- | flake.nix | 84 |
1 files changed, 67 insertions, 17 deletions
@@ -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); }; } |
