mirror of
https://github.com/JulienMalka/snowfield.git
synced 2025-03-25 21:30:52 +01:00
Added utils function to clean code
This commit is contained in:
parent
e84ad90ba8
commit
3a701f454d
2 changed files with 36 additions and 33 deletions
36
flake.nix
36
flake.nix
|
@ -20,38 +20,8 @@
|
|||
|
||||
outputs = { self, home-manager, nixpkgs, neovim-nightly-overlay, nur, ... }@inputs:
|
||||
let
|
||||
importDir = dir: pipe dir [
|
||||
builtins.readDir
|
||||
(mapAttrsToList (name: type:
|
||||
if type == "regular" && hasSuffix ".nix" name && name != "default.nix" then
|
||||
[{ name = removeSuffix ".nix" name; value = import (dir + "/${name}"); }]
|
||||
else if type == "directory" && pathExists (dir + "/${name}/default.nix") then
|
||||
[{ inherit name; value = import (dir + "/${name}"); }]
|
||||
else
|
||||
[ ]
|
||||
))
|
||||
concatLists
|
||||
listToAttrs
|
||||
];
|
||||
mkMachine = host: host-config: modules: {
|
||||
lisa = nixpkgs.lib.nixosSystem {
|
||||
system = "x86_64-linux";
|
||||
modules = builtins.attrValues modules ++ [
|
||||
./configuration.nix
|
||||
host-config
|
||||
home-manager.nixosModules.home-manager
|
||||
{
|
||||
home-manager.useGlobalPkgs = true;
|
||||
home-manager.useUserPackages = true;
|
||||
home-manager.users.julien = import ./config/home/home-lisa.nix;
|
||||
nixpkgs.overlays = [
|
||||
inputs.neovim-nightly-overlay.overlay
|
||||
];
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
in
|
||||
utils = import ./utils.nix { inherit nixpkgs home-manager inputs; };
|
||||
in with utils;
|
||||
{
|
||||
nixosModules = builtins.listToAttrs (map
|
||||
(x: {
|
||||
|
@ -60,7 +30,7 @@
|
|||
})
|
||||
(builtins.attrNames (builtins.readDir ./modules)));
|
||||
|
||||
nixosConfigurations = mapAttrs (name: value: (mkMachine name value nixosModules)) (importDir ./machines);
|
||||
nixosConfigurations = builtins.mapAttrs (name: value: (mkMachine name value self.nixosModules)) (importConfig ./machines);
|
||||
|
||||
|
||||
|
||||
|
|
33
utils.nix
Normal file
33
utils.nix
Normal file
|
@ -0,0 +1,33 @@
|
|||
{ nixpkgs, home-manager, inputs }:
|
||||
with builtins;
|
||||
|
||||
let mapAttrNames = f: set:
|
||||
listToAttrs (map (attr: { name = f attr; value = set.${attr}; }) (attrNames set));
|
||||
in
|
||||
{
|
||||
|
||||
mkMachine = host: host-config: modules: nixpkgs.lib.nixosSystem {
|
||||
system = "x86_64-linux";
|
||||
specialArgs = {
|
||||
inherit inputs;
|
||||
};
|
||||
modules = builtins.attrValues modules ++ [
|
||||
./configuration.nix
|
||||
host-config
|
||||
home-manager.nixosModules.home-manager
|
||||
{
|
||||
home-manager.useGlobalPkgs = true;
|
||||
home-manager.useUserPackages = true;
|
||||
home-manager.users.julien = import ./config/home/home-lisa.nix;
|
||||
nixpkgs.overlays = [
|
||||
inputs.neovim-nightly-overlay.overlay
|
||||
];
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
|
||||
importConfig = path: (mapAttrNames (name: nixpkgs.lib.removeSuffix ".nix" name)) ((builtins.mapAttrs (name: value: import (path + "/${name}")) (builtins.readDir path)));
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue