-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
125 lines (112 loc) · 4.18 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
{
description = "Pumita's configuration";
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
home-manager = { inputs.nixpkgs.follows = "nixpkgs"; url = "github:nix-community/home-manager"; };
# custom inputs
dotfiles = { inputs.nixpkgs.follows = "nixpkgs"; url = "github:cosasdepuma/.dotfiles"; };
};
outputs = { nixpkgs, ... } @ inputs:
let
# forAllSystems :: fn: str -> set
# generates the same configuration for multiple system archs
forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed;
# loadModules :: str -> list
# load all the default modules from inputs
loadModules = t: nixpkgs.lib.mapAttrsToList (_: v:
if builtins.hasAttr t v then
if builtins.hasAttr "default" v."${t}" then
v."${t}".default
else {}
else {}) inputs;
# mkShells :: set -> set
# generates multiples development shells
mkShells = pkgs: with builtins;
listToAttrs
(map (x: { name = (nixpkgs.lib.removeSuffix ".nix" x); value = (import ./shells/${x} { inherit pkgs; }); })
(filter (x: (match ".+\.nix$" x) != null) (attrNames (readDir ./shells))));
# mkHosts :: list -> set
# generates multiples nixosConfigutations
mkHosts = hosts: builtins.mapAttrs (hostname: v: mkHost ({ inherit hostname; } // v)) hosts;
# mkHost :: set -> set
# generates a nixosConfiguration based on the machine hostname
mkHost = {
hostname,
version ? "23.05",
system ? "x86_64-linux",
layout ? "us,es",
allowUnfree ? true,
autoLogin ? true,
shell ? "fish",
editor ? "neovim",
overlays ? import ./overlays,
user ? { name = "puma"; description = "Pumita"; },
repository ? "github:cosasdepuma/nixos",
...
}: nixpkgs.lib.nixosSystem {
inherit system;
modules = (loadModules "nixosModules") ++ [
./hardware-configuration.nix
./configuration.nix
./host/${hostname}.nix
];
specialArgs = {
inherit inputs hostname user version;
opts = { inherit layout allowUnfree autoLogin overlays repository; };
};
};
# mkHomes :: list -> set
# generates multiples homeConfigurations
mkHomes = homes: builtins.mapAttrs (user: v: mkHome ({ inherit user; } // v)) homes;
# mkHome :: set -> set
# generates a homeConfiguration based on the user name
mkHome = {
user,
profile ? "default",
version ? "23.05",
system ? "x86_64-linux",
allowUnfree ? true,
...
}: inputs.home-manager.lib.homeManagerConfiguration {
pkgs = nixpkgs.legacyPackages."${system}";
modules = (loadModules "homeManagerModules") ++ [
({
programs.home-manager.enable = true;
home.stateVersion = version;
home.username = user;
home.homeDirectory = "/home/${user}"; # FIXME: Make it MacOS compatible (/Users/${user})
nixpkgs.config.allowUnfree = allowUnfree;
nixpkgs.config.allowUnfreePreciate = (_: allowUnfree);
systemd.user.startServices = "sd-switch";
})
./home/${profile}.nix
];
extraSpecialArgs = { inherit inputs user version; };
};
in {
# ------------------------------
# Development Shells
# ------------------------------
# Shell environments available throught `nix develop --flake /etc/nixos#$ENVIRONMENT`
devShells = forAllSystems (system:
let pkgs = nixpkgs.legacyPackages."${system}";
in mkShells pkgs
);
# ------------------------------
# System
# ------------------------------
# System configuration available through `nixos-rebuild switch --flake /etc/nixos#$HOSTNAME`
nixosConfigurations = mkHosts {
# Void VM
void = { user.name = "entity"; user.description = "An empty entity"; };
};
# ------------------------------
# Home Manager
# ------------------------------
# Home configuration available through `home-manager switch --flake /etc/nixos#$USER`
homeConfigurations = mkHomes {
# Pumita's home
entity = {};
};
};
}