Skip to content

Commit

Permalink
refactor(flake): split flake configuration
Browse files Browse the repository at this point in the history
Also I cleaned up flake.nix
  • Loading branch information
Wittano committed Jul 21, 2024
1 parent 66d1163 commit 57a4ac6
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 72 deletions.
70 changes: 4 additions & 66 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,83 +49,21 @@

pkgs = mkPkgs inputs.nixpkgs;
unstable = mkPkgs inputs.nixpkgs-unstable;
oldPkgs = mkPkgs inputs.oldNixpkgs;

privateRepo = lib.my.pkgs.importPkgs ./pkgs;

lib = nixpkgs.lib.extend (sefl: super: {
hm = home-manager.lib.hm;
my = import ./lib { inherit lib system inputs pkgs unstable privateRepo oldPkgs; };
my = import ./lib { inherit lib system inputs pkgs unstable privateRepo; };
});

templatesDirs = builtins.attrNames
(lib.filterAttrs (n: v: v == "directory")
(builtins.readDir ./templates));

templates = lib.lists.forEach templatesDirs (name: {
inherit name;

value = {
path = ./templates/${name};
description = "Template for ${name}";
};
});

devShells =
let
shellPkgs = import inputs.nixpkgs-unstable {
inherit system;

config = {
allowUnfree = true;
allowBroken = true;
};
};
names = lib.my.string.mkNixNamesFromDir ./shells;
mkShellAttrs = name: {
inherit name;
value = pkgs.callPackage (./shells + "/${name}.nix") { unstable = shellPkgs; };
};
shells = builtins.listToAttrs (builtins.map mkShellAttrs names);
in
shells;
in
{
lib = lib.my;

nixosConfigurations =
let
inherit (lib.attrsets) nameValuePair;
inherit (lib.my.hosts) mkHost;
inherit (lib.lists) flatten;

hosts = builtins.attrNames (builtins.readDir ./hosts);
desktopHosts = lib.my.string.mkNixNamesFromDir ./modules/desktop/wm;

finalHosts = (flatten (builtins.map (x: builtins.map (d: "${x}-${d}") desktopHosts) hosts)) ++ hosts;

devHosts = builtins.listToAttrs (builtins.map
(n:
let devName = "${n}-dev";
in
nameValuePair (devName) (mkHost {
name = devName;
isDevMode = true;
}))
finalHosts);

normalHosts = builtins.listToAttrs (builtins.map
(name: {
inherit name;
value = mkHost { inherit name; };
})
finalHosts);
in
normalHosts // devHosts;

nixosConfigurations = import ./nixos-configs.nix { inherit lib; };
overlays.default = overlays.overlay;
devShells.${pkgs.system} = devShells;
devShells.${system} = import ./shells.nix { inherit inputs lib pkgs; };
packages.${system} = privateRepo;
templates = builtins.listToAttrs templates;
templates = import ./templates.nix { inherit lib; };
};
}
4 changes: 2 additions & 2 deletions lib/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lib, system, inputs, pkgs, unstable, privateRepo, oldPkgs, ... }:
{ lib, system, inputs, pkgs, unstable, privateRepo, ... }:
with lib;
let
dotfilesPath = ./../dotfiles;
Expand All @@ -7,6 +7,6 @@ in
attrsets.mapAttrs'
(n: v: {
name = strings.removeSuffix ".nix" n;
value = import (./. + "/${n}") { inherit lib pkgs dotfilesPath privateRepo unstable inputs system secretDir oldPkgs; };
value = import (./. + "/${n}") { inherit lib pkgs dotfilesPath privateRepo unstable inputs system secretDir; };
})
(builtins.readDir ./.)
4 changes: 2 additions & 2 deletions lib/desktop.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs, lib, unstable, secretDir, oldPkgs, ... }:
{ pkgs, lib, unstable, secretDir, ... }:
with lib;
with lib.my;
let
Expand Down Expand Up @@ -30,7 +30,7 @@ let
'';

mkDesktopApp = config: dotfiles: name: desktopName: import (./../modules/desktop/submodules + "/${name}.nix") {
inherit pkgs dotfiles config unstable lib desktopName secretDir oldPkgs;
inherit pkgs dotfiles config unstable lib desktopName secretDir;
};
in
{
Expand Down
4 changes: 2 additions & 2 deletions lib/hosts.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lib, system, pkgs, unstable, privateRepo, inputs, dotfilesPath, secretDir, oldPkgs, ... }:
{ lib, system, pkgs, unstable, privateRepo, inputs, dotfilesPath, secretDir, ... }:
with lib;
with lib.my;
let
Expand Down Expand Up @@ -39,7 +39,7 @@ in
inherit system;

specialArgs = {
inherit pkgs unstable lib dotfiles isDevMode inputs privateRepo system hostname desktopName secretDir oldPkgs;
inherit pkgs unstable lib dotfiles isDevMode inputs privateRepo system hostname desktopName secretDir;
templateDir = ./../templates;
};

Expand Down
29 changes: 29 additions & 0 deletions nixos-configs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{ lib, ... }:
let
inherit (lib.attrsets) nameValuePair;
inherit (lib.my.hosts) mkHost;
inherit (lib.lists) flatten;

hosts = builtins.attrNames (builtins.readDir ./hosts);
desktopHosts = lib.my.string.mkNixNamesFromDir ./modules/desktop/wm;

finalHosts = (flatten (builtins.map (x: builtins.map (d: "${x}-${d}") desktopHosts) hosts)) ++ hosts;

devHosts = builtins.listToAttrs (builtins.map
(n:
let devName = "${n}-dev";
in
nameValuePair (devName) (mkHost {
name = devName;
isDevMode = true;
}))
finalHosts);

normalHosts = builtins.listToAttrs (builtins.map
(name: {
inherit name;
value = mkHost { inherit name; };
})
finalHosts);
in
normalHosts // devHosts
17 changes: 17 additions & 0 deletions shells.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{ inputs, lib, pkgs, ... }: with lib;
with lib.my; let
shellPkgs = import inputs.nixpkgs-unstable {
inherit system;

config = {
allowUnfree = true;
allowBroken = true;
};
};
names = lib.my.string.mkNixNamesFromDir ./shells;
mkShellAttrs = name: {
inherit name;
value = pkgs.callPackage (./shells + "/${name}.nix") { unstable = shellPkgs; };
};
in
builtins.listToAttrs (builtins.map mkShellAttrs names)
15 changes: 15 additions & 0 deletions templates.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{ lib, ... }: with lib; with lib.my; let
templatesDirs = builtins.attrNames
(lib.filterAttrs (n: v: v == "directory")
(builtins.readDir ./templates));

templates = lists.forEach templatesDirs (name: {
inherit name;

value = {
path = ./templates/${name};
description = "Template for ${name}";
};
});
in
builtins.listToAttrs templates

0 comments on commit 57a4ac6

Please sign in to comment.