Merge branch 'flake-parts-hosts'
This commit is contained in:
commit
515668ccdd
371
flake.nix
371
flake.nix
@ -3,6 +3,7 @@
|
|||||||
description = "NixOS Configuration";
|
description = "NixOS Configuration";
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
|
# {{{
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
|
||||||
# ^^^^^^^^^^^^^ this part is optional
|
# ^^^^^^^^^^^^^ this part is optional
|
||||||
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||||
@ -103,7 +104,7 @@
|
|||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
inputs.systems.follows = "systems";
|
inputs.systems.follows = "systems";
|
||||||
};
|
};
|
||||||
};
|
}; # }}}
|
||||||
|
|
||||||
outputs = {
|
outputs = {
|
||||||
self,
|
self,
|
||||||
@ -116,6 +117,7 @@
|
|||||||
self,
|
self,
|
||||||
config,
|
config,
|
||||||
lib,
|
lib,
|
||||||
|
nixfiles-lib,
|
||||||
...
|
...
|
||||||
} @ flakeArgs: {
|
} @ flakeArgs: {
|
||||||
# flake-parts imports
|
# flake-parts imports
|
||||||
@ -129,12 +131,86 @@
|
|||||||
# flake-parts systems (still uses nix-systems)
|
# flake-parts systems (still uses nix-systems)
|
||||||
systems = import inputs.systems;
|
systems = import inputs.systems;
|
||||||
|
|
||||||
|
# expose vars to nix repl
|
||||||
debug = lib.mkDefault true;
|
debug = lib.mkDefault true;
|
||||||
|
|
||||||
|
nixfiles = {
|
||||||
|
vars = {
|
||||||
|
### Configuration
|
||||||
|
# My username
|
||||||
|
username = "nullbite";
|
||||||
|
# My current timezone for any mobile devices (i.e., my laptop)
|
||||||
|
mobileTimeZone = "America/New_York";
|
||||||
|
};
|
||||||
|
|
||||||
|
common.overlays = let
|
||||||
|
nix-minecraft-patched-overlay = let
|
||||||
|
normal = inputs.nix-minecraft-upstream.overlays.default;
|
||||||
|
quilt = inputs.nix-minecraft.overlays.default;
|
||||||
|
in
|
||||||
|
lib.composeExtensions
|
||||||
|
normal
|
||||||
|
(final: prev: let
|
||||||
|
x = quilt final prev;
|
||||||
|
in {
|
||||||
|
inherit (x) quiltServers quilt-server;
|
||||||
|
minecraftServers = prev.minecraftServers // x.quiltServers;
|
||||||
|
});
|
||||||
|
|
||||||
|
packagesOverlay = final: prev: let
|
||||||
|
packages = import ./pkgs {inherit (prev) pkgs;};
|
||||||
|
in {
|
||||||
|
inherit (packages) mopidy-autoplay google-fonts;
|
||||||
|
atool-wrapped = packages.atool;
|
||||||
|
};
|
||||||
|
in [
|
||||||
|
packagesOverlay
|
||||||
|
# various temporary fixes that automatically revert
|
||||||
|
self.overlays.mitigations
|
||||||
|
|
||||||
|
# auto backports from nixpkgs unstable
|
||||||
|
self.overlays.backports
|
||||||
|
|
||||||
|
# modpacks (keeps modpack version in sync between hosts so i can reverse
|
||||||
|
# proxy create track map because it's broken)
|
||||||
|
self.overlays.modpacks
|
||||||
|
|
||||||
|
inputs.hyprwm-contrib.overlays.default
|
||||||
|
inputs.rust-overlay.overlays.default
|
||||||
|
inputs.nixfiles-assets.overlays.default
|
||||||
|
nix-minecraft-patched-overlay
|
||||||
|
];
|
||||||
|
|
||||||
|
systems = {
|
||||||
|
slab.system = "x86_64-linux";
|
||||||
|
nullbox.system = "x86_64-linux";
|
||||||
|
rpi4.system = "aarch64-linux";
|
||||||
|
|
||||||
|
nixos-wsl = {
|
||||||
|
system = "x86_64-linux";
|
||||||
|
wsl = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
# for eval testing
|
||||||
|
rpi4-x86_64 = {
|
||||||
|
system = "x86_64-linux";
|
||||||
|
name = "rpi4";
|
||||||
|
modules = [
|
||||||
|
{
|
||||||
|
nixpkgs.hostPlatform = "x86_64-linux";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}; # end systems
|
||||||
|
};
|
||||||
|
|
||||||
flake = let
|
flake = let
|
||||||
# {{{
|
# {{{
|
||||||
|
inherit (nixfiles-lib.flake-legacy) mkSystem mkWSLSystem mkISOSystem mkHome;
|
||||||
inherit (inputs) nixpkgs nixpkgs-unstable;
|
inherit (inputs) nixpkgs nixpkgs-unstable;
|
||||||
inherit (self) outputs;
|
inherit (self) outputs;
|
||||||
|
inherit (config.nixfiles.vars) username mobileTimeZone;
|
||||||
|
|
||||||
# inputs is already defined
|
# inputs is already defined
|
||||||
lib = nixpkgs.lib;
|
lib = nixpkgs.lib;
|
||||||
systems = ["x86_64-linux" "aarch64-linux"];
|
systems = ["x86_64-linux" "aarch64-linux"];
|
||||||
@ -176,260 +252,14 @@
|
|||||||
nix-minecraft-patched-overlay
|
nix-minecraft-patched-overlay
|
||||||
];
|
];
|
||||||
|
|
||||||
### Configuration
|
# function to generate packages for each system
|
||||||
# My username
|
|
||||||
username = "nullbite";
|
|
||||||
# My current timezone for any mobile devices (i.e., my laptop)
|
|
||||||
mobileTimeZone = "Europe/Amsterdam";
|
|
||||||
|
|
||||||
# Variables to be passed to NixOS modules in the vars attrset
|
|
||||||
vars = {
|
|
||||||
inherit username mobileTimeZone self;
|
|
||||||
};
|
|
||||||
|
|
||||||
# funciton to generate packages for each system
|
|
||||||
eachSystem = lib.genAttrs (import inputs.systems);
|
eachSystem = lib.genAttrs (import inputs.systems);
|
||||||
|
|
||||||
# This function produces a module that adds the home-manager module to the
|
|
||||||
# system and configures the given module to the user's Home Manager
|
|
||||||
# configuration
|
|
||||||
homeManagerInit = let
|
|
||||||
_username = username;
|
|
||||||
_nixpkgs = nixpkgs;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
system,
|
|
||||||
nixpkgs ? _nixpkgs, # this is so modules can know which flake the system is using
|
|
||||||
home-manager ? inputs.home-manager,
|
|
||||||
username ? _username,
|
|
||||||
module ? _: {},
|
|
||||||
rootModule ? (import ./home/root.nix),
|
|
||||||
userModules ? {
|
|
||||||
${username} = [module];
|
|
||||||
root = [rootModule];
|
|
||||||
},
|
|
||||||
stateVersion,
|
|
||||||
}: {
|
|
||||||
config,
|
|
||||||
lib,
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}: let
|
|
||||||
mapUserModules = lib.attrsets.mapAttrs (user: modules: {...}: {
|
|
||||||
imports =
|
|
||||||
[
|
|
||||||
./home
|
|
||||||
]
|
|
||||||
++ modules;
|
|
||||||
config = {
|
|
||||||
home = {inherit stateVersion;};
|
|
||||||
};
|
|
||||||
});
|
|
||||||
users = mapUserModules userModules;
|
|
||||||
in {
|
|
||||||
imports = [
|
|
||||||
home-manager.nixosModules.home-manager
|
|
||||||
];
|
|
||||||
|
|
||||||
home-manager = {
|
|
||||||
useGlobalPkgs = true;
|
|
||||||
useUserPackages = true;
|
|
||||||
backupFileExtension = "hm.bak";
|
|
||||||
inherit users;
|
|
||||||
extraSpecialArgs = {
|
|
||||||
inherit inputs outputs vars nixpkgs home-manager;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
# TODO rewrite this so it follows the same wrapper pattern as
|
|
||||||
# mkHome This function produces a nixosSystem which imports
|
|
||||||
# configuration.nix and a Home Manager home.nix for the given user
|
|
||||||
# from ./hosts/${hostname}/
|
|
||||||
#
|
|
||||||
# nevermind i am migrating everything to flake-parts, i'm glad i
|
|
||||||
# never got around to this. i think the module system takes care of
|
|
||||||
# whatever the fuck godforsaken use-case i had for rewriting this
|
|
||||||
# (more ergonomic and/or default arguments or something).
|
|
||||||
mkSystemN = let
|
|
||||||
_username = username;
|
|
||||||
_overlays = overlays;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
nixpkgs ? inputs.nixpkgs,
|
|
||||||
home-manager ? inputs.home-manager,
|
|
||||||
username ? _username,
|
|
||||||
entrypoint ? ./system,
|
|
||||||
modules ? [],
|
|
||||||
stateVersion ? null,
|
|
||||||
config ? {},
|
|
||||||
overlays ? _overlays,
|
|
||||||
system,
|
|
||||||
...
|
|
||||||
} @ args: let
|
|
||||||
_modules =
|
|
||||||
[entrypoint config]
|
|
||||||
++ modules
|
|
||||||
++ [
|
|
||||||
{
|
|
||||||
nixpkgs.config = {
|
|
||||||
inherit overlays;
|
|
||||||
allowUnfree = true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
]
|
|
||||||
++ lib.optional (args ? stateVersion) {config.system.stateVersion = stateVersion;};
|
|
||||||
in
|
|
||||||
nixpkgs.lib.nixosSystem {
|
|
||||||
};
|
|
||||||
mkSystem = let
|
|
||||||
_username = username;
|
|
||||||
_overlays = overlays;
|
|
||||||
_nixpkgs = nixpkgs;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
system,
|
|
||||||
nixpkgs ? _nixpkgs,
|
|
||||||
home-manager ? inputs.home-manager,
|
|
||||||
overlays ? _overlays,
|
|
||||||
hostname,
|
|
||||||
username ? _username,
|
|
||||||
stateVersion,
|
|
||||||
extraModules ? [],
|
|
||||||
}:
|
|
||||||
nixpkgs.lib.nixosSystem {
|
|
||||||
inherit system;
|
|
||||||
modules =
|
|
||||||
[
|
|
||||||
./system
|
|
||||||
({
|
|
||||||
pkgs,
|
|
||||||
config,
|
|
||||||
lib,
|
|
||||||
...
|
|
||||||
} @ args: {
|
|
||||||
# Values for every single system that would not conceivably need
|
|
||||||
# to be made modular
|
|
||||||
system.stateVersion = stateVersion;
|
|
||||||
nixpkgs = {
|
|
||||||
inherit overlays;
|
|
||||||
config = {
|
|
||||||
# not having the freedom to install unfree programs is unfree
|
|
||||||
allowUnfree = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
nix.settings.experimental-features = ["nix-command" "flakes"];
|
|
||||||
})
|
|
||||||
./hosts/${hostname}/configuration.nix
|
|
||||||
(homeManagerInit {
|
|
||||||
inherit nixpkgs home-manager;
|
|
||||||
module = import ./hosts/${hostname}/home.nix;
|
|
||||||
inherit username system stateVersion;
|
|
||||||
})
|
|
||||||
]
|
|
||||||
++ extraModules;
|
|
||||||
specialArgs = {
|
|
||||||
inherit inputs outputs vars nixpkgs home-manager;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
mkWSLSystem = let
|
|
||||||
_username = username;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
username ? _username,
|
|
||||||
extraModules ? [],
|
|
||||||
...
|
|
||||||
} @ args: let
|
|
||||||
WSLModule = {...}: {
|
|
||||||
imports = [
|
|
||||||
inputs.nix-wsl.nixosModules.wsl
|
|
||||||
];
|
|
||||||
wsl.enable = true;
|
|
||||||
wsl.defaultUser = username;
|
|
||||||
};
|
|
||||||
override = {extraModules = extraModules ++ [WSLModule];};
|
|
||||||
in
|
|
||||||
mkSystem (args // override);
|
|
||||||
|
|
||||||
mkISOSystem = system:
|
|
||||||
inputs.nixpkgs-unstable.lib.nixosSystem {
|
|
||||||
inherit system;
|
|
||||||
modules = [
|
|
||||||
"${inputs.nixpkgs-unstable}/nixos/modules/installer/cd-dvd/installation-cd-minimal-new-kernel-no-zfs.nix"
|
|
||||||
({
|
|
||||||
config,
|
|
||||||
pkgs,
|
|
||||||
lib,
|
|
||||||
...
|
|
||||||
}: {
|
|
||||||
environment.systemPackages = with pkgs; [
|
|
||||||
neovim
|
|
||||||
gparted
|
|
||||||
];
|
|
||||||
})
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
# values to be passed to nixosModules and homeManagerModules wrappers
|
# values to be passed to nixosModules and homeManagerModules wrappers
|
||||||
moduleInputs = {
|
moduleInputs = {
|
||||||
};
|
};
|
||||||
|
|
||||||
# Make a home-manager standalone configuration. This implementation is
|
|
||||||
# better than mkSystem because it extends homeManagerConfiguration.
|
|
||||||
mkHome = let
|
|
||||||
_home-manager = inputs.home-manager;
|
|
||||||
_nixpkgs = inputs.nixpkgs;
|
|
||||||
_username = username;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
home-manager ? _home-manager,
|
|
||||||
nixpkgs ? _nixpkgs,
|
|
||||||
username ? _username,
|
|
||||||
homeDirectory ? "/home/${username}",
|
|
||||||
entrypoint ? ./home/standalone.nix,
|
|
||||||
modules ? [],
|
|
||||||
stateVersion ? null,
|
|
||||||
config ? {},
|
|
||||||
system,
|
|
||||||
...
|
|
||||||
} @ args: let
|
|
||||||
_modules =
|
|
||||||
[entrypoint]
|
|
||||||
++ modules
|
|
||||||
++ [config]
|
|
||||||
++ [
|
|
||||||
{
|
|
||||||
config = {
|
|
||||||
home = {
|
|
||||||
inherit username homeDirectory;
|
|
||||||
};
|
|
||||||
nixpkgs.config = {
|
|
||||||
allowUnfree = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
]
|
|
||||||
++ lib.optional (args ? stateVersion) {config.home.stateVersion = stateVersion;};
|
|
||||||
in
|
|
||||||
home-manager.lib.homeManagerConfiguration ({
|
|
||||||
modules = _modules;
|
|
||||||
pkgs = import nixpkgs {inherit system overlays;};
|
|
||||||
|
|
||||||
extraSpecialArgs = {
|
|
||||||
inherit inputs outputs vars nixpkgs home-manager;
|
|
||||||
|
|
||||||
# this is needed because modules don't use the default arg for some reason???
|
|
||||||
osConfig = {};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
// builtins.removeAttrs args
|
|
||||||
["system" "nixpkgs" "home-manager" "modules" "username" "homeDirectory" "stateVersion" "entrypoint" "config"]);
|
|
||||||
# }}}
|
# }}}
|
||||||
in {
|
in {
|
||||||
# for repl debugging via :lf .
|
|
||||||
inherit inputs vars;
|
|
||||||
|
|
||||||
devShells = eachSystem (system: let
|
devShells = eachSystem (system: let
|
||||||
pkgs = import nixpkgs-unstable {inherit system;};
|
pkgs = import nixpkgs-unstable {inherit system;};
|
||||||
in {
|
in {
|
||||||
@ -471,51 +301,6 @@
|
|||||||
|
|
||||||
nixosConfigurations = {
|
nixosConfigurations = {
|
||||||
iso = mkISOSystem "x86_64-linux";
|
iso = mkISOSystem "x86_64-linux";
|
||||||
slab = mkSystem {
|
|
||||||
nixpkgs = inputs.nixpkgs-unstable;
|
|
||||||
home-manager = inputs.home-manager-unstable;
|
|
||||||
system = "x86_64-linux";
|
|
||||||
hostname = "slab";
|
|
||||||
stateVersion = "23.11";
|
|
||||||
};
|
|
||||||
|
|
||||||
nullbox = mkSystem {
|
|
||||||
nixpkgs = inputs.nixpkgs-unstable;
|
|
||||||
home-manager = inputs.home-manager-unstable;
|
|
||||||
system = "x86_64-linux";
|
|
||||||
hostname = "nullbox";
|
|
||||||
stateVersion = "23.11";
|
|
||||||
};
|
|
||||||
|
|
||||||
nixos-wsl = mkWSLSystem {
|
|
||||||
nixpkgs = inputs.nixpkgs-unstable;
|
|
||||||
home-manager = inputs.home-manager-unstable;
|
|
||||||
system = "x86_64-linux";
|
|
||||||
stateVersion = "23.11";
|
|
||||||
hostname = "nixos-wsl";
|
|
||||||
};
|
|
||||||
|
|
||||||
# for eval testing
|
|
||||||
rpi4-x86_64 = mkSystem {
|
|
||||||
nixpkgs = inputs.nixpkgs-unstable;
|
|
||||||
home-manager = inputs.home-manager-unstable;
|
|
||||||
system = "x86_64-linux";
|
|
||||||
stateVersion = "24.11";
|
|
||||||
hostname = "rpi4";
|
|
||||||
extraModules = [
|
|
||||||
{
|
|
||||||
nixpkgs.hostPlatform = "x86_64-linux";
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
rpi4 = mkSystem {
|
|
||||||
nixpkgs = inputs.nixpkgs-unstable;
|
|
||||||
home-manager = inputs.home-manager-unstable;
|
|
||||||
system = "aarch64-linux";
|
|
||||||
stateVersion = "24.11";
|
|
||||||
hostname = "rpi4";
|
|
||||||
};
|
|
||||||
}; # end nixosConfigurations
|
}; # end nixosConfigurations
|
||||||
|
|
||||||
homeConfigurations = {
|
homeConfigurations = {
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
{ ... }:
|
{...}: {
|
||||||
{
|
|
||||||
imports = [
|
imports = [
|
||||||
./packages.nix
|
./packages.nix
|
||||||
|
./home.nix
|
||||||
|
./system.nix
|
||||||
|
./meta.nix
|
||||||
|
./overlays.nix
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
1
flake/home.nix
Normal file
1
flake/home.nix
Normal file
@ -0,0 +1 @@
|
|||||||
|
{ ... }: { }
|
11
flake/meta.nix
Normal file
11
flake/meta.nix
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}: {
|
||||||
|
options.nixfiles.vars = lib.mkOption {
|
||||||
|
description = "Global variables";
|
||||||
|
type = lib.types.attrs;
|
||||||
|
default = {};
|
||||||
|
};
|
||||||
|
}
|
19
flake/overlays.nix
Normal file
19
flake/overlays.nix
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
inputs,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
overlayType = lib.mkOptionType {
|
||||||
|
name = "nixpkgs-overlay";
|
||||||
|
description = "nixpkgs overlay";
|
||||||
|
check = lib.isFunction;
|
||||||
|
merge = lib.mergeOneOption;
|
||||||
|
};
|
||||||
|
in {
|
||||||
|
options.nixfiles.common.overlays = lib.mkOption {
|
||||||
|
description = "List of overlays shared between various parts of the flake.";
|
||||||
|
type = lib.types.listOf overlayType;
|
||||||
|
default = [];
|
||||||
|
};
|
||||||
|
}
|
248
flake/system.nix
Normal file
248
flake/system.nix
Normal file
@ -0,0 +1,248 @@
|
|||||||
|
{
|
||||||
|
config,
|
||||||
|
options,
|
||||||
|
lib,
|
||||||
|
nixfiles-lib,
|
||||||
|
inputs,
|
||||||
|
self,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
cfg = config.nixfiles.systems;
|
||||||
|
inherit
|
||||||
|
(lib)
|
||||||
|
types
|
||||||
|
mkOption
|
||||||
|
mkIf
|
||||||
|
filterAttrs
|
||||||
|
mapAttrs
|
||||||
|
;
|
||||||
|
|
||||||
|
inherit (builtins) attrNames isNull;
|
||||||
|
|
||||||
|
inherit (nixfiles-lib.flake-legacy) mkSystem mkHome mkWSLSystem mkISOSystem homeManagerInit;
|
||||||
|
inherit (nixfiles-lib.types) mkCheckedType;
|
||||||
|
|
||||||
|
mkConfigurationOption = systemType:
|
||||||
|
mkOption {
|
||||||
|
description = "${systemType} configuration type";
|
||||||
|
type = with types; nullOr mkCheckedType "configuration";
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
in {
|
||||||
|
options.nixfiles.systems = let
|
||||||
|
systemModule = let
|
||||||
|
outerConfig = config;
|
||||||
|
outerOptions = options;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
name,
|
||||||
|
config,
|
||||||
|
...
|
||||||
|
}: {
|
||||||
|
options = {
|
||||||
|
enable =
|
||||||
|
lib.mkEnableOption ""
|
||||||
|
// {
|
||||||
|
description = ''
|
||||||
|
Whether to install this configuration into the flake outputs.
|
||||||
|
'';
|
||||||
|
default = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
nixpkgs = mkOption {
|
||||||
|
description = "nixpkgs input to build system with";
|
||||||
|
type = nixfiles-lib.types.flake;
|
||||||
|
default = inputs.nixpkgs-unstable;
|
||||||
|
};
|
||||||
|
|
||||||
|
extraConfig = mkOption {
|
||||||
|
description = ''
|
||||||
|
Arguments to pass to nixpkgs.lib.nixosSystem
|
||||||
|
'';
|
||||||
|
type = types.attrs;
|
||||||
|
default = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
system = mkOption {
|
||||||
|
description = "Nix system value";
|
||||||
|
type = types.str;
|
||||||
|
example = "x86_64-linux";
|
||||||
|
};
|
||||||
|
|
||||||
|
modules = mkOption {
|
||||||
|
description = "Extra NixOS configuration modules.";
|
||||||
|
type = with types; listOf deferredModule;
|
||||||
|
default = [];
|
||||||
|
};
|
||||||
|
|
||||||
|
name = mkOption {
|
||||||
|
description = ''
|
||||||
|
Name of NixOS configuration. This influences the default
|
||||||
|
directory to load configuration from. This does *not* modify the
|
||||||
|
system's hostname, but should probably be set to the same value.
|
||||||
|
'';
|
||||||
|
type = lib.types.str;
|
||||||
|
default = name;
|
||||||
|
};
|
||||||
|
|
||||||
|
configRoot = mkOption {
|
||||||
|
description = "Path to directory containing system and home configuration modules.";
|
||||||
|
type = lib.types.path;
|
||||||
|
default = self + "/hosts/${config.name}";
|
||||||
|
};
|
||||||
|
|
||||||
|
configuration = mkOption {
|
||||||
|
description = "Path/module of main NixOS configuration.";
|
||||||
|
type = with types; nullOr deferredModule;
|
||||||
|
default = config.configRoot + "/configuration.nix";
|
||||||
|
};
|
||||||
|
|
||||||
|
home-manager = {
|
||||||
|
enable =
|
||||||
|
lib.mkEnableOption ""
|
||||||
|
// {
|
||||||
|
description = ''
|
||||||
|
Whether to enable home-manager for this configuration.
|
||||||
|
'';
|
||||||
|
default = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
input = mkOption {
|
||||||
|
description = "home-manager input";
|
||||||
|
type = nixfiles-lib.types.flake;
|
||||||
|
default = inputs.home-manager-unstable;
|
||||||
|
};
|
||||||
|
|
||||||
|
configuration = mkOption {
|
||||||
|
description = "Path/module of main home-manager configuration.";
|
||||||
|
type = with types; nullOr deferredModule;
|
||||||
|
default = config.configRoot + "/home.nix";
|
||||||
|
};
|
||||||
|
|
||||||
|
modules = mkOption {
|
||||||
|
description = "Extra home-manager modules";
|
||||||
|
type = with types; listOf deferredModule;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
wsl =
|
||||||
|
lib.mkEnableOption ""
|
||||||
|
// {
|
||||||
|
description = ''
|
||||||
|
Whether to import WSL related configuration
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
result = lib.mkOption {
|
||||||
|
description = "Resulting system configuration";
|
||||||
|
type = with types; nullOr (mkCheckedType "configuration");
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
home-manager.input = lib.mkIf (config.nixpkgs == inputs.nixpkgs) (lib.mkDefault inputs.home-manager);
|
||||||
|
|
||||||
|
modules = let
|
||||||
|
nixfilesModule = self + "/system";
|
||||||
|
defaultsModule = {...}: {
|
||||||
|
# Values for every single system that would not conceivably need
|
||||||
|
# to be made modular
|
||||||
|
|
||||||
|
# this should be set in the system config
|
||||||
|
# system.stateVersion = stateVersion;
|
||||||
|
nixpkgs = {
|
||||||
|
inherit (outerConfig.nixfiles.common) overlays;
|
||||||
|
config = {
|
||||||
|
# not having the freedom to install unfree programs is unfree
|
||||||
|
allowUnfree = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
# this should be on by default and there is no reason to turn it
|
||||||
|
# off because this flake will literally stop working otheriwse
|
||||||
|
nix.settings.experimental-features = ["nix-command" "flakes"];
|
||||||
|
};
|
||||||
|
wslModule = {...}: {
|
||||||
|
imports = [
|
||||||
|
inputs.nix-wsl.nixosModules.wsl
|
||||||
|
];
|
||||||
|
wsl.enable = true;
|
||||||
|
wsl.defaultUser = outerConfig.nixfiles.vars.username;
|
||||||
|
};
|
||||||
|
|
||||||
|
homeManagerModule = let
|
||||||
|
homeManagerModuleInner = homeManagerInit {
|
||||||
|
inherit (config) nixpkgs system;
|
||||||
|
inherit (outerConfig.nixfiles.vars) username;
|
||||||
|
home-manager = config.home-manager.input;
|
||||||
|
module =
|
||||||
|
if (isNull config.home-manager.configuration)
|
||||||
|
then {}
|
||||||
|
else config.home-manager.configuration;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
pkgs,
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
inheritStateVersionModule = {lib, ...}: {
|
||||||
|
config = {
|
||||||
|
home.stateVersion = lib.mkDefault config.system.stateVersion;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in {
|
||||||
|
imports = [
|
||||||
|
# TODO placeholder using old function
|
||||||
|
homeManagerModuleInner
|
||||||
|
];
|
||||||
|
|
||||||
|
# previously, home-manager inherited stateVersion from nixos in
|
||||||
|
# a really hacky way that depended on the wrapper function.
|
||||||
|
# this should preserve that behavior in a much safer way by
|
||||||
|
# directly setting it in a module. ideally, it should probably
|
||||||
|
# be set manually, but I want to maintain backwards
|
||||||
|
# compatibility for now
|
||||||
|
options.home-manager.users = lib.mkOption {
|
||||||
|
type = with lib.types; attrsOf (submodule inheritStateVersionModule);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
[
|
||||||
|
nixfilesModule
|
||||||
|
defaultsModule
|
||||||
|
]
|
||||||
|
++ lib.optional (!(isNull config.configuration)) config.configuration
|
||||||
|
++ lib.optional config.home-manager.enable homeManagerModule
|
||||||
|
++ lib.optional config.wsl wslModule;
|
||||||
|
extraConfig = {
|
||||||
|
inherit (config) system modules;
|
||||||
|
# TODO get rid of specialArgs and pass things as a module
|
||||||
|
specialArgs = let
|
||||||
|
inherit (self) outputs;
|
||||||
|
in {
|
||||||
|
inherit inputs outputs;
|
||||||
|
inherit (outerConfig.nixfiles) vars;
|
||||||
|
inherit (config) nixpkgs;
|
||||||
|
inherit (config.home-manager) input;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
result = config.nixpkgs.lib.nixosSystem config.extraConfig;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
lib.mkOption {
|
||||||
|
description = ''
|
||||||
|
NixOS system configurations
|
||||||
|
'';
|
||||||
|
type = with types; attrsOf (submodule systemModule);
|
||||||
|
default = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
flake.nixosConfigurations = let
|
||||||
|
enabledSystems = filterAttrs (n: v: v.enable) cfg;
|
||||||
|
in
|
||||||
|
mapAttrs (_: v: v.result) enabledSystems;
|
||||||
|
};
|
||||||
|
}
|
@ -47,5 +47,8 @@
|
|||||||
device = "/";
|
device = "/";
|
||||||
options = [ "bind" ];
|
options = [ "bind" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# standard disclaimer don't change this for any reason whatsoever
|
||||||
|
system.stateVersion = "23.11";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -25,3 +25,7 @@ in
|
|||||||
// lib.optionalAttrs (attrs ? pkgs) {
|
// lib.optionalAttrs (attrs ? pkgs) {
|
||||||
minecraft = (import ./minecraft.nix) attrs';
|
minecraft = (import ./minecraft.nix) attrs';
|
||||||
}
|
}
|
||||||
|
# modules that rely on `self` (flake)
|
||||||
|
// lib.optionalAttrs (attrs ? self) {
|
||||||
|
flake-legacy = (import ./flake-legacy.nix) attrs';
|
||||||
|
}
|
||||||
|
259
lib/nixfiles/flake-legacy.nix
Normal file
259
lib/nixfiles/flake-legacy.nix
Normal file
@ -0,0 +1,259 @@
|
|||||||
|
{
|
||||||
|
self,
|
||||||
|
lib,
|
||||||
|
moduleAttrs,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
inherit (moduleAttrs.config.nixfiles.common) overlays;
|
||||||
|
|
||||||
|
### Configuration
|
||||||
|
# My username
|
||||||
|
username = "nullbite";
|
||||||
|
# My current timezone for any mobile devices (i.e., my laptop)
|
||||||
|
mobileTimeZone = "Europe/Amsterdam";
|
||||||
|
|
||||||
|
# Variables to be passed to NixOS modules in the vars attrset
|
||||||
|
vars = {
|
||||||
|
inherit username mobileTimeZone self;
|
||||||
|
};
|
||||||
|
|
||||||
|
# funciton to generate packages for each system
|
||||||
|
eachSystem = lib.genAttrs (import inputs.systems);
|
||||||
|
|
||||||
|
# values to be passed to nixosModules and homeManagerModules wrappers
|
||||||
|
moduleInputs = {
|
||||||
|
};
|
||||||
|
inherit (self) inputs outputs;
|
||||||
|
inherit (inputs) nixpkgs nixpkgs-unstable home-manager home-manager-unstable;
|
||||||
|
in rec {
|
||||||
|
# This function produces a module that adds the home-manager module to the
|
||||||
|
# system and configures the given module to the user's Home Manager
|
||||||
|
# configuration
|
||||||
|
homeManagerInit = let
|
||||||
|
_username = username;
|
||||||
|
_nixpkgs = nixpkgs;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
system,
|
||||||
|
nixpkgs ? _nixpkgs, # this is so modules can know which flake the system is using
|
||||||
|
home-manager ? inputs.home-manager,
|
||||||
|
username ? _username,
|
||||||
|
module ? _: {},
|
||||||
|
rootModule ? (import (self + "/home/root.nix")),
|
||||||
|
userModules ? {
|
||||||
|
${username} = [module];
|
||||||
|
root = [rootModule];
|
||||||
|
},
|
||||||
|
stateVersion ? null,
|
||||||
|
}: {
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
mapUserModules = lib.attrsets.mapAttrs (user: modules: {lib, ...}: {
|
||||||
|
imports =
|
||||||
|
[
|
||||||
|
(self + "/home")
|
||||||
|
]
|
||||||
|
++ modules;
|
||||||
|
config = {
|
||||||
|
home = lib.mkIf (!(builtins.isNull stateVersion)) {inherit stateVersion;};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
users = mapUserModules userModules;
|
||||||
|
in {
|
||||||
|
imports = [
|
||||||
|
home-manager.nixosModules.home-manager
|
||||||
|
];
|
||||||
|
|
||||||
|
home-manager = {
|
||||||
|
useGlobalPkgs = true;
|
||||||
|
useUserPackages = true;
|
||||||
|
backupFileExtension = "hm.bak";
|
||||||
|
inherit users;
|
||||||
|
extraSpecialArgs = {
|
||||||
|
inherit inputs outputs vars nixpkgs home-manager;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
# TODO rewrite this so it follows the same wrapper pattern as
|
||||||
|
# mkHome This function produces a nixosSystem which imports
|
||||||
|
# configuration.nix and a Home Manager home.nix for the given user
|
||||||
|
# from ./hosts/${hostname}/
|
||||||
|
#
|
||||||
|
# nevermind i am migrating everything to flake-parts, i'm glad i
|
||||||
|
# never got around to this. i think the module system takes care of
|
||||||
|
# whatever the fuck godforsaken use-case i had for rewriting this
|
||||||
|
# (more ergonomic and/or default arguments or something).
|
||||||
|
mkSystemN = let
|
||||||
|
_username = username;
|
||||||
|
_overlays = overlays;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
nixpkgs ? inputs.nixpkgs,
|
||||||
|
home-manager ? inputs.home-manager,
|
||||||
|
username ? _username,
|
||||||
|
entrypoint ? (self + "/system"),
|
||||||
|
modules ? [],
|
||||||
|
stateVersion ? null,
|
||||||
|
config ? {},
|
||||||
|
overlays ? _overlays,
|
||||||
|
system,
|
||||||
|
...
|
||||||
|
} @ args: let
|
||||||
|
_modules =
|
||||||
|
[entrypoint config]
|
||||||
|
++ modules
|
||||||
|
++ [
|
||||||
|
{
|
||||||
|
nixpkgs.config = {
|
||||||
|
inherit overlays;
|
||||||
|
allowUnfree = true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
]
|
||||||
|
++ lib.optional (args ? stateVersion) {config.system.stateVersion = stateVersion;};
|
||||||
|
in
|
||||||
|
nixpkgs.lib.nixosSystem {
|
||||||
|
};
|
||||||
|
mkSystem = let
|
||||||
|
_username = username;
|
||||||
|
_overlays = overlays;
|
||||||
|
_nixpkgs = nixpkgs;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
system,
|
||||||
|
nixpkgs ? _nixpkgs,
|
||||||
|
home-manager ? inputs.home-manager,
|
||||||
|
overlays ? _overlays,
|
||||||
|
hostname,
|
||||||
|
username ? _username,
|
||||||
|
stateVersion,
|
||||||
|
extraModules ? [],
|
||||||
|
}:
|
||||||
|
nixpkgs.lib.nixosSystem {
|
||||||
|
inherit system;
|
||||||
|
modules =
|
||||||
|
[
|
||||||
|
(self + "/system")
|
||||||
|
({
|
||||||
|
pkgs,
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
} @ args: {
|
||||||
|
# Values for every single system that would not conceivably need
|
||||||
|
# to be made modular
|
||||||
|
system.stateVersion = stateVersion;
|
||||||
|
nixpkgs = {
|
||||||
|
inherit overlays;
|
||||||
|
config = {
|
||||||
|
# not having the freedom to install unfree programs is unfree
|
||||||
|
allowUnfree = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
nix.settings.experimental-features = ["nix-command" "flakes"];
|
||||||
|
})
|
||||||
|
(self + "/hosts/${hostname}/configuration.nix")
|
||||||
|
(homeManagerInit {
|
||||||
|
inherit nixpkgs home-manager;
|
||||||
|
module = import (self + "/hosts/${hostname}/home.nix");
|
||||||
|
inherit username system stateVersion;
|
||||||
|
})
|
||||||
|
]
|
||||||
|
++ extraModules;
|
||||||
|
specialArgs = {
|
||||||
|
inherit inputs outputs vars nixpkgs home-manager;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
mkWSLSystem = let
|
||||||
|
_username = username;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
username ? _username,
|
||||||
|
extraModules ? [],
|
||||||
|
...
|
||||||
|
} @ args: let
|
||||||
|
WSLModule = {...}: {
|
||||||
|
imports = [
|
||||||
|
inputs.nix-wsl.nixosModules.wsl
|
||||||
|
];
|
||||||
|
wsl.enable = true;
|
||||||
|
wsl.defaultUser = username;
|
||||||
|
};
|
||||||
|
override = {extraModules = extraModules ++ [WSLModule];};
|
||||||
|
in
|
||||||
|
mkSystem (args // override);
|
||||||
|
|
||||||
|
mkISOSystem = system:
|
||||||
|
inputs.nixpkgs-unstable.lib.nixosSystem {
|
||||||
|
inherit system;
|
||||||
|
modules = [
|
||||||
|
"${inputs.nixpkgs-unstable}/nixos/modules/installer/cd-dvd/installation-cd-minimal-new-kernel-no-zfs.nix"
|
||||||
|
({
|
||||||
|
config,
|
||||||
|
pkgs,
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}: {
|
||||||
|
environment.systemPackages = with pkgs; [
|
||||||
|
neovim
|
||||||
|
gparted
|
||||||
|
];
|
||||||
|
})
|
||||||
|
];
|
||||||
|
};
|
||||||
|
# Make a home-manager standalone configuration. This implementation is
|
||||||
|
# better than mkSystem because it extends homeManagerConfiguration.
|
||||||
|
mkHome = let
|
||||||
|
_home-manager = inputs.home-manager;
|
||||||
|
_nixpkgs = inputs.nixpkgs;
|
||||||
|
_username = username;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
home-manager ? _home-manager,
|
||||||
|
nixpkgs ? _nixpkgs,
|
||||||
|
username ? _username,
|
||||||
|
homeDirectory ? "/home/${username}",
|
||||||
|
entrypoint ? (self + "/home/standalone.nix"),
|
||||||
|
modules ? [],
|
||||||
|
stateVersion ? null,
|
||||||
|
config ? {},
|
||||||
|
system,
|
||||||
|
...
|
||||||
|
} @ args: let
|
||||||
|
_modules =
|
||||||
|
[entrypoint]
|
||||||
|
++ modules
|
||||||
|
++ [config]
|
||||||
|
++ [
|
||||||
|
{
|
||||||
|
config = {
|
||||||
|
home = {
|
||||||
|
inherit username homeDirectory;
|
||||||
|
};
|
||||||
|
nixpkgs.config = {
|
||||||
|
allowUnfree = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
]
|
||||||
|
++ lib.optional (args ? stateVersion) {config.home.stateVersion = stateVersion;};
|
||||||
|
in
|
||||||
|
home-manager.lib.homeManagerConfiguration ({
|
||||||
|
modules = _modules;
|
||||||
|
pkgs = import nixpkgs {inherit system overlays;};
|
||||||
|
|
||||||
|
extraSpecialArgs = {
|
||||||
|
inherit inputs outputs vars nixpkgs home-manager;
|
||||||
|
|
||||||
|
# this is needed because modules don't use the default arg for some reason???
|
||||||
|
osConfig = {};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// builtins.removeAttrs args
|
||||||
|
["system" "nixpkgs" "home-manager" "modules" "username" "homeDirectory" "stateVersion" "entrypoint" "config"]);
|
||||||
|
}
|
@ -1,6 +1,10 @@
|
|||||||
{lib, ...}: let
|
{
|
||||||
|
lib,
|
||||||
|
self,
|
||||||
|
...
|
||||||
|
} @ moduleAttrs: let
|
||||||
inherit (lib) types;
|
inherit (lib) types;
|
||||||
nixfiles-lib = (import ./.) {inherit lib;};
|
nixfiles-lib = (import ./.) {inherit lib self moduleAttrs;};
|
||||||
in {
|
in {
|
||||||
options.nixfiles.lib = lib.mkOption {
|
options.nixfiles.lib = lib.mkOption {
|
||||||
description = "nixfiles library";
|
description = "nixfiles library";
|
||||||
|
@ -1,13 +1,21 @@
|
|||||||
{ pkgs, ... }:
|
{pkgs, ...}: let
|
||||||
let
|
|
||||||
inherit (pkgs) lib;
|
inherit (pkgs) lib;
|
||||||
inherit (lib.types) mkOptionType;
|
inherit (lib.types) mkOptionType;
|
||||||
inherit (lib.options) mergeEqualOption;
|
inherit (lib.options) mergeEqualOption;
|
||||||
in
|
in {
|
||||||
{
|
mkCheckedType = type:
|
||||||
|
mkOptionType {
|
||||||
|
name = "${type}";
|
||||||
|
description = "Attribute set of type ${type}";
|
||||||
|
descriptionClass = "noun";
|
||||||
|
merge = mergeEqualOption;
|
||||||
|
check = value: value._type or "" == "${type}";
|
||||||
|
};
|
||||||
flake = mkOptionType {
|
flake = mkOptionType {
|
||||||
name = "flake";
|
name = "flake";
|
||||||
description = "Nix flake";
|
description = "Nix flake";
|
||||||
descriptionClass = "noun";
|
descriptionClass = "noun";
|
||||||
merge = mergeEqualOption; check = (value: value._type or "" == "flake"); };
|
merge = mergeEqualOption;
|
||||||
|
check = value: value._type or "" == "flake";
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user