mirror of
https://github.com/Swarsel/.dotfiles.git
synced 2025-12-06 09:07:21 +01:00
docs: improve lib documentation (WIP)
This commit is contained in:
parent
b67abcce27
commit
e6038688ae
4 changed files with 46 additions and 52 deletions
|
|
@ -158,6 +158,7 @@ In =outputs = inputs@ [...]=, the =inputs@= makes it so that all inputs are auto
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
<<flakeoutputgeneral>>
|
<<flakeoutputgeneral>>
|
||||||
|
|
||||||
nixosConfigurations =
|
nixosConfigurations =
|
||||||
<<flakenixosconf>>
|
<<flakenixosconf>>
|
||||||
homeConfigurations =
|
homeConfigurations =
|
||||||
|
|
@ -166,6 +167,7 @@ In =outputs = inputs@ [...]=, the =inputs@= makes it so that all inputs are auto
|
||||||
<<flakedarwinconf>>
|
<<flakedarwinconf>>
|
||||||
nixOnDroidConfigurations =
|
nixOnDroidConfigurations =
|
||||||
<<flakedroidconf>>
|
<<flakedroidconf>>
|
||||||
|
|
||||||
topology =
|
topology =
|
||||||
<<topologyconf>>
|
<<topologyconf>>
|
||||||
};
|
};
|
||||||
|
|
@ -302,26 +304,15 @@ When setting this option normally, the password would normally be written world-
|
||||||
:CUSTOM_ID: h:df0072bc-853f-438f-bd85-bfc869501015
|
:CUSTOM_ID: h:df0072bc-853f-438f-bd85-bfc869501015
|
||||||
:END:
|
:END:
|
||||||
|
|
||||||
Here I define a few variables that I need for my system specifications. First and foremost, =pkgs=, which gets passed the emacs-overlay, nur, and nixgl modules to it. With this, I can grab all these packages by referencing =pkgs.<name>= instead of having to put e.g. =nixgl.auto.nixGLDefault=.
|
Here I define a few variables that I need for my system specifications. There used to be more here, but I managed to optimize my configuration, and only two things remain:
|
||||||
|
- =outputs=, which is needed for =lib=
|
||||||
The interesting part is in the start:
|
- =lib=: This exposes a common =lib= for NixOS and home-manager that is extended by my own personal =lib= functions.
|
||||||
- first, I define =pkgsFor=. This function reads all available systems from nixpkgs and generates pkgs for them.
|
|
||||||
- next, =forEachSystem= is a function that can be called to declare an output for each such defined system.
|
|
||||||
- =forAllSystems= is a crude function that I use for expressions that depend on =system=, as the prior two attributes already consumed it at that stage. This is only really used to generate the checks in their own file.
|
|
||||||
- =mkFullHost= is a function that takes a hostname as well as a boolean whether it is NixOS or not, and returns a matching =nixosSystem= or =darwinSystem=. This function is only used for systems that can use both NixOS and home-manager options (darwin still counts here as it can use some NixOS options).
|
|
||||||
- =mkFullHostConfigs= is the function that dynamically creates all definded hosts. The hosts are defined by placing a directory in =hosts/= under either the =nixos/= or =darwin/= directory. These directories are being read by =readHosts= and delivered to this funtion in the later call in [[#h:9c9b9e3b-8771-44fa-ba9e-5056ae809655][nixosConfigurations]] or [[#h:f881aa05-a670-48dd-a57b-2916abdcb692][darwinConfigurations]].
|
|
||||||
|
|
||||||
#+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).extend (_: _: { swarselsystems = import ./lib { inherit self lib inputs outputs systems; }; });
|
lib = (nixpkgs.lib // home-manager.lib).extend (_: _: { swarselsystems = import ./lib { inherit self lib inputs outputs systems; }; });
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Home-Manager modules wanted on non-NixOS systems
|
|
||||||
|
|
||||||
# Home-Manager modules wanted on both NixOS and non-NixOS systems
|
|
||||||
|
|
||||||
#+end_src
|
#+end_src
|
||||||
** General (outputs)
|
** General (outputs)
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
|
|
@ -4378,9 +4369,13 @@ This section defines all functions of my own that I add to =lib=. These are used
|
||||||
|
|
||||||
A breakdown of each function:
|
A breakdown of each function:
|
||||||
|
|
||||||
TODO
|
The interesting part is in the start:
|
||||||
|
- first, I define =pkgsFor=. This function reads all available systems from nixpkgs and generates pkgs for them.
|
||||||
|
- next, =forEachSystem= is a function that can be called to declare an output for each such defined system.
|
||||||
|
- =forAllSystems= is a crude function that I use for expressions that depend on =system=, as the prior two attributes already consumed it at that stage. This is only really used to generate the checks in their own file.
|
||||||
|
- =mkFullHostConfigs= is the function that dynamically creates all definded hosts. The hosts are defined by placing a directory in =hosts/= under either the =nixos/= or =darwin/= directory. These directories are being read by =readHosts= and delivered to this funtion in the later call in [[#h:9c9b9e3b-8771-44fa-ba9e-5056ae809655][nixosConfigurations]] or [[#h:f881aa05-a670-48dd-a57b-2916abdcb692][darwinConfigurations]].
|
||||||
- =mkFullHost=:
|
- =mkFullHost=:
|
||||||
This function is used in mkFullHostConfigs. It basically dynamically creates a nixosConfiguration host, setting its =speciaArgs= and =modules= attributes. The modules are populated based on whether this is a NixOS or darwin host. For the latter, I will only ever use machines that I get for testing from work, and for these my username is different, so I implemented an if-condition for it. This could be done more cleanly using variables, but some care needs to be taken with the home-manager imports and this approach works, so for now this is fine. Thanks to this function, the import sections of the host configs are pretty clean for most hosts.
|
This is a function that takes a hostname as well as a boolean whether it is NixOS or not, and returns a matching =nixosSystem= or =darwinSystem=. This function is only used for systems that can use both NixOS and home-manager options (darwin still counts here as it can use some NixOS options). This is used in mkFullHostConfigs. In more detail, it dynamically creates a nixosConfiguration host, setting its =speciaArgs= and =modules= attributes. The modules are populated based on whether this is a NixOS or darwin host. For the latter, I will only ever use machines that I get for testing from work, and for these my username is different, so I implemented an if-condition for it. This could be done more cleanly using variables, but some care needs to be taken with the home-manager imports and this approach works, so for now this is fine. Thanks to this function, the import sections of the host configs are pretty clean for most hosts.
|
||||||
=lib.optionals= evaluates to an empty list (=[]=) in case that the conditional is not met.
|
=lib.optionals= evaluates to an empty list (=[]=) in case that the conditional is not met.
|
||||||
TODO
|
TODO
|
||||||
|
|
||||||
|
|
@ -4428,11 +4423,11 @@ TODO
|
||||||
] ++
|
] ++
|
||||||
(if (host == "toto" || host == "iso") then [ ] else
|
(if (host == "toto" || host == "iso") then [ ] else
|
||||||
([
|
([
|
||||||
# put inports here that are for all servers and normal hosts
|
# put nixos imports here that are for all servers and normal hosts
|
||||||
inputs.nix-topology.nixosModules.default
|
inputs.nix-topology.nixosModules.default
|
||||||
] ++
|
] ++
|
||||||
(if (host == "winters" || host == "sync") then [ ] else [
|
(if (host == "winters" || host == "sync") then [ ] else [
|
||||||
# put imports here that are for all normal hosts
|
# put nixos imports here that are for all normal hosts
|
||||||
"${self}/profiles/${type}/common"
|
"${self}/profiles/${type}/common"
|
||||||
inputs.stylix.nixosModules.stylix
|
inputs.stylix.nixosModules.stylix
|
||||||
inputs.nswitch-rcm-nix.nixosModules.nswitch-rcm
|
inputs.nswitch-rcm-nix.nixosModules.nswitch-rcm
|
||||||
|
|
@ -4441,20 +4436,22 @@ TODO
|
||||||
{
|
{
|
||||||
home-manager.users.swarsel.imports = (
|
home-manager.users.swarsel.imports = (
|
||||||
if (host == "winters" || host == "sync") then [ ] else [
|
if (host == "winters" || host == "sync") then [ ] else [
|
||||||
# put imports here that are for all normal hosts
|
# put home-manager imports here that are for all normal hosts
|
||||||
"${self}/profiles/home/common"
|
"${self}/profiles/home/common"
|
||||||
]
|
]
|
||||||
) ++ [
|
) ++ [
|
||||||
# put inports here that are for all servers and normal hosts
|
# put home-manager imports here that are for all servers and normal hosts
|
||||||
inputs.sops-nix.homeManagerModules.sops
|
inputs.sops-nix.homeManagerModules.sops
|
||||||
inputs.nix-index-database.hmModules.nix-index
|
inputs.nix-index-database.hmModules.nix-index
|
||||||
] ++ (builtins.attrValues outputs.homeModules);
|
] ++ (builtins.attrValues outputs.homeModules);
|
||||||
}
|
}
|
||||||
] else [
|
] else [
|
||||||
|
# put nixos imports here that are for darwin hosts
|
||||||
"${self}/profiles/darwin/nixos/common"
|
"${self}/profiles/darwin/nixos/common"
|
||||||
inputs.home-manager.darwinModules.home-manager
|
inputs.home-manager.darwinModules.home-manager
|
||||||
{
|
{
|
||||||
home-manager.users."leon.schwarzaeugl".imports = [
|
home-manager.users."leon.schwarzaeugl".imports = [
|
||||||
|
# put home-manager imports here that are for darwin hosts
|
||||||
"${self}/profiles/darwin/home"
|
"${self}/profiles/darwin/home"
|
||||||
] ++ (builtins.attrValues outputs.homeModules);
|
] ++ (builtins.attrValues outputs.homeModules);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
43
flake.lock
generated
43
flake.lock
generated
|
|
@ -255,7 +255,6 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"flake-compat_6": {
|
"flake-compat_6": {
|
||||||
"flake": false,
|
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1733328505,
|
"lastModified": 1733328505,
|
||||||
"narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=",
|
"narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=",
|
||||||
|
|
@ -474,11 +473,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1735882644,
|
"lastModified": 1737465171,
|
||||||
"narHash": "sha256-3FZAG+pGt3OElQjesCAWeMkQ7C/nB1oTHLRQ8ceP110=",
|
"narHash": "sha256-R10v2hoJRLq8jcL4syVFag7nIGE7m13qO48wRIukWNg=",
|
||||||
"owner": "cachix",
|
"owner": "cachix",
|
||||||
"repo": "git-hooks.nix",
|
"repo": "git-hooks.nix",
|
||||||
"rev": "a5a961387e75ae44cc20f0a57ae463da5e959656",
|
"rev": "9364dc02281ce2d37a1f55b6e51f7c0f65a75f17",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
@ -640,11 +639,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1737630279,
|
"lastModified": 1740347597,
|
||||||
"narHash": "sha256-wJQCxyMRc4P26zDrHmZiRD5bbfcJpqPG3e2djdGG3pk=",
|
"narHash": "sha256-st5q9egkPGz8TUcVVlIQX7y6G3AzHob+6M963bwVq74=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "home-manager",
|
"repo": "home-manager",
|
||||||
"rev": "0db5c8bfcce78583ebbde0b2abbc95ad93445f7c",
|
"rev": "12e26a74e5eb1a31e13daaa08858689e25ebd449",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
@ -1168,11 +1167,11 @@
|
||||||
},
|
},
|
||||||
"nixpkgs_9": {
|
"nixpkgs_9": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1736798957,
|
"lastModified": 1740367490,
|
||||||
"narHash": "sha256-qwpCtZhSsSNQtK4xYGzMiyEDhkNzOCz/Vfu4oL2ETsQ=",
|
"narHash": "sha256-WGaHVAjcrv+Cun7zPlI41SerRtfknGQap281+AakSAw=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "9abb87b552b7f55ac8916b6fc9e5cb486656a2f3",
|
"rev": "0196c0175e9191c474c26ab5548db27ef5d34b05",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
@ -1285,11 +1284,11 @@
|
||||||
"treefmt-nix": "treefmt-nix_2"
|
"treefmt-nix": "treefmt-nix_2"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1739903703,
|
"lastModified": 1740408283,
|
||||||
"narHash": "sha256-w2tTcjx39lJoPDaFbIxi+INIjAKE0jbIx9TNjj9ghmg=",
|
"narHash": "sha256-2xECnhgF3MU9YjmvOkrRp8wRFo2OjjewgCtlfckhL5s=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "NUR",
|
"repo": "NUR",
|
||||||
"rev": "2215ad5c4347f522523715e809f5f2022509f504",
|
"rev": "496a4a11162bdffb9a7b258942de138873f019f7",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
@ -1500,11 +1499,11 @@
|
||||||
"tinted-zed": "tinted-zed"
|
"tinted-zed": "tinted-zed"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1740241659,
|
"lastModified": 1740520441,
|
||||||
"narHash": "sha256-2CXyPERfW6rm9R7nV73orfEsuqMlP/LoAfMUBK4s2jE=",
|
"narHash": "sha256-CWK3L7i7YqubbcrdS/5D/+Vo+IuClrNR+5B+ByhBlEo=",
|
||||||
"owner": "danth",
|
"owner": "danth",
|
||||||
"repo": "stylix",
|
"repo": "stylix",
|
||||||
"rev": "3a686a20b8f4dc026e561c1c5a85671c8cfeeb4f",
|
"rev": "a98c363a58accad047a2580382d90433619a08e0",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
@ -1610,11 +1609,11 @@
|
||||||
"tinted-schemes": {
|
"tinted-schemes": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1737565458,
|
"lastModified": 1740351358,
|
||||||
"narHash": "sha256-y+9cvOA6BLKT0WfebDsyUpUa/YxKow9hTjBp6HpQv68=",
|
"narHash": "sha256-Hdk850xgAd3DL8KX0AbyU7tC834d3Lej1jOo3duWiOA=",
|
||||||
"owner": "tinted-theming",
|
"owner": "tinted-theming",
|
||||||
"repo": "schemes",
|
"repo": "schemes",
|
||||||
"rev": "ae31625ba47aeaa4bf6a98cf11a8d4886f9463d9",
|
"rev": "a1bc2bd89e693e7e3f5764cfe8114e2ae150e184",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
@ -1626,11 +1625,11 @@
|
||||||
"tinted-tmux": {
|
"tinted-tmux": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1735737224,
|
"lastModified": 1740272597,
|
||||||
"narHash": "sha256-FO2hRBkZsjlIRqzNHCPc/52yxg11kHGA8MEtSun9RwE=",
|
"narHash": "sha256-/etfUV3HzAaLW3RSJVwUaW8ULbMn3v6wbTlXSKbcoWQ=",
|
||||||
"owner": "tinted-theming",
|
"owner": "tinted-theming",
|
||||||
"repo": "tinted-tmux",
|
"repo": "tinted-tmux",
|
||||||
"rev": "aead506a9930c717ebf81cc83a2126e9ca08fa64",
|
"rev": "b6c7f46c8718cc484f2db8b485b06e2a98304cd0",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
|
||||||
|
|
@ -90,12 +90,6 @@
|
||||||
inherit (self) outputs;
|
inherit (self) outputs;
|
||||||
lib = (nixpkgs.lib // home-manager.lib).extend (_: _: { swarselsystems = import ./lib { inherit self lib inputs outputs systems; }; });
|
lib = (nixpkgs.lib // home-manager.lib).extend (_: _: { swarselsystems = import ./lib { inherit self lib inputs outputs systems; }; });
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Home-Manager modules wanted on non-NixOS systems
|
|
||||||
|
|
||||||
# Home-Manager modules wanted on both NixOS and non-NixOS systems
|
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -157,6 +151,7 @@
|
||||||
import ./checks { inherit self inputs system pkgs; }
|
import ./checks { inherit self inputs system pkgs; }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
nixosConfigurations =
|
nixosConfigurations =
|
||||||
lib.swarselsystems.mkFullHostConfigs (lib.swarselsystems.readHosts "nixos") "nixos";
|
lib.swarselsystems.mkFullHostConfigs (lib.swarselsystems.readHosts "nixos") "nixos";
|
||||||
homeConfigurations =
|
homeConfigurations =
|
||||||
|
|
@ -183,6 +178,7 @@
|
||||||
|
|
||||||
lib.swarselsystems.mkHalfHostConfigs (lib.swarselsystems.readHosts "android") "android" lib.swarselsystems.pkgsFor.aarch64-linux;
|
lib.swarselsystems.mkHalfHostConfigs (lib.swarselsystems.readHosts "android") "android" lib.swarselsystems.pkgsFor.aarch64-linux;
|
||||||
|
|
||||||
|
|
||||||
topology =
|
topology =
|
||||||
|
|
||||||
lib.swarselsystems.forEachSystem (pkgs: import inputs.nix-topology {
|
lib.swarselsystems.forEachSystem (pkgs: import inputs.nix-topology {
|
||||||
|
|
|
||||||
|
|
@ -41,11 +41,11 @@
|
||||||
] ++
|
] ++
|
||||||
(if (host == "toto" || host == "iso") then [ ] else
|
(if (host == "toto" || host == "iso") then [ ] else
|
||||||
([
|
([
|
||||||
# put inports here that are for all servers and normal hosts
|
# put nixos imports here that are for all servers and normal hosts
|
||||||
inputs.nix-topology.nixosModules.default
|
inputs.nix-topology.nixosModules.default
|
||||||
] ++
|
] ++
|
||||||
(if (host == "winters" || host == "sync") then [ ] else [
|
(if (host == "winters" || host == "sync") then [ ] else [
|
||||||
# put imports here that are for all normal hosts
|
# put nixos imports here that are for all normal hosts
|
||||||
"${self}/profiles/${type}/common"
|
"${self}/profiles/${type}/common"
|
||||||
inputs.stylix.nixosModules.stylix
|
inputs.stylix.nixosModules.stylix
|
||||||
inputs.nswitch-rcm-nix.nixosModules.nswitch-rcm
|
inputs.nswitch-rcm-nix.nixosModules.nswitch-rcm
|
||||||
|
|
@ -54,20 +54,22 @@
|
||||||
{
|
{
|
||||||
home-manager.users.swarsel.imports = (
|
home-manager.users.swarsel.imports = (
|
||||||
if (host == "winters" || host == "sync") then [ ] else [
|
if (host == "winters" || host == "sync") then [ ] else [
|
||||||
# put imports here that are for all normal hosts
|
# put home-manager imports here that are for all normal hosts
|
||||||
"${self}/profiles/home/common"
|
"${self}/profiles/home/common"
|
||||||
]
|
]
|
||||||
) ++ [
|
) ++ [
|
||||||
# put inports here that are for all servers and normal hosts
|
# put home-manager imports here that are for all servers and normal hosts
|
||||||
inputs.sops-nix.homeManagerModules.sops
|
inputs.sops-nix.homeManagerModules.sops
|
||||||
inputs.nix-index-database.hmModules.nix-index
|
inputs.nix-index-database.hmModules.nix-index
|
||||||
] ++ (builtins.attrValues outputs.homeModules);
|
] ++ (builtins.attrValues outputs.homeModules);
|
||||||
}
|
}
|
||||||
] else [
|
] else [
|
||||||
|
# put nixos imports here that are for darwin hosts
|
||||||
"${self}/profiles/darwin/nixos/common"
|
"${self}/profiles/darwin/nixos/common"
|
||||||
inputs.home-manager.darwinModules.home-manager
|
inputs.home-manager.darwinModules.home-manager
|
||||||
{
|
{
|
||||||
home-manager.users."leon.schwarzaeugl".imports = [
|
home-manager.users."leon.schwarzaeugl".imports = [
|
||||||
|
# put home-manager imports here that are for darwin hosts
|
||||||
"${self}/profiles/darwin/home"
|
"${self}/profiles/darwin/home"
|
||||||
] ++ (builtins.attrValues outputs.homeModules);
|
] ++ (builtins.attrValues outputs.homeModules);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue