refactor(flake): optimize structure
- get rid of some `rec`s - move lib & overlays into flake modules
This commit is contained in:
parent
ea5b11995b
commit
10c0834daa
105
flake.nix
105
flake.nix
|
@ -79,49 +79,12 @@ rec {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = { self, nixpkgs, nixpkgs-unstable, nixos-hardware, fh, flake-parts
|
outputs = { self, nixpkgs, nixpkgs-unstable, ... }@inputs:
|
||||||
, flake-utils, home-manager, agenix, deploy-rs, pre-commit-hooks
|
|
||||||
, nvim-kitty-navigator, ... }@inputs:
|
|
||||||
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
|
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
|
||||||
systems = [ "x86_64-linux" "aarch64-linux" ];
|
systems = [ "x86_64-linux" "aarch64-linux" ];
|
||||||
imports = [ ];
|
imports = [ ./lib ./overlays.nix ];
|
||||||
flake = rec {
|
flake = {
|
||||||
lib = rec {
|
inherit nixConfig;
|
||||||
createSystem = hostName:
|
|
||||||
{ hardwareConfig, config }:
|
|
||||||
({ pkgs, lib, ... }: {
|
|
||||||
networking.hostName = hostName;
|
|
||||||
|
|
||||||
nixpkgs.overlays = [ self.overlays.default ];
|
|
||||||
|
|
||||||
imports = [
|
|
||||||
nixosModules.flakeDefaults
|
|
||||||
agenix.nixosModules.default
|
|
||||||
inputs.matrix-appservices.nixosModule
|
|
||||||
hardwareConfig
|
|
||||||
config
|
|
||||||
];
|
|
||||||
|
|
||||||
environment.systemPackages =
|
|
||||||
[ agenix.packages.x86_64-linux.default ];
|
|
||||||
});
|
|
||||||
createUser' = import ./lib/createUser.nix;
|
|
||||||
createUser = name: args:
|
|
||||||
({ pkgs, ... }@args2:
|
|
||||||
(createUser' name args) ({ inherit home-manager; } // args2));
|
|
||||||
createMediaGroup = _: { users.groups.media.gid = 600; };
|
|
||||||
};
|
|
||||||
|
|
||||||
overlays.default = final: prev: {
|
|
||||||
unstable = import nixpkgs-unstable {
|
|
||||||
inherit (prev) system;
|
|
||||||
config.allowUnfree = true;
|
|
||||||
};
|
|
||||||
inherit (fh.packages.${prev.system}) fh;
|
|
||||||
inherit (self.packages.${prev.system}) deconz brlaser;
|
|
||||||
vimPlugins = prev.vimPlugins
|
|
||||||
// final.callPackage ./pkgs/vim-plugins { inherit inputs; };
|
|
||||||
};
|
|
||||||
|
|
||||||
nixosModules = {
|
nixosModules = {
|
||||||
flakeDefaults = import ./modules/flakeDefaults.nix;
|
flakeDefaults = import ./modules/flakeDefaults.nix;
|
||||||
|
@ -140,73 +103,74 @@ rec {
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
modules = [
|
modules = [
|
||||||
nixpkgs.nixosModules.notDetected
|
nixpkgs.nixosModules.notDetected
|
||||||
nixos-hardware.nixosModules.common-pc
|
inputs.nixos-hardware.nixosModules.common-pc
|
||||||
nixos-hardware.nixosModules.common-pc-ssd
|
inputs.nixos-hardware.nixosModules.common-pc-ssd
|
||||||
nixos-hardware.nixosModules.common-cpu-amd-pstate
|
inputs.nixos-hardware.nixosModules.common-cpu-amd-pstate
|
||||||
nixos-hardware.nixosModules.common-gpu-amd
|
inputs.nixos-hardware.nixosModules.common-gpu-amd
|
||||||
(lib.createSystem "home-pc" {
|
(self.lib.createSystem "home-pc" {
|
||||||
hardwareConfig = ./hardware/home-pc.nix;
|
hardwareConfig = ./hardware/home-pc.nix;
|
||||||
config = ./hosts/home-pc.nix;
|
config = ./hosts/home-pc.nix;
|
||||||
})
|
})
|
||||||
lib.createMediaGroup
|
self.lib.createMediaGroup
|
||||||
(lib.createUser "felschr" {
|
(self.lib.createUser "felschr" {
|
||||||
user.extraGroups =
|
user.extraGroups =
|
||||||
[ "wheel" "audio" "disk" "libvirtd" "qemu-libvirtd" "media" ];
|
[ "wheel" "audio" "disk" "libvirtd" "qemu-libvirtd" "media" ];
|
||||||
modules = [ homeManagerModules.git ];
|
modules = [ self.homeManagerModules.git ];
|
||||||
config = ./home/felschr.nix;
|
config = ./home/felschr.nix;
|
||||||
usesContainers = true;
|
usesContainers = true;
|
||||||
})
|
})
|
||||||
({ pkgs, ... }: {
|
({ pkgs, ... }: {
|
||||||
environment.systemPackages =
|
environment.systemPackages =
|
||||||
[ deploy-rs.defaultPackage.x86_64-linux ];
|
[ inputs.deploy-rs.defaultPackage.x86_64-linux ];
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
specialArgs = { inherit inputs nixConfig; };
|
specialArgs = { inherit inputs; };
|
||||||
};
|
};
|
||||||
pilot1 = nixpkgs.lib.nixosSystem {
|
pilot1 = nixpkgs.lib.nixosSystem {
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
modules = [
|
modules = [
|
||||||
nixpkgs.nixosModules.notDetected
|
nixpkgs.nixosModules.notDetected
|
||||||
nixos-hardware.nixosModules.common-pc
|
inputs.nixos-hardware.nixosModules.common-pc
|
||||||
nixos-hardware.nixosModules.common-pc-ssd
|
inputs.nixos-hardware.nixosModules.common-pc-ssd
|
||||||
nixos-hardware.nixosModules.common-cpu-intel
|
inputs.nixos-hardware.nixosModules.common-cpu-intel
|
||||||
(lib.createSystem "pilot1" {
|
(self.lib.createSystem "pilot1" {
|
||||||
hardwareConfig = ./hardware/pilot1.nix;
|
hardwareConfig = ./hardware/pilot1.nix;
|
||||||
config = ./hosts/work-pc.nix;
|
config = ./hosts/work-pc.nix;
|
||||||
})
|
})
|
||||||
(lib.createUser "felschr" {
|
(self.lib.createUser "felschr" {
|
||||||
user.extraGroups = [ "wheel" "audio" "disk" ];
|
user.extraGroups = [ "wheel" "audio" "disk" ];
|
||||||
modules = [ homeManagerModules.git ];
|
modules = [ self.homeManagerModules.git ];
|
||||||
config = ./home/felschr-work.nix;
|
config = ./home/felschr-work.nix;
|
||||||
usesContainers = true;
|
usesContainers = true;
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
specialArgs = { inherit inputs nixConfig; };
|
specialArgs = { inherit inputs; };
|
||||||
};
|
};
|
||||||
home-server = nixpkgs.lib.nixosSystem {
|
home-server = nixpkgs.lib.nixosSystem {
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
modules = [
|
modules = [
|
||||||
nixpkgs.nixosModules.notDetected
|
nixpkgs.nixosModules.notDetected
|
||||||
nixos-hardware.nixosModules.common-pc
|
inputs.nixos-hardware.nixosModules.common-pc
|
||||||
nixos-hardware.nixosModules.common-pc-ssd
|
inputs.nixos-hardware.nixosModules.common-pc-ssd
|
||||||
nixos-hardware.nixosModules.common-cpu-intel-kaby-lake
|
inputs.nixos-hardware.nixosModules.common-cpu-intel-kaby-lake
|
||||||
(lib.createSystem "home-server" {
|
inputs.matrix-appservices.nixosModule
|
||||||
|
(self.lib.createSystem "home-server" {
|
||||||
hardwareConfig = ./hardware/lattepanda.nix;
|
hardwareConfig = ./hardware/lattepanda.nix;
|
||||||
config = ./hosts/home-server.nix;
|
config = ./hosts/home-server.nix;
|
||||||
})
|
})
|
||||||
lib.createMediaGroup
|
self.lib.createMediaGroup
|
||||||
(lib.createUser "felschr" {
|
(self.lib.createUser "felschr" {
|
||||||
user = {
|
user = {
|
||||||
extraGroups = [ "wheel" "audio" "disk" "media" ];
|
extraGroups = [ "wheel" "audio" "disk" "media" ];
|
||||||
openssh.authorizedKeys.keys = [
|
openssh.authorizedKeys.keys = [
|
||||||
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIP751vlJUnB7Pfe1KNr6weWkx/rkP4J3lTYpAekHdOgV"
|
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIP751vlJUnB7Pfe1KNr6weWkx/rkP4J3lTYpAekHdOgV"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
modules = [ homeManagerModules.git ];
|
modules = [ self.homeManagerModules.git ];
|
||||||
config = ./home/felschr-server.nix;
|
config = ./home/felschr-server.nix;
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
specialArgs = { inherit inputs nixConfig; };
|
specialArgs = { inherit inputs; };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -216,7 +180,7 @@ rec {
|
||||||
sshUser = "felschr";
|
sshUser = "felschr";
|
||||||
sshOpts = [ "-t" ];
|
sshOpts = [ "-t" ];
|
||||||
user = "root";
|
user = "root";
|
||||||
path = deploy-rs.lib.x86_64-linux.activate.nixos
|
path = inputs.deploy-rs.lib.x86_64-linux.activate.nixos
|
||||||
self.nixosConfigurations.home-server;
|
self.nixosConfigurations.home-server;
|
||||||
magicRollback = false; # otherwise password prompt won't work
|
magicRollback = false; # otherwise password prompt won't work
|
||||||
};
|
};
|
||||||
|
@ -231,14 +195,15 @@ rec {
|
||||||
packages = import ./pkgs { inherit pkgs; };
|
packages = import ./pkgs { inherit pkgs; };
|
||||||
|
|
||||||
apps = {
|
apps = {
|
||||||
deconz = flake-utils.lib.mkApp { drv = config.packages.deconz; };
|
deconz =
|
||||||
|
inputs.flake-utils.lib.mkApp { drv = config.packages.deconz; };
|
||||||
};
|
};
|
||||||
|
|
||||||
devShells.default =
|
devShells.default =
|
||||||
pkgs.mkShell { inherit (config.checks.pre-commit) shellHook; };
|
pkgs.mkShell { inherit (config.checks.pre-commit) shellHook; };
|
||||||
|
|
||||||
checks = deploy-rs.lib.${system}.deployChecks self.deploy // {
|
checks = inputs.deploy-rs.lib.${system}.deployChecks self.deploy // {
|
||||||
pre-commit = pre-commit-hooks.lib.${system}.run {
|
pre-commit = inputs.pre-commit-hooks.lib.${system}.run {
|
||||||
src = ./.;
|
src = ./.;
|
||||||
hooks = {
|
hooks = {
|
||||||
nixfmt.enable = true;
|
nixfmt.enable = true;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
name:
|
name:
|
||||||
{ user ? { }, hm ? { }, modules ? [ ], config, usesContainers ? false, ... }:
|
{ user ? { }, hm ? { }, modules ? [ ], config, usesContainers ? false, ... }:
|
||||||
|
|
||||||
{ inputs, nixConfig, pkgs, lib, home-manager, ... }: {
|
{ inputs, pkgs, lib, home-manager, ... }: {
|
||||||
imports = [ home-manager.nixosModules.home-manager ];
|
imports = [ home-manager.nixosModules.home-manager ];
|
||||||
|
|
||||||
users.users."${name}" = {
|
users.users."${name}" = {
|
||||||
|
@ -24,6 +24,6 @@ name:
|
||||||
useGlobalPkgs = true;
|
useGlobalPkgs = true;
|
||||||
backupFileExtension = "backup";
|
backupFileExtension = "backup";
|
||||||
users."${name}" = lib.mkMerge [ { imports = modules; } (import config) ];
|
users."${name}" = lib.mkMerge [ { imports = modules; } (import config) ];
|
||||||
extraSpecialArgs = { inherit inputs nixConfig; };
|
extraSpecialArgs = { inherit inputs; };
|
||||||
} // hm;
|
} // hm;
|
||||||
}
|
}
|
||||||
|
|
21
lib/default.nix
Normal file
21
lib/default.nix
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
{ inputs, ... }:
|
||||||
|
|
||||||
|
let createUser' = import ./createUser.nix;
|
||||||
|
in {
|
||||||
|
flake = {
|
||||||
|
lib = {
|
||||||
|
createSystem = hostName:
|
||||||
|
{ hardwareConfig, config }:
|
||||||
|
({ pkgs, lib, ... }: {
|
||||||
|
networking.hostName = hostName;
|
||||||
|
|
||||||
|
imports = [ ../modules/common.nix hardwareConfig config ];
|
||||||
|
});
|
||||||
|
createUser = name: args:
|
||||||
|
({ pkgs, ... }@args2:
|
||||||
|
(createUser' name args)
|
||||||
|
({ inherit (inputs) home-manager; } // args2));
|
||||||
|
createMediaGroup = _: { users.groups.media.gid = 600; };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
12
modules/common.nix
Normal file
12
modules/common.nix
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
{ inputs, ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
imports = [
|
||||||
|
inputs.self.nixosModules.flakeDefaults
|
||||||
|
inputs.agenix.nixosModules.default
|
||||||
|
];
|
||||||
|
|
||||||
|
nixpkgs.overlays = [ inputs.self.overlays.default ];
|
||||||
|
|
||||||
|
environment.systemPackages = [ inputs.agenix.packages.x86_64-linux.default ];
|
||||||
|
}
|
16
overlays.nix
Normal file
16
overlays.nix
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
{ inputs, ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
flake = {
|
||||||
|
overlays.default = final: prev: {
|
||||||
|
unstable = import inputs.nixpkgs-unstable {
|
||||||
|
inherit (prev) system;
|
||||||
|
config.allowUnfree = true;
|
||||||
|
};
|
||||||
|
inherit (inputs.fh.packages.${prev.system}) fh;
|
||||||
|
inherit (inputs.self.packages.${prev.system}) deconz brlaser;
|
||||||
|
vimPlugins = prev.vimPlugins
|
||||||
|
// final.callPackage ./pkgs/vim-plugins { inherit inputs; };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,6 +1,8 @@
|
||||||
{ lib, inputs, nixConfig, ... }:
|
{ inputs, lib, ... }:
|
||||||
|
|
||||||
let flakes = lib.filterAttrs (name: value: value ? outputs) inputs;
|
let
|
||||||
|
flakes = lib.filterAttrs (name: value: value ? outputs) inputs;
|
||||||
|
inherit (inputs.self.outputs) nixConfig;
|
||||||
in {
|
in {
|
||||||
nix.gc = {
|
nix.gc = {
|
||||||
automatic = true;
|
automatic = true;
|
||||||
|
|
Loading…
Reference in a new issue