nixos/flake.nix

387 lines
12 KiB
Nix
Raw Normal View History

2021-05-19 23:08:18 +02:00
{
description = "Malte Tammena's system configuration";
2021-10-13 17:38:24 +02:00
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
2021-12-26 21:49:18 +01:00
nixos-hardware = {
url = "github:NixOS/nixos-hardware";
inputs.nixpkgs.follows = "nixpkgs";
};
nixpkgs-wayland = {
url = "github:nix-community/nixpkgs-wayland";
inputs.nixpkgs.follows = "nixpkgs";
};
emulator-2a = {
url = "github:MalteT/2a-emulator/develop";
inputs.nixpkgs.follows = "nixpkgs";
};
mensa = {
url = "github:MalteT/mensa/main";
inputs.nixpkgs.follows = "nixpkgs";
};
custom-udev-rules = {
url = "github:MalteT/custom-udev-rules";
inputs.nixpkgs.follows = "nixpkgs";
};
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
colmena = {
url = "github:zhaofengli/colmena";
inputs.nixpkgs.follows = "nixpkgs";
};
sops-nix = {
url = "github:Mic92/sops-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
glados = {
url = "git+https://git.sr.ht/~megamanmalte/GLaDOS?ref=main";
inputs.nixpkgs.follows = "nixpkgs";
};
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
2021-10-13 17:38:24 +02:00
gruvbox-material-gtk = {
url = "github:sainnhe/gruvbox-material-gtk";
flake = false;
};
rip = {
url = "github:nivekuil/rip";
flake = false;
};
"2i-emulator" = {
url = "github:klemens/2i-emulator";
flake = false;
};
"cataclysm-dda" = {
url = "github:CleverRaven/Cataclysm-DDA";
flake = false;
};
fend = {
2021-12-26 21:49:18 +01:00
url = "github:MalteT/fend/flake";
inputs.nixpkgs.follows = "nixpkgs";
};
2021-07-21 09:10:17 +02:00
};
2021-05-19 23:08:18 +02:00
2021-12-22 21:37:23 +01:00
outputs = { self, nixpkgs, nixos-hardware, home-manager, ... }@inputs: {
2021-06-15 18:15:54 +02:00
2021-12-22 21:37:23 +01:00
colmena = {
meta = { nixpkgs = import nixpkgs { system = "x86_64-linux"; }; };
2021-05-19 23:08:18 +02:00
2021-12-22 21:37:23 +01:00
helix-texta = { name, nodes, pkgs, ... }: {
imports = [ self.nixosModules.helix-texta ];
config.deployment = {
allowLocalDeployment = true;
targetHost = null;
2021-12-04 15:07:07 +01:00
};
2021-12-22 21:37:23 +01:00
};
2021-12-04 15:07:07 +01:00
2022-01-06 10:22:46 +01:00
murex-pecten = { name, nodes, pkgs, ... }: {
imports = [ self.nixosModules.murex-pecten ];
config.deployment = {
#allowLocalDeployment = true;
targetHost = "murex-pecten";
targetUser = "root";
2022-01-06 10:22:46 +01:00
};
};
2021-12-22 21:37:23 +01:00
cornu-aspersum = { ... }: {
imports = [ self.nixosModules.cornu-aspersum ];
config.deployment = {
targetHost = "ccqcraft.de";
targetUser = "root";
};
2021-12-22 21:37:23 +01:00
};
2021-12-22 21:37:23 +01:00
elysia-clarki = { ... }: {
imports = [ self.nixosModules.elysia-clarki ];
config.deployment = {
targetHost = "elysia-clarki";
targetUser = "root";
2021-12-04 15:07:07 +01:00
};
};
trochulus-hispidus = { ... }: {
imports = [ self.nixosModules.trochulus-hispidus ];
config.deployment = {
targetHost = "trochulus-hispidus";
targetUser = "root";
};
};
2021-12-22 21:37:23 +01:00
};
2021-12-04 15:07:07 +01:00
2021-12-22 21:37:23 +01:00
nixosModules = {
helix-texta = { pkgs, config, ... }: {
imports = [
./hosts/helix-texta.nix
./modules/light-actkbd.nix
./modules/scanner.nix
self.nixosModules.thinkpad-p1-gen3
home-manager.nixosModules.home-manager
2021-12-26 23:01:36 +01:00
self.nixosModules.home-manager-config
2021-12-22 21:37:23 +01:00
self.nixosModules.x86_64-linux-basics
];
2021-12-04 15:07:07 +01:00
2021-12-22 21:37:23 +01:00
config = {
nix = {
# add binary caches
binaryCachePublicKeys = [
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
"nixpkgs-wayland.cachix.org-1:3lwxaILxMRkVhehr5StQprHdEo4IrE8sRho9R9HOLYA="
];
binaryCaches = nixpkgs.lib.mkForce [
"https://cache.nixos.org"
"https://nixpkgs-wayland.cachix.org"
2021-12-04 15:07:07 +01:00
];
};
2021-12-22 21:37:23 +01:00
environment.systemPackages =
[ inputs.colmena.packages.${config.nixpkgs.system}.colmena ];
2021-12-04 15:07:07 +01:00
2021-12-22 21:37:23 +01:00
# Overwrite basics
services.openssh.enable = false;
programs.mosh.enable = false;
2021-12-22 21:37:23 +01:00
# Overlays only relevant to my primary laptop
nixpkgs.overlays = [
inputs.nixpkgs-wayland.overlay
inputs.fenix.overlay
(import ./overlays/sane-backends.nix)
(import ./overlays/logisim.nix)
2021-12-04 15:07:07 +01:00
];
};
};
2022-01-06 10:22:46 +01:00
murex-pecten = { ... }: {
imports = [
self.nixosModules.x86_64-linux-basics
nixos-hardware.nixosModules.common-pc
nixos-hardware.nixosModules.common-pc-ssd
nixos-hardware.nixosModules.common-cpu-amd
nixos-hardware.nixosModules.common-gpu-amd
2022-01-07 08:39:12 +01:00
home-manager.nixosModules.home-manager
self.nixosModules.home-manager-config
2022-01-06 10:22:46 +01:00
./hosts/murex-pecten.nix
./hardware/aorus.nix
];
2022-01-07 08:39:12 +01:00
config = { nixpkgs.overlays = [ inputs.fenix.overlay ]; };
2022-01-06 10:22:46 +01:00
};
2021-12-22 21:37:23 +01:00
cornu-aspersum = { ... }: {
imports = [
self.nixosModules.x86_64-linux-basics
./hosts/cornu-aspersum.nix
./hardware/netcup-rs-2000-g9.nix
./modules/nginx-reverse-proxy.nix
./modules/ccqcraft.nix
inputs.glados.nixosModules.glados
./modules/radicale.nix
./modules/grafana.nix
2021-12-22 21:37:23 +01:00
];
2021-06-10 21:34:27 +02:00
};
2021-12-22 21:37:23 +01:00
elysia-clarki = { pkgs, ... }: {
imports = [
2021-12-22 21:37:23 +01:00
self.nixosModules.x86_64-linux-basics
./hosts/elysia-clarki.nix
./hardware/intel-nuc.nix
./modules/local-build-service.nix
./modules/nginx-reverse-proxy.nix
2022-01-21 17:57:52 +01:00
#./modules/binary-cache.nix
2021-12-22 21:37:23 +01:00
./modules/ccqcraft-backups.nix
./modules/restic.nix
];
2021-12-22 21:37:23 +01:00
config = {
# Override kernel version for zfs
boot.kernelPackages = pkgs.linuxPackages_5_10;
2021-11-29 16:36:57 +01:00
};
2021-06-15 18:15:54 +02:00
};
2021-12-26 20:44:36 +01:00
trochulus-hispidus = { pkgs, ... }: {
imports = [
2021-12-26 23:01:36 +01:00
home-manager.nixosModules.home-manager
2021-12-26 20:44:36 +01:00
self.nixosModules.x86_64-linux-basics
2021-12-26 23:01:36 +01:00
self.nixosModules.home-manager-config
2021-12-26 20:44:36 +01:00
./hosts/trochulus-hispidus.nix
./hardware/latitude-e7440.nix
];
};
2021-12-22 21:37:23 +01:00
};
2021-06-15 18:15:54 +02:00
2021-12-22 21:37:23 +01:00
nixosModules.thinkpad-p1-gen3 = { ... }: {
imports = [
nixos-hardware.nixosModules.common-cpu-intel
nixos-hardware.nixosModules.common-gpu-nvidia
nixos-hardware.nixosModules.common-pc-laptop
nixos-hardware.nixosModules.common-pc-laptop-ssd
nixos-hardware.nixosModules.common-pc-laptop-acpi_call
./hardware/thinkpad-p1-gen3.nix
];
};
2021-06-09 22:24:06 +02:00
2021-12-26 23:01:36 +01:00
nixosModules.home-manager-config = { ... }: {
2021-12-22 21:37:23 +01:00
home-manager.verbose = true;
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
};
2021-12-22 21:37:23 +01:00
# Necessary for flakes to work
nixosModules.nixUnstable = { pkgs, ... }: {
nix.registry.nixpkgs.flake = nixpkgs;
nix.package = pkgs.nixUnstable;
nix.extraOptions = ''
experimental-features = nix-command flakes
'';
nixpkgs.overlays = [ (self: super: { nix = super.nixUnstable; }) ];
2021-12-26 23:02:11 +01:00
# Enable store optimiser
nix.optimise = {
automatic = true;
dates = [ "04:00" ];
};
2021-12-22 21:37:23 +01:00
};
2021-06-15 19:02:47 +02:00
2021-12-22 21:37:23 +01:00
# Some basics that every machine should have
2022-01-13 22:58:29 +01:00
nixosModules.x86_64-linux-basics = { pkgs, config, ... }: {
2021-12-22 21:37:23 +01:00
imports = [
inputs.custom-udev-rules.nixosModule
inputs.sops-nix.nixosModules.sops
self.nixosModules.nixUnstable
./modules/neovim.nix
./modules/base-system.nix
2021-12-22 21:37:23 +01:00
];
config = {
# Set the system revision if this flake has it
system.configurationRevision = pkgs.lib.mkIf (self ? rev) self.rev;
# Add some useful overlays
# TODO: How would I do this inside ./modules/base-system.nix?
nixpkgs.overlays = [
(self: super: {
# Add FiraCode as a package, but use NerdFonts
firaCodeNerd = super.nerdfonts.override { fonts = [ "FiraCode" ]; };
# Add the emulator
"2a-emulator" =
inputs.emulator-2a.packages.x86_64-linux."2a-emulator";
# Add my mensa tool
mensa = inputs.mensa.packages.x86_64-linux.mensa;
# TODO: Replace with upstream
fend = inputs.fend.packages.x86_64-linux.fend;
})
# Override cataclysm to use git
(import ./overlays/cataclysm-dda.nix)
];
2022-01-13 22:58:29 +01:00
};
2021-12-22 21:37:23 +01:00
};
2021-07-07 18:49:12 +02:00
2021-12-22 21:37:23 +01:00
# My thinkpad P1
nixosConfigurations.helix-texta = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [ self.nixosModules.helix-texta ];
};
2021-12-21 15:44:22 +01:00
2022-01-06 10:22:46 +01:00
# My tower
nixosConfigurations.murex-pecten = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [ self.nixosModules.murex-pecten ];
};
2021-12-22 21:37:23 +01:00
# Currently hosted by NetCup
nixosConfigurations.cornu-aspersum = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [ self.nixosModules.cornu-aspersum ];
};
# Server @home
nixosConfigurations.elysia-clarki = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [ self.nixosModules.elysia-clarki ];
2021-12-26 20:44:36 +01:00
};
# Marie's laptop
nixosConfigurations.trochulus-hispidus = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [ self.nixosModules.trochulus-hispidus ];
2021-12-22 21:37:23 +01:00
};
devShell.x86_64-linux =
let pkgs = import nixpkgs { system = "x86_64-linux"; };
in pkgs.mkShell {
packages = [
(with pkgs;
writeScriptBin "rebuild" ''
#!${stdenv.shell}
if [ -z $1 ]; then
echo "Need 'switch|boot|...'"
exit 1
fi
today=`${coreutils}/bin/date +%Y-%m-%d`
branch=`${git}/bin/git branch --show-current`
rev=`${git}/bin/git log -1 --format=%h`
dirty=`${git}/bin/git diff --quiet || echo '~'`
NIXOS_LABEL_VERSION=$today-$branch-$rev$dirty
# Extract build secrets
echo Extracting build secrets..
${sops}/bin/sops --extract '["polymc-client-id"]' -d secrets/secrets.yaml > build-secrets/polymc-client-id
2021-12-22 21:37:23 +01:00
sudo ${nixos-rebuild}/bin/nixos-rebuild $1 --flake .
'')
2022-01-14 18:10:58 +01:00
(with pkgs;
writeScriptBin "all-hosts" ''
nix eval --json .#nixosConfigurations --apply builtins.attrNames 2>/dev/null | jq -r .[]
'')
2022-01-16 15:55:37 +01:00
(with pkgs;
writeScriptBin "push-to" ''
if [ -z $2 ]; then
echo "Need 'switch|boot|...'"
exit 1
fi
host=$1
action=$2
nixos-rebuild --flake .#$host --build-host root@$host --target-host root@$host $action
'')
2022-01-14 18:10:58 +01:00
(with pkgs;
writeScriptBin "option" ''
host=$1
option=$2
nix eval .#nixosConfigurations.$host.config.$option 2>/dev/null
'')
(with pkgs;
writeScriptBin "hm-option" ''
host=$1
option=$2
user=$3
if [[ -z $user ]]; then
user=$USER
fi
nix eval .#nixosConfigurations.$host.config.home-manager.users.$user.$option 2>/dev/null
'')
(with pkgs;
writeScriptBin "test-config" ''
#!${stdenv.shell}
2022-01-14 18:10:58 +01:00
for host in $(all-hosts); do
echo == Checking ''${host}..
nixos-rebuild --flake .#$host dry-build 2> /tmp/build-output
if [[ $? -ne 0 ]]; then
bat --file-name "Failed to verify config for $host" /tmp/build-output
exit 1
fi
done
echo === All checks passed
'')
2021-12-22 21:37:23 +01:00
inputs.colmena.packages.x86_64-linux.colmena
];
};
};
2021-05-19 23:08:18 +02:00
}