2023-05-25 04:39:57 +07:00
|
|
|
{
|
|
|
|
description = "NixOS + Home Manager configuration of chayleaf";
|
|
|
|
|
|
|
|
inputs = {
|
|
|
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
|
|
|
nixos-hardware.url = "github:NixOS/nixos-hardware";
|
|
|
|
impermanence.url = "github:nix-community/impermanence";
|
|
|
|
nur.url = "github:nix-community/NUR";
|
|
|
|
rust-overlay = {
|
|
|
|
url = "github:oxalica/rust-overlay";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
|
|
|
home-manager = {
|
|
|
|
url = "github:nix-community/home-manager";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
|
|
|
nix-gaming = {
|
|
|
|
url = "github:fufexan/nix-gaming";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
|
|
|
notlua = {
|
2023-06-11 21:48:35 +07:00
|
|
|
url = "github:chayleaf/notlua";
|
2023-05-25 04:39:57 +07:00
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
2023-06-24 07:12:11 +07:00
|
|
|
notnft = {
|
2023-06-24 14:52:13 +07:00
|
|
|
url = "github:chayleaf/notnft";
|
2023-06-24 07:12:11 +07:00
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
|
|
|
nixos-router = {
|
2023-06-24 14:52:13 +07:00
|
|
|
url = "github:chayleaf/nixos-router";
|
2023-06-24 07:12:11 +07:00
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
2023-06-27 15:25:19 +07:00
|
|
|
maubot = {
|
|
|
|
url = "github:chayleaf/maubot.nix";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
2023-05-25 04:39:57 +07:00
|
|
|
nixos-mailserver = {
|
|
|
|
url = "gitlab:simple-nixos-mailserver/nixos-mailserver";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
inputs.nixpkgs-22_11.follows = "nixpkgs";
|
|
|
|
};
|
2023-06-11 18:02:38 +07:00
|
|
|
flake-compat = {
|
|
|
|
url = "github:edolstra/flake-compat";
|
|
|
|
flake = false;
|
|
|
|
};
|
2023-05-25 04:39:57 +07:00
|
|
|
};
|
|
|
|
|
2023-06-27 15:25:19 +07:00
|
|
|
outputs = inputs@{ self, nixpkgs, nixos-hardware, impermanence, home-manager, nur, nix-gaming, notlua, notnft, nixos-mailserver, nixos-router, maubot, ... }:
|
2023-05-25 05:09:17 +07:00
|
|
|
let
|
2023-06-24 09:49:57 +07:00
|
|
|
# --impure required for developing
|
2023-06-27 15:25:19 +07:00
|
|
|
# it takes the paths for modules from filesystem as opposed to flake inputs
|
|
|
|
devNft = false;
|
|
|
|
devNixRt = false;
|
|
|
|
devMaubot = false;
|
2023-05-25 05:09:17 +07:00
|
|
|
# IRL-related stuff I'd rather not put into git
|
2023-05-26 01:38:17 +07:00
|
|
|
priv =
|
|
|
|
if builtins.pathExists ./private.nix then (import ./private.nix { })
|
|
|
|
else if builtins.pathExists ./private/default.nix then (import ./private { })
|
2023-05-26 00:40:31 +07:00
|
|
|
# workaround for git flakes not having access to non-checked out files
|
2023-05-26 01:38:17 +07:00
|
|
|
else if builtins?extraBuiltins.secrets then builtins.extraBuiltins.secrets
|
2023-05-26 00:40:31 +07:00
|
|
|
# yes, this is impure, this is a last ditch effort at getting access to secrets
|
2023-05-26 01:38:17 +07:00
|
|
|
else import /etc/nixos/private { };
|
2023-06-24 07:12:11 +07:00
|
|
|
devPath = priv.devPath or ../.;
|
2023-05-25 06:24:57 +07:00
|
|
|
# if x has key s, get it. Otherwise return def
|
|
|
|
# All private config for hostname
|
2023-05-30 10:02:36 +07:00
|
|
|
getPriv = hostname: priv.${hostname} or { };
|
2023-05-25 06:24:57 +07:00
|
|
|
# Private NixOS config for hostname
|
2023-05-30 10:02:36 +07:00
|
|
|
getPrivSys = hostname: (getPriv hostname).system or { };
|
2023-05-25 06:24:57 +07:00
|
|
|
# Private home-manager config for hostname and username
|
2023-05-30 10:02:36 +07:00
|
|
|
getPrivUser = hostname: user: (getPriv hostname).${user} or { };
|
2023-05-25 06:24:57 +07:00
|
|
|
# extended lib
|
2023-05-25 05:09:17 +07:00
|
|
|
lib = nixpkgs.lib // {
|
|
|
|
quoteListenAddr = addr:
|
|
|
|
if nixpkgs.lib.hasInfix ":" addr then "[${addr}]" else addr;
|
|
|
|
};
|
2023-05-30 10:02:36 +07:00
|
|
|
# can't use callPackage ./pkgs here, idk why; use import instead
|
2023-05-25 06:24:57 +07:00
|
|
|
overlay = self: super: import ./pkgs {
|
|
|
|
pkgs = super;
|
2023-06-11 21:48:35 +07:00
|
|
|
pkgs' = self;
|
2023-05-25 06:24:57 +07:00
|
|
|
lib = super.lib;
|
|
|
|
nur = import nur {
|
|
|
|
pkgs = super;
|
|
|
|
nurpkgs = super;
|
2023-05-25 04:39:57 +07:00
|
|
|
};
|
2023-05-25 06:24:57 +07:00
|
|
|
nix-gaming = nix-gaming.packages.${super.system};
|
|
|
|
};
|
|
|
|
# I override some settings down the line, but overlays always stay the same
|
|
|
|
mkPkgs = config: import nixpkgs (config // {
|
|
|
|
overlays = (if config?overlays then config.overlays else [ ]) ++ [ overlay ];
|
|
|
|
});
|
2023-06-24 09:49:57 +07:00
|
|
|
# this is actual config, it gets processed below
|
2023-05-25 06:24:57 +07:00
|
|
|
config = {
|
2023-05-25 05:09:17 +07:00
|
|
|
nixserver = {
|
|
|
|
modules = [
|
|
|
|
nixos-mailserver.nixosModules.default
|
2023-06-24 13:07:42 +07:00
|
|
|
./system/devices/hp-probook-g0-server.nix
|
2023-06-27 15:25:19 +07:00
|
|
|
(if devMaubot then import /${devPath}/maubot.nix/module else maubot.nixosModules.default)
|
2023-05-25 05:09:17 +07:00
|
|
|
];
|
|
|
|
};
|
2023-06-24 07:12:11 +07:00
|
|
|
router-emmc = rec {
|
2023-05-25 05:09:17 +07:00
|
|
|
system = "aarch64-linux";
|
2023-06-27 15:25:19 +07:00
|
|
|
specialArgs.notnft = if devNft then (import /${devPath}/notnft { inherit (nixpkgs) lib; }).config.notnft else notnft.lib.${system};
|
|
|
|
specialArgs.router-lib = if devNixRt then import /${devPath}/nixos-router/lib.nix { inherit (nixpkgs) lib; } else nixos-router.lib.${system};
|
2023-06-24 09:49:57 +07:00
|
|
|
specialArgs.server-config = nixosConfigurations.nixserver.config;
|
2023-05-25 05:09:17 +07:00
|
|
|
modules = [
|
2023-06-24 13:07:42 +07:00
|
|
|
(import ./system/devices/bpi-r3-router.nix "emmc")
|
2023-06-27 15:25:19 +07:00
|
|
|
(if devNixRt then (import /${devPath}/nixos-router) else nixos-router.nixosModules.default)
|
2023-06-12 17:07:38 +07:00
|
|
|
];
|
|
|
|
};
|
2023-06-24 07:12:11 +07:00
|
|
|
router-sd = rec {
|
2023-06-12 17:07:38 +07:00
|
|
|
system = "aarch64-linux";
|
2023-06-27 15:25:19 +07:00
|
|
|
specialArgs.notnft = if devNft then (import /${devPath}/notnft { inherit (nixpkgs) lib; }).config.notnft else notnft.lib.${system};
|
|
|
|
specialArgs.router-lib = if devNixRt then import /${devPath}/nixos-router/lib.nix { inherit (nixpkgs) lib; } else nixos-router.lib.${system};
|
2023-06-24 09:49:57 +07:00
|
|
|
specialArgs.server-config = nixosConfigurations.nixserver.config;
|
2023-06-12 17:07:38 +07:00
|
|
|
modules = [
|
2023-06-24 13:07:42 +07:00
|
|
|
(import ./system/devices/bpi-r3-router.nix "sd")
|
2023-06-27 15:25:19 +07:00
|
|
|
(if devNixRt then (import /${devPath}/nixos-router) else nixos-router.nixosModules.default)
|
2023-05-25 05:09:17 +07:00
|
|
|
];
|
|
|
|
};
|
2023-05-25 06:24:57 +07:00
|
|
|
nixmsi = rec {
|
|
|
|
system = "x86_64-linux";
|
|
|
|
modules = [
|
|
|
|
nix-gaming.nixosModules.pipewireLowLatency
|
2023-06-24 13:07:42 +07:00
|
|
|
./system/devices/msi-delta-15-workstation.nix
|
2023-05-25 06:24:57 +07:00
|
|
|
];
|
2023-05-25 11:34:27 +07:00
|
|
|
home.common.enableNixosModule = false;
|
2023-05-25 06:24:57 +07:00
|
|
|
home.common.extraSpecialArgs = {
|
|
|
|
notlua = notlua.lib.${system};
|
|
|
|
};
|
|
|
|
home.user = [
|
|
|
|
nur.nixosModules.nur
|
|
|
|
./home/hosts/nixmsi.nix
|
|
|
|
];
|
|
|
|
};
|
2023-05-25 05:09:17 +07:00
|
|
|
};
|
2023-06-24 09:49:57 +07:00
|
|
|
|
|
|
|
# this is the system config processing part
|
2023-06-24 07:12:11 +07:00
|
|
|
nixosConfigurations = builtins.mapAttrs (hostname: args @ { system ? "x86_64-linux", modules, specialArgs ? {}, nixpkgs ? {}, home ? {}, ... }:
|
2023-05-25 05:09:17 +07:00
|
|
|
lib.nixosSystem ({
|
|
|
|
inherit system;
|
2023-05-30 10:02:36 +07:00
|
|
|
# allow modules to access nixpkgs directly, use customized lib,
|
|
|
|
# and pass nixos-harware to let hardware modules import parts of nixos-hardware
|
|
|
|
specialArgs = {
|
|
|
|
inherit lib nixpkgs;
|
|
|
|
hardware = nixos-hardware.nixosModules;
|
2023-06-24 07:12:11 +07:00
|
|
|
} // specialArgs;
|
2023-05-25 05:09:17 +07:00
|
|
|
modules = modules ++ [
|
2023-05-30 10:02:36 +07:00
|
|
|
# Third-party NixOS modules
|
|
|
|
impermanence.nixosModule
|
|
|
|
# My custom NixOS modules
|
2023-05-25 05:09:17 +07:00
|
|
|
./system/modules/vfio.nix
|
|
|
|
./system/modules/ccache.nix
|
|
|
|
./system/modules/impermanence.nix
|
|
|
|
./system/modules/common.nix
|
2023-05-26 01:38:17 +07:00
|
|
|
(getPrivSys hostname)
|
2023-05-30 10:02:36 +07:00
|
|
|
# The common configuration that isn't part of common.nix
|
2023-06-12 17:07:38 +07:00
|
|
|
({ config, pkgs, lib, ... }: {
|
|
|
|
networking.hostName = lib.mkDefault hostname;
|
2023-05-25 11:34:27 +07:00
|
|
|
nixpkgs.overlays = [ overlay ];
|
2023-05-26 00:40:31 +07:00
|
|
|
nix.extraOptions = ''
|
|
|
|
plugin-files = ${pkgs.nix-plugins.override { nix = config.nix.package; }}/lib/nix/plugins/libnix-extra-builtins.so
|
|
|
|
'';
|
2023-05-25 11:34:27 +07:00
|
|
|
|
2023-05-30 10:02:36 +07:00
|
|
|
# registry is used for the new flaky nix command
|
2023-05-25 05:09:17 +07:00
|
|
|
nix.registry =
|
|
|
|
builtins.mapAttrs
|
|
|
|
(_: v: { flake = v; })
|
|
|
|
(lib.filterAttrs (_: v: v?outputs) inputs);
|
2023-05-25 05:02:07 +07:00
|
|
|
|
2023-05-30 10:02:36 +07:00
|
|
|
# add import'able flake inputs (like nixpkgs) to nix path
|
|
|
|
# nix path is used for old nix commands (like nix-build, nix-shell)
|
2023-05-25 05:09:17 +07:00
|
|
|
environment.etc = lib.mapAttrs'
|
|
|
|
(name: value: {
|
|
|
|
name = "nix/inputs/${name}";
|
|
|
|
value = { source = value.outPath; };
|
|
|
|
})
|
|
|
|
(lib.filterAttrs (_: v: builtins.pathExists "${v}/default.nix") inputs);
|
|
|
|
nix.nixPath = [ "/etc/nix/inputs" ];
|
2023-05-26 00:40:31 +07:00
|
|
|
})
|
2023-05-30 10:02:36 +07:00
|
|
|
]
|
|
|
|
# the following is NixOS home-manager module configuration. Currently unused, but I might start using it for some hosts later.
|
|
|
|
++ (lib.optionals (home != {} && ((home.common or {}).enableNixosModule or true)) [
|
2023-05-25 06:24:57 +07:00
|
|
|
home-manager.nixosModules.home-manager
|
|
|
|
{
|
2023-05-30 10:02:36 +07:00
|
|
|
home-manager = builtins.removeAttrs (home.common or { }) [ "nixpkgs" "nix" "enableNixosModule" ];
|
2023-05-25 06:24:57 +07:00
|
|
|
}
|
|
|
|
{
|
2023-05-30 10:02:36 +07:00
|
|
|
# set both to false to match behavior with standalone home-manager
|
2023-05-25 11:34:27 +07:00
|
|
|
home-manager.useGlobalPkgs = false;
|
|
|
|
home-manager.useUserPackages = false;
|
|
|
|
home-manager.users = builtins.mapAttrs (username: modules: {
|
|
|
|
imports = modules ++ [
|
|
|
|
{
|
2023-05-30 10:02:36 +07:00
|
|
|
nixpkgs = (home.common or { }).nixpkgs or { };
|
|
|
|
nix = (home.common or { }).nix or { };
|
2023-05-25 11:34:27 +07:00
|
|
|
}
|
2023-05-26 00:40:31 +07:00
|
|
|
({ config, pkgs, lib, ...}: {
|
2023-05-25 11:34:27 +07:00
|
|
|
nixpkgs.overlays = [ overlay ];
|
2023-05-26 00:40:31 +07:00
|
|
|
nix.package = lib.mkDefault pkgs.nixFlakes;
|
2023-06-11 21:48:35 +07:00
|
|
|
# this is only needed if nixos doesnt set plugin-files already
|
|
|
|
/*nix.extraOptions = ''
|
2023-05-26 00:40:31 +07:00
|
|
|
plugin-files = ${pkgs.nix-plugins.override { nix = config.nix.package; }}/lib/nix/plugins/libnix-extra-builtins.so
|
2023-06-11 21:48:35 +07:00
|
|
|
'';*/
|
2023-05-25 11:34:27 +07:00
|
|
|
})
|
2023-05-26 01:38:17 +07:00
|
|
|
(getPrivUser hostname username)
|
2023-05-25 11:34:27 +07:00
|
|
|
];
|
2023-05-25 06:24:57 +07:00
|
|
|
}) (builtins.removeAttrs home [ "common" ]);
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
} // (builtins.removeAttrs args [ "home" "modules" "nixpkgs" ])))
|
2023-05-25 05:09:17 +07:00
|
|
|
config;
|
2023-06-24 09:49:57 +07:00
|
|
|
in {
|
|
|
|
inherit nixosConfigurations;
|
|
|
|
overlays.default = overlay;
|
|
|
|
packages = lib.genAttrs [
|
|
|
|
"x86_64-linux"
|
|
|
|
"aarch64-linux"
|
|
|
|
] (system: let self = overlay self (import nixpkgs { inherit system; }); in self );
|
|
|
|
nixosImages.router = let pkgs = import nixpkgs { system = "aarch64-linux"; overlays = [ overlay ]; }; in {
|
2023-06-24 14:52:13 +07:00
|
|
|
emmcImage = pkgs.callPackage ./system/hardware/bpi-r3/image.nix {
|
2023-06-24 09:49:57 +07:00
|
|
|
inherit (nixosConfigurations.router-emmc) config;
|
|
|
|
rootfsImage = nixosConfigurations.router-emmc.config.system.build.rootfsImage;
|
|
|
|
bpiR3Stuff = pkgs.bpiR3StuffEmmc;
|
|
|
|
};
|
2023-06-24 14:52:13 +07:00
|
|
|
sdImage = pkgs.callPackage ./system/hardware/bpi-r3/image.nix {
|
2023-06-24 09:49:57 +07:00
|
|
|
inherit (nixosConfigurations.router-sd) config;
|
|
|
|
rootfsImage = nixosConfigurations.router-sd.config.system.build.rootfsImage;
|
|
|
|
bpiR3Stuff = pkgs.bpiR3StuffSd;
|
|
|
|
};
|
|
|
|
};
|
2023-05-30 10:02:36 +07:00
|
|
|
|
2023-05-25 06:24:57 +07:00
|
|
|
# for each hostname, for each user, generate an attribute "${user}@${hostname}"
|
2023-05-25 05:09:17 +07:00
|
|
|
homeConfigurations =
|
|
|
|
builtins.foldl'
|
|
|
|
(a: b: a // b)
|
|
|
|
{ }
|
|
|
|
(builtins.concatLists
|
|
|
|
(lib.mapAttrsToList
|
2023-05-25 06:24:57 +07:00
|
|
|
(hostname: sysConfig:
|
2023-05-25 11:34:27 +07:00
|
|
|
let
|
2023-05-26 00:40:31 +07:00
|
|
|
system = if sysConfig?system then sysConfig.system else "x86_64-linux";
|
2023-05-30 10:02:36 +07:00
|
|
|
common' = builtins.removeAttrs (sysConfig.home.common or { }) [ "nix" "nixpkgs" "enableNixosModule" ];
|
|
|
|
pkgs = mkPkgs ({ inherit system; } // ((sysConfig.home.common or { }).nixpkgs or {}));
|
|
|
|
common = common' // { inherit pkgs; };
|
2023-05-25 11:34:27 +07:00
|
|
|
in
|
2023-05-25 05:09:17 +07:00
|
|
|
lib.mapAttrsToList
|
2023-05-25 06:24:57 +07:00
|
|
|
# this is where actual config takes place
|
|
|
|
(user: homeConfig: {
|
2023-05-30 10:02:36 +07:00
|
|
|
"${user}@${hostname}" = home-manager.lib.homeManagerConfiguration (common // {
|
2023-05-25 06:24:57 +07:00
|
|
|
modules = homeConfig ++ [
|
2023-05-26 01:38:17 +07:00
|
|
|
(getPrivUser hostname user)
|
2023-05-26 00:40:31 +07:00
|
|
|
({ config, pkgs, lib, ... }: {
|
2023-05-25 11:34:27 +07:00
|
|
|
nixpkgs.overlays = [ overlay ];
|
2023-05-26 00:40:31 +07:00
|
|
|
nix.package = lib.mkDefault pkgs.nixFlakes;
|
2023-06-11 21:48:35 +07:00
|
|
|
# this is only needed if nixos doesnt set plugin-files already
|
|
|
|
/*nix.extraOptions = ''
|
2023-05-26 00:40:31 +07:00
|
|
|
plugin-files = ${pkgs.nix-plugins.override { nix = config.nix.package; }}/lib/nix/plugins/libnix-extra-builtins.so
|
2023-06-11 21:48:35 +07:00
|
|
|
'';*/
|
2023-05-25 11:34:27 +07:00
|
|
|
})
|
2023-05-25 06:24:57 +07:00
|
|
|
];
|
2023-05-25 05:09:17 +07:00
|
|
|
});
|
2023-05-25 05:02:07 +07:00
|
|
|
})
|
2023-05-30 10:02:36 +07:00
|
|
|
(builtins.removeAttrs (sysConfig.home or { }) [ "common" ]))
|
2023-05-25 05:09:17 +07:00
|
|
|
config));
|
|
|
|
};
|
2023-05-25 04:39:57 +07:00
|
|
|
}
|