Working on modularizing stuff
This commit is contained in:
parent
835faf218d
commit
8349809fec
15 changed files with 256 additions and 41 deletions
22
default.nix
Normal file
22
default.nix
Normal file
|
@ -0,0 +1,22 @@
|
|||
{ inputs, config, lib, pkgs, ... }:
|
||||
let
|
||||
inherit (builtins) toString;
|
||||
inherit (lib.attrsets) attrValues filterAttrs mapAttrs mapAttrsToList;
|
||||
inherit (lib.modules) mkAliasOptionModule mkDefault mkIf;
|
||||
inherit (lib.my) mapModulesRec';
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
inputs.home-manager.nixosModules.home-manager
|
||||
(mkAliasOptionModule ["hm"] ["home-manager" "users" config.user.name])
|
||||
]
|
||||
++ (mapModulesRec' (toString ./modules) import);
|
||||
|
||||
environments.variables = {
|
||||
};
|
||||
|
||||
system = {
|
||||
stateVersion = "23.11";
|
||||
configurationRevision = with inputs; mkIf (self ? rev) self.rev;
|
||||
};
|
||||
}
|
59
flake.nix
59
flake.nix
|
@ -12,17 +12,54 @@
|
|||
stylix.url = "github:danth/stylix";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, ... }@inputs: {
|
||||
nixosConfigurations = {
|
||||
default = nixpkgs.lib.nixosSystem {
|
||||
specialArgs = {inherit inputs;};
|
||||
modules = [
|
||||
./hosts/default/configuration.nix
|
||||
inputs.home-manager.nixosModules.default
|
||||
inputs.stylix.nixosModules.stylix
|
||||
];
|
||||
};
|
||||
outputs = { self, nixpkgs, ... }@inputs: let
|
||||
inherit (lib.my) mapModules mapModules mapHosts;
|
||||
|
||||
};
|
||||
mkPkgs = pkgs: extraOverlays:
|
||||
import pkgs {
|
||||
inherit system;
|
||||
config.allowUnfree = true;
|
||||
overlays = extraOverlays ++ (lib.attrValues self.overlays);
|
||||
};
|
||||
pkgs = mkPkgs nixpkgs [self.overlays.default];
|
||||
pkgs-unstable = mkPkgs nixpkgs-unstable [];
|
||||
|
||||
lib = nixpkgs.lib.extend (final: prev: {
|
||||
my = import ./lib {
|
||||
inherit pkgs inputs;
|
||||
|
||||
lib = final;
|
||||
};
|
||||
});
|
||||
in {
|
||||
lib = lib.my;
|
||||
|
||||
packages."${system}" = mapModules ./paclages (p: pkgs.callPackage p {});
|
||||
|
||||
nixosModules =
|
||||
{
|
||||
chris = import ./.;
|
||||
}
|
||||
// mapModulesRec ./modules import;
|
||||
|
||||
nixosConfigurations = mapHosts ./hosts {};
|
||||
|
||||
devShells."${system}".default = import ./shell.nix { inherit lib pkgs; };
|
||||
|
||||
|
||||
|
||||
# nixosConfigurations = {
|
||||
# pc = nixpkgs.lib.nixosSystem {
|
||||
# specialArgs = {inherit inputs;};
|
||||
# modules = [
|
||||
# ./hosts/pc/default.nix
|
||||
# inputs.home-manager.nixosModules.default
|
||||
# inputs.stylix.nixosModules.stylix
|
||||
# ];
|
||||
# };
|
||||
# };
|
||||
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
|
2
hosts/laptop/default.nix
Normal file
2
hosts/laptop/default.nix
Normal file
|
@ -0,0 +1,2 @@
|
|||
{}:
|
||||
{}
|
36
hosts/pc/default.nix
Normal file
36
hosts/pc/default.nix
Normal file
|
@ -0,0 +1,36 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
{
|
||||
imports = [ ./hardware-configuration.nix ];
|
||||
|
||||
modules = {
|
||||
themes.active = "everforrest";
|
||||
|
||||
desktop = {
|
||||
plasma.enable = true;
|
||||
|
||||
terminal = {
|
||||
default = "alacritty";
|
||||
allacrity.enable = true;
|
||||
};
|
||||
|
||||
editors = {
|
||||
default = "nano";
|
||||
nano.enable = true;
|
||||
};
|
||||
|
||||
browsers = {
|
||||
default = "firefox";
|
||||
firefox.enable = true;
|
||||
};
|
||||
};
|
||||
|
||||
shell = {
|
||||
default = "zsh";
|
||||
toolset = {
|
||||
git.enable = true;
|
||||
gnupg.enable = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
imports = [
|
||||
./hardware-configuration.nix
|
||||
../../modules/system/boot.nix
|
||||
../../modules/system/networking.nix
|
||||
../../modules/system/audio.nix
|
||||
../../modules/system/zsa_voyager.nix
|
||||
|
||||
|
@ -25,33 +26,8 @@
|
|||
allowUnfree = true;
|
||||
};
|
||||
|
||||
networking.hostName = "chris-pc";
|
||||
# Pick only one of the below networking options.
|
||||
# networking.wireless.enable = true; # Enables wireless support via wpa_supplicant.
|
||||
networking.networkmanager.enable = true; # Easiest to use and most distros use this by default.
|
||||
|
||||
nix.settings.experimental-features = [ "nix-command" "flakes" ];
|
||||
|
||||
# Set your time zone.
|
||||
time.timeZone = "Europe/Amsterdam";
|
||||
|
||||
# Enable the X11 windowing system.
|
||||
services.xserver.enable = true;
|
||||
|
||||
|
||||
# Enable sound.
|
||||
sound.enable = false;
|
||||
hardware.pulseaudio.enable = false;
|
||||
users.extraGroups.audio.members = [ "chris" ];
|
||||
security.rtkit.enable = true;
|
||||
services.pipewire = {
|
||||
enable = true;
|
||||
alsa.enable = true
|
||||
alsa.support32Bit = true;
|
||||
pulse.enable = true;
|
||||
jack.enable = true;
|
||||
};
|
||||
|
||||
# Define a user account. Don't forget to set a password with ‘passwd’.
|
||||
users.users.chris = {
|
||||
isNormalUser = true;
|
||||
|
@ -76,7 +52,6 @@
|
|||
# chromium
|
||||
thunderbird
|
||||
zoxide
|
||||
bottles
|
||||
atuin
|
||||
btop
|
||||
dust
|
||||
|
@ -86,9 +61,6 @@
|
|||
nextcloud-client
|
||||
];
|
||||
|
||||
# session variable for chrome/electron wayland
|
||||
environment.sessionVariables.NIXOS_OZONE_WL = "1";
|
||||
|
||||
systemd.services.numLockOnTty = {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
serviceConfig = {
|
2
hosts/server/default.nix
Normal file
2
hosts/server/default.nix
Normal file
|
@ -0,0 +1,2 @@
|
|||
{}:
|
||||
{}
|
21
lib/attrs.nix
Normal file
21
lib/attrs.nix
Normal file
|
@ -0,0 +1,21 @@
|
|||
{ lib, ... }:
|
||||
let
|
||||
inherit (lib.lists) any count;
|
||||
inherit (lib.attrsets) filterAttrs listToAttrs mapAttrs' mapAttrsToList;
|
||||
in rec
|
||||
{
|
||||
attrsToList = attrs:
|
||||
mapAttrsToList (name: value: { inherit name value; }) attrs;
|
||||
|
||||
mapFilterAttrs = pred: f: attrs:
|
||||
filterAttrs pred (mapAttrs' f attrs);
|
||||
|
||||
getAttrs' = values: f:
|
||||
listToAttrs (map f values);
|
||||
|
||||
anyAttrs = pred: attrs:
|
||||
any (attr: pred attr.name attr.value) (attrsToList attrs);
|
||||
|
||||
countAttrs = pred: attrs:
|
||||
count (attr: pred attr.name attr.value) (attrsToList attrs);
|
||||
}
|
22
lib/default.nix
Normal file
22
lib/default.nix
Normal file
|
@ -0,0 +1,22 @@
|
|||
{ inputs, lib, pkgs, ... }:
|
||||
let
|
||||
inherit (lib.attrsets) attrValues;
|
||||
inherit (lib.fixedPoints) makeExtensible;
|
||||
inherit (lib.lists) foldr;
|
||||
inherit (modules) mapModules;
|
||||
|
||||
modules = import ./modules.nix {
|
||||
inherit lib;
|
||||
|
||||
self.attrs = import ./attrs.nix {
|
||||
inherit lib;
|
||||
|
||||
self = {};
|
||||
};
|
||||
};
|
||||
|
||||
mylib = makeExensible (self:
|
||||
mapModules ./. (file: import file { inherit self lib pkgs inputs; })
|
||||
);
|
||||
in
|
||||
mylib.extend (self: super: foldr (a: b: a // b) {} (attrValues super))
|
36
lib/modules.nix
Normal file
36
lib/modules.nix
Normal file
|
@ -0,0 +1,36 @@
|
|||
{ lib, self, ... }:
|
||||
let
|
||||
inherit (builtins) attrValues readDir pathExists concatLists;
|
||||
inherit (lib.attrsets) mapAttrsToList filterAttrs nameValuePair;
|
||||
inherit (lib.strings) hasPrefix hasSuffix removeSuffix;
|
||||
inherit (lib.trivial) id;
|
||||
inherit (self.attrs) mapFilterAttrs;
|
||||
in rec
|
||||
{
|
||||
mapModules = dir: fn:
|
||||
mapFilterAttrs (n: v: v != null && !(hasPrefix "_" n)) (n: v: let path = "${toString dir}/${n}"; in
|
||||
if v == "directory" && pathExists "${path}/default.nix"
|
||||
then nameValuePair n (fn path)
|
||||
else if v == "regular" && n != "default.nix" && hasSuffix ".nix" n
|
||||
then nameValuePair (removeSuffix ".nix" n) (fn path)
|
||||
else nameValuePair "" null
|
||||
) (readDir dir);
|
||||
|
||||
mapModules' = dir: fn: attrValues (mapModules dir fn);
|
||||
|
||||
mapModulesRec = dir: fn:
|
||||
mapFilterAttrs (n: v: v != null && !(hasPrefix "_" n)) (n: v: let path = "${toString dir}/${n}"; in
|
||||
if v == "directory" && pathExists "${path}/default.nix"
|
||||
then nameValuePair n (mapModulesRec path fn)
|
||||
else if v == "regular" && n != "default.nix" && hasSuffix ".nix" n
|
||||
then nameValuePair (removeSuffix ".nix" n) (fn path)
|
||||
else nameValuePair "" null
|
||||
) (readDir dir);
|
||||
|
||||
mapModulesRec' = dir: fn: let
|
||||
dirs = mapAttrsToList (k: _: "${dir}/${k}") (filterAttrs (n: v: v == "directory" && !(hasPrefix "_" n)) (readDir dir));
|
||||
files = attrValues (mapModules dir id);
|
||||
paths = files ++ contactLists (map (d: mapModulesRec' d id) dirs);
|
||||
in
|
||||
map fn paths;
|
||||
}
|
30
lib/nixos.nix
Normal file
30
lib/nixos.nix
Normal file
|
@ -0,0 +1,30 @@
|
|||
{ inputs, lib, pkgs, self, ... }:
|
||||
let
|
||||
inherit (inputs.nixpkgs.lib) nixosSystem;
|
||||
inherit (builtins) baseNameOf elem;
|
||||
inherit (lib.attrsets) filterAttrs;
|
||||
inherit (lib.modules) mkDefault;
|
||||
inherit (lib.strings) removeSuffix;
|
||||
inherit (self.modules) mapModules;
|
||||
in rec
|
||||
{
|
||||
mkHost = path: attrs @ {sytem ? "x86_64-linux", ...}:
|
||||
nixosSystem {
|
||||
inherit system;
|
||||
|
||||
specialArgs = { inherit lib input system; };
|
||||
|
||||
modules = [
|
||||
{
|
||||
nixpkgs.pkgs = pkgs;
|
||||
networking.hostName = mkDefault (removeSuffix ".nix" (baseNameOf path));
|
||||
}
|
||||
(filterAttrs (n: v: !elem n ["system"]) attrs)
|
||||
../. # ../default.nix
|
||||
(import path)
|
||||
];
|
||||
};
|
||||
|
||||
mapHosts = dir: attrs @ { system ? system, ... }:
|
||||
mapModules dir (hostPath: mkHost hostPath attrs);
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
{ pkgs, ... }:
|
||||
{
|
||||
services = {
|
||||
xserver.enable = true;
|
||||
|
||||
displayManager = {
|
||||
sddm = {
|
||||
enable = true;
|
||||
|
@ -11,9 +13,11 @@
|
|||
user = "chris";
|
||||
};
|
||||
};
|
||||
|
||||
desktopManager.plasma6.enable = true;
|
||||
};
|
||||
|
||||
services.desktopManager.plasma6.enable = true;
|
||||
environment.sessionVariables.NIXOS_OZONE_WL = "1";
|
||||
|
||||
environment.plasma6.excludePackages = with pkgs.kdePackages; [
|
||||
konsole
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
{}:
|
||||
{
|
||||
boot.loader.systemd-boot-enable = true;
|
||||
|
||||
time.timeZone = "Europe/Amsterdam";
|
||||
|
||||
fileSystems."/home/chris/new_games" = {
|
||||
device = "/dev/disk/by-label/games";
|
||||
|
|
7
modules/system/networking.nix
Normal file
7
modules/system/networking.nix
Normal file
|
@ -0,0 +1,7 @@
|
|||
{ pkgs, ... }:
|
||||
{
|
||||
networking = {
|
||||
hostName = "chris-pc";
|
||||
networkmanager.enable = true;
|
||||
};
|
||||
}
|
22
shell.nix
Normal file
22
shell.nix
Normal file
|
@ -0,0 +1,22 @@
|
|||
{ lib, pkgs ? import <nixpkgs> {} }:
|
||||
let
|
||||
inherit (lib.attrsets) attrValues;
|
||||
inherit (lib.meta) getExe;
|
||||
in
|
||||
pkgs.mkShell {
|
||||
buildInputs = attrValues {
|
||||
inherit (pkgs) git nix-bash-completions;
|
||||
};
|
||||
|
||||
shellHook = let
|
||||
inherit (pkgs) nixStable writeShelScriptBin;
|
||||
|
||||
nixBin = writeShellScriptBin "nix" ''
|
||||
${ getExe nixStable} --option experimental-features "nix-command flakes" "$@"
|
||||
'';
|
||||
in ''
|
||||
export FLAKE="$(pwd)"
|
||||
export PATH="$FLAKE/bin:${nixBin}/bin:$PATH"
|
||||
'';
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue