summaryrefslogtreecommitdiff
path: root/flake.nix
diff options
context:
space:
mode:
authorKleidi Bujari <mail@4kb.net>2025-04-02 21:59:20 -0400
committerKleidi Bujari <mail@4kb.net>2025-04-02 21:59:20 -0400
commit09c2b6de63a6ff35348fcb2c2eb57b974f0a8a52 (patch)
treebd8f1d3a51f12cd98764ae572b00f0b32de62644 /flake.nix
parentb1738c105de3bc0ba7cd27f68c9eb146439a0964 (diff)
downloaddepot-09c2b6de63a6ff35348fcb2c2eb57b974f0a8a52.tar.gz
depot-09c2b6de63a6ff35348fcb2c2eb57b974f0a8a52.tar.bz2
depot-09c2b6de63a6ff35348fcb2c2eb57b974f0a8a52.zip
automate project structure
Diffstat (limited to 'flake.nix')
-rw-r--r--flake.nix92
1 files changed, 43 insertions, 49 deletions
diff --git a/flake.nix b/flake.nix
index 3cda153..703ed9c 100644
--- a/flake.nix
+++ b/flake.nix
@@ -1,19 +1,11 @@
{
description = "Personal monorepo";
-
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
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";
-
- agenix.url = "github:ryantm/agenix/0.15.0";
- agenix.inputs.nixpkgs.follows = "nixpkgs";
- agenix.inputs.darwin.follows = "";
-
nixos-hardware.url = "github:nixos/nixos-hardware/master";
# Rust projects
@@ -25,70 +17,71 @@
let
inherit (builtins)
attrNames
- filter
listToAttrs
map
readDir
;
+ inherit (nixpkgs) lib;
+
inherit (nixpkgs.lib)
+ mapAttrs
nixosSystem
;
- readTree = import ./mod/nix/readTree { };
+ systems = [ "x86_64-linux" "aarch64-linux" ];
- # 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;
- };
+ inherit (import ./lib/depot-tools.nix { inherit inputs systems lib; })
+ importDir
+ eachSystem
+ systemArgs
+ ;
- # Named arguments to be made available to any nix expression in
- # the depot module.
- depot = readTree.fix (self: readDepot {
- depot = self;
+ packages = eachSystem (
+ { newScope, ... }:
+ mapAttrs (pname: { path, ... }: newScope { inherit pname; } path { })
+ (importDir ./packages)
+ );
+ publisherArgs = {
+ flake = self;
inherit inputs;
+ };
- # 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";
+ expectsPublisherArgs =
+ module:
+ builtins.isFunction module
+ && builtins.all (arg: builtins.elem arg (builtins.attrNames publisherArgs)) (
+ builtins.attrNames (builtins.functionArgs module)
+ );
- # Expose lib attribute to modules.
- lib = nixpkgs.lib;
- });
+ injectPublisherArgs =
+ modulePath:
+ let
+ module = import modulePath;
+ in
+ if expectsPublisherArgs module then
+ lib.setDefaultModuleLocation modulePath (module publisherArgs)
+ else
+ modulePath;
- machines = filter (m: m != "xnet")
- (attrNames (readDir ./machines));
+ nixosModules = mapAttrs (_: moduleDir: injectPublisherArgs moduleDir)
+ (mapAttrs (_: { path, ... }: path) (importDir ./modules));
in
{
- inherit depot;
-
- nixosModules.xnet.imports =
- [ ./machines/xnet inputs.disko.nixosModules.disko ];
+ inherit packages nixosModules;
nixosConfigurations = listToAttrs (
map
(name: {
inherit name;
- value = nixosSystem {
+ value = nixosSystem rec {
system = "x86_64-linux";
- specialArgs = { inherit inputs depot; };
+ specialArgs = {
+ inherit inputs;
+ inherit (self) outputs;
+ inherit (systemArgs.${system}) flake perSystem;
+ };
modules = [
# Machine's specific configuration
./machines/${name}
@@ -105,6 +98,7 @@
];
};
})
- machines);
+ (attrNames (readDir ./machines))
+ );
};
}