feat: add nix-topology

This commit is contained in:
Swarsel 2024-12-28 12:34:34 +01:00
parent dcb18d99b0
commit 47b99bb39d
Signed by: swarsel
GPG key ID: 26A54C31F2A4FD84
4 changed files with 1025 additions and 827 deletions

View file

@ -715,7 +715,7 @@ In =outputs = inputs@ [...]=, the =inputs@= makes it so that all inputs are auto
<<flakenixosconf>> <<flakenixosconf>>
homeConfigurations = { homeConfigurations = {
<<flakehomeconf>> <<flakehomeconf>>
}; };
darwinConfigurations = darwinConfigurations =
@ -725,6 +725,9 @@ In =outputs = inputs@ [...]=, the =inputs@= makes it so that all inputs are auto
<<flakedroidconf>> <<flakedroidconf>>
}; };
topology =
<<topologyconf>>
}; };
} }
@ -836,6 +839,8 @@ A short overview over each input and what it does:
This is a private repository that I use for settings in modules that do not expose a =secretsFile= (or similar) option. An example is the =LastFM.ApiKey= option in [[#h:f347f3ad-5100-4c4f-8616-cfd7f8e14a72][navidrome]]: This is a private repository that I use for settings in modules that do not expose a =secretsFile= (or similar) option. An example is the =LastFM.ApiKey= option in [[#h:f347f3ad-5100-4c4f-8616-cfd7f8e14a72][navidrome]]:
=LastFM.ApiKey = builtins.readFile "${secretsDirectory}/navidrome/lastfm-secret";= =LastFM.ApiKey = builtins.readFile "${secretsDirectory}/navidrome/lastfm-secret";=
When setting this option normally, the password would normally be written world-readable not only in the nix store, but also in the configuration. Hence, I put such passwords into a private repository. This allows me to keep purity of the flake while keeping a level of security on these secrets. When setting this option normally, the password would normally be written world-readable not only in the nix store, but also in the configuration. Hence, I put such passwords into a private repository. This allows me to keep purity of the flake while keeping a level of security on these secrets.
- [[https://github.com/oddlama/nix-topology][nix-topology]]
This automatically creates a topology diagram of my configuration.
#+begin_src nix :tangle no :noweb-ref flakeinputs #+begin_src nix :tangle no :noweb-ref flakeinputs
@ -939,6 +944,8 @@ When setting this option normally, the password would normally be written world-
inputs = { }; inputs = { };
}; };
nix-topology.url = "github:oddlama/nix-topology";
#+end_src #+end_src
** let ** let
:PROPERTIES: :PROPERTIES:
@ -958,69 +965,70 @@ The interesting part is in the start:
#+begin_src nix :tangle no :noweb-ref flakelet #+begin_src nix :tangle no :noweb-ref flakelet
inherit (self) outputs; inherit (self) outputs;
lib = nixpkgs.lib // home-manager.lib; lib = nixpkgs.lib // home-manager.lib;
pkgsFor = lib.genAttrs (import systems) ( pkgsFor = lib.genAttrs (import systems) (
system: system:
import nixpkgs { import nixpkgs {
inherit system; inherit system;
config.allowUnfree = true; config.allowUnfree = true;
} }
); );
forEachSystem = f: lib.genAttrs (import systems) (system: f pkgsFor.${system}); forEachSystem = f: lib.genAttrs (import systems) (system: f pkgsFor.${system});
forAllSystems = lib.genAttrs [ forAllSystems = lib.genAttrs [
"x86_64-linux" "x86_64-linux"
"aarch64-linux" "aarch64-linux"
"x86_64-darwin" "x86_64-darwin"
"aarch64-darwin" "aarch64-darwin"
]; ];
mkFullHost = host: isNixos: { mkFullHost = host: isNixos: {
${host} = ${host} =
let let
func = if isNixos then lib.nixosSystem else inputs.nix-darwin.lib.darwinSystem; func = if isNixos then lib.nixosSystem else inputs.nix-darwin.lib.darwinSystem;
systemFunc = func; systemFunc = func;
in in
systemFunc { systemFunc {
specialArgs = { specialArgs = {
inherit inputs outputs self; inherit inputs outputs self;
lib = lib.extend (_: _: { swarselsystems = import ./lib { inherit lib; }; }); lib = lib.extend (_: _: { swarselsystems = import ./lib { inherit lib; }; });
};
modules = [ ./hosts/${if isNixos then "nixos" else "darwin"}/${host} ];
}; };
modules = [ ./hosts/${if isNixos then "nixos" else "darwin"}/${host} ]; };
}; mkFullHostConfigs = hosts: isNixos: lib.foldl (acc: set: acc // set) { } (lib.map (host: mkFullHost host isNixos) hosts);
}; readHosts = folder: lib.attrNames (builtins.readDir ./hosts/${folder});
mkFullHostConfigs = hosts: isNixos: lib.foldl (acc: set: acc // set) { } (lib.map (host: mkFullHost host isNixos) hosts);
readHosts = folder: lib.attrNames (builtins.readDir ./hosts/${folder});
# NixOS modules that can only be used on NixOS systems # NixOS modules that can only be used on NixOS systems
nixModules = [ nixModules = [
inputs.stylix.nixosModules.stylix inputs.stylix.nixosModules.stylix
inputs.lanzaboote.nixosModules.lanzaboote inputs.lanzaboote.nixosModules.lanzaboote
inputs.disko.nixosModules.disko inputs.disko.nixosModules.disko
inputs.impermanence.nixosModules.impermanence inputs.impermanence.nixosModules.impermanence
inputs.sops-nix.nixosModules.sops inputs.sops-nix.nixosModules.sops
inputs.nswitch-rcm-nix.nixosModules.nswitch-rcm inputs.nswitch-rcm-nix.nixosModules.nswitch-rcm
./profiles/common/nixos inputs.nix-topology.nixosModules.default
]; ./profiles/common/nixos
];
# Home-Manager modules wanted on non-NixOS systems # Home-Manager modules wanted on non-NixOS systems
homeModules = [ homeModules = [
inputs.stylix.homeManagerModules.stylix inputs.stylix.homeManagerModules.stylix
]; ];
# Home-Manager modules wanted on both NixOS and non-NixOS systems # Home-Manager modules wanted on both NixOS and non-NixOS systems
mixedModules = [ mixedModules = [
inputs.sops-nix.homeManagerModules.sops inputs.sops-nix.homeManagerModules.sops
inputs.nix-index-database.hmModules.nix-index inputs.nix-index-database.hmModules.nix-index
./profiles/common/home ./profiles/common/home
]; ];
# For adding things to _module.args (making arguments available globally) # For adding things to _module.args (making arguments available globally)
# moduleArgs = [ # moduleArgs = [
# { # {
# _module.args = { inherit self; }; # _module.args = { inherit self; };
# } # }
# ]; # ];
#+end_src #+end_src
** General (outputs) ** General (outputs)
@ -1171,6 +1179,22 @@ Nix on Android also demands an own flake output, which is provided here.
#+end_src #+end_src
** topologyConfigurations
#+begin_src nix :tangle no :noweb-ref topologyconf
forEachSystem (pkgs: import inputs.nix-topology {
inherit pkgs;
modules = [
# Your own file to define global topology. Works in principle like a nixos module but uses different options.
# ./topology.nix
{ inherit (self) nixosConfigurations; }
];
});
#+end_src
* System * System
:PROPERTIES: :PROPERTIES:
:CUSTOM_ID: h:02cd20be-1ffa-4904-9d5a-da5a89ba1421 :CUSTOM_ID: h:02cd20be-1ffa-4904-9d5a-da5a89ba1421
@ -3557,6 +3581,7 @@ When adding a new entry here, do not forget to add it in the default output of t
// (zjstatus final prev) // (zjstatus final prev)
// (inputs.nur.overlays.default final prev) // (inputs.nur.overlays.default final prev)
// (inputs.emacs-overlay.overlay final prev) // (inputs.emacs-overlay.overlay final prev)
// (inputs.nix-topology.overlays.default final prev)
// (inputs.nixgl.overlay final prev); // (inputs.nixgl.overlay final prev);
} }

1695
flake.lock generated

File diff suppressed because it is too large Load diff

View file

@ -115,6 +115,8 @@
inputs = { }; inputs = { };
}; };
nix-topology.url = "github:oddlama/nix-topology";
}; };
outputs = outputs =
@ -169,6 +171,7 @@
inputs.impermanence.nixosModules.impermanence inputs.impermanence.nixosModules.impermanence
inputs.sops-nix.nixosModules.sops inputs.sops-nix.nixosModules.sops
inputs.nswitch-rcm-nix.nixosModules.nswitch-rcm inputs.nswitch-rcm-nix.nixosModules.nswitch-rcm
inputs.nix-topology.nixosModules.default
./profiles/common/nixos ./profiles/common/nixos
]; ];
@ -284,5 +287,17 @@
}; };
topology =
forEachSystem (pkgs: import inputs.nix-topology {
inherit pkgs;
modules = [
# Your own file to define global topology. Works in principle like a nixos module but uses different options.
# ./topology.nix
{ inherit (self) nixosConfigurations; }
];
});
}; };
} }

View file

@ -65,6 +65,7 @@ in
// (zjstatus final prev) // (zjstatus final prev)
// (inputs.nur.overlays.default final prev) // (inputs.nur.overlays.default final prev)
// (inputs.emacs-overlay.overlay final prev) // (inputs.emacs-overlay.overlay final prev)
// (inputs.nix-topology.overlays.default final prev)
// (inputs.nixgl.overlay final prev); // (inputs.nixgl.overlay final prev);
} }