Skip to content

Commit 6c56844

Browse files
committed
refactor(nix): remove per-system functions
simply handled by setup.py
1 parent 2d54e65 commit 6c56844

File tree

2 files changed

+28
-30
lines changed

2 files changed

+28
-30
lines changed

flake.nix

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,61 +60,65 @@
6060
};
6161

6262
outputs = inputs @ { self, ... }:
63-
with self.lib;
63+
let
64+
inherit (self.lib) dotfiles;
65+
inherit (self.lib) pkgs;
66+
inherit (dotfiles) system;
67+
in
6468
{
6569
lib = inputs.nixpkgs.lib // import ./lib { inherit inputs; };
6670

67-
packages = foreachSystem (system:
68-
{
71+
packages = {
72+
${system} = {
6973
default =
7074
if dotfiles.profile == "home" then
7175
inputs.home-manager.packages.${system}.home-manager
7276
else if dotfiles.profile == "darwin" then
7377
inputs.darwin.packages.${system}.darwin-rebuild
7478
else if dotfiles.profile == "nixos" then
75-
pkgsBySystem.${system}.nixos-rebuild
79+
pkgs.nixos-rebuild
7680
else if dotfiles.profile == "" then
7781
builtins.abort "Empty profile type, please run setup.py with `--bootstrap`"
7882
else
7983
builtins.abort "Unknown profile type: '${dotfiles.profile}'"
8084
;
81-
}
82-
);
85+
};
86+
};
8387

84-
homeConfigurations = mkHome;
88+
homeConfigurations = self.lib.mkHome { };
8589

86-
nixosConfigurations = mkSystem {
90+
nixosConfigurations = self.lib.mkSystem {
8791
isDarwin = false;
8892
};
8993

90-
darwinConfigurations = mkSystem {
94+
darwinConfigurations = self.lib.mkSystem {
9195
# NOTE: home manager activation is showing following error
9296
# error: profile '/Users/william/.local/state/nix/profiles/profile' is incompatible with 'nix-env'; please use 'nix profile' instead
9397
# temporary workaround is to synlink ~/.local/state/nix/profile to ~/.nix-profile
9498
# ref: https://discourse.nixos.org/t/home-manager-insists-on-using-nix-profile/57708
9599
isDarwin = true;
96100
};
97101

98-
checks = foreachSystem (system: {
102+
checks = {
99103
pre-commit-check = inputs.git-hooks.lib.${system}.run {
100-
src = cleanSource ./.;
104+
src = self.lib.cleanSource ./.;
101105
hooks = {
102106
# TODO: treefmt, selene, shellcheck
103107
editorconfig-checker.enable = true;
104108
nixpkgs-fmt.enable = true;
105109
stylua = {
106110
enable = true;
107-
entry = "${pkgsBySystem.${system}.stylua}/bin/stylua --config-path ./config/nvim/stylua.toml";
111+
entry = "${pkgs.stylua}/bin/stylua --config-path ${dotfiles.directory}/config/nvim/stylua.toml";
108112
};
109113
};
110114
};
111-
});
115+
};
112116

113-
devShells = foreachSystem (system: {
114-
default = pkgsBySystem.${system}.mkShell {
117+
devShells = {
118+
default = pkgs.mkShell {
115119
inherit (self.checks.${system}.pre-commit-check) shellHook;
116120
buildInputs = self.checks.${system}.pre-commit-check.enabledPackages;
117121
};
118-
});
122+
};
119123
};
120124
}

lib/default.nix

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ let
66

77
inherit (inputs.nixpkgs) lib;
88

9-
systems = [ "x86_64-linux" "aarch64-darwin" ];
10-
foreachSystem = lib.genAttrs systems;
11-
12-
pkgsBySystem = foreachSystem (system:
9+
pkgs =
1310
# https://github.com/nix-community/home-manager/issues/2942#issuecomment-1378627909
1411
import inputs.nixpkgs {
15-
inherit system;
12+
inherit (dotfiles) system;
1613
overlays = [
1714
# TODO: this should be local to system specific home-manager module, and loaded conditionally
1815
inputs.niri.overlays.niri
@@ -26,10 +23,9 @@ let
2623
};
2724
};
2825
};
29-
}
30-
);
26+
};
3127

32-
fonts = pkgs: with pkgs; [
28+
fontPkgs = with pkgs; [
3329
maple-mono.Normal-NF-CN-unhinted
3430
maple-mono.NF-CN-unhinted
3531
] ++ (with nerd-fonts; [
@@ -40,11 +36,11 @@ let
4036
]);
4137
in
4238
{
43-
inherit foreachSystem pkgsBySystem dotfiles systems;
39+
inherit dotfiles pkgs;
4440

4541
stateVersion = "${builtins.elemAt (lib.splitString "-" lockfile.nodes.${input_name}.original.ref) 1}";
4642

47-
mkHome = let pkgs = pkgsBySystem.${dotfiles.system}; in {
43+
mkHome = {}: {
4844
${dotfiles.username} = inputs.home-manager.lib.homeManagerConfiguration {
4945
inherit pkgs;
5046
extraSpecialArgs = {
@@ -56,16 +52,14 @@ in
5652
./nix.nix
5753
{
5854
fonts.fontconfig.enable = true;
59-
home.packages = fonts pkgs;
55+
home.packages = fontPkgs;
6056
}
6157
];
6258
};
6359
};
6460

6561
mkSystem = { isDarwin }:
6662
let
67-
pkgs = pkgsBySystem.${dotfiles.system};
68-
6963
# NixOS vs nix-darwin functionst
7064
systemFunc = if isDarwin then inputs.darwin.lib.darwinSystem else inputs.nixpkgs.lib.nixosSystem;
7165
hmModules = if isDarwin then inputs.home-manager.darwinModules else inputs.home-manager.nixosModules;
@@ -80,7 +74,7 @@ in
8074
../system/${dotfiles.profile}
8175
hmModules.home-manager
8276
{
83-
fonts.packages = fonts pkgs;
77+
fonts.packages = fontPkgs;
8478
}
8579
] ++ (pkgs.lib.optionals pkgs.stdenv.isDarwin [
8680
inputs.homebrew.darwinModules.nix-homebrew

0 commit comments

Comments
 (0)