nixos-configs/lib/flake/default.nix

117 lines
3 KiB
Nix
Raw Normal View History

inputs: rec {
# Import pkgs from a nixpkgs instance
mkPkgs = {
system,
nixpkgs,
cfg ? {},
2024-12-10 22:28:26 -05:00
nix ? null,
cudaSupport ? false,
}:
import nixpkgs {
inherit system;
2024-12-10 22:28:26 -05:00
overlays =
[
(inputs.self.overlays.nix-version {inherit nix;})
inputs.self.overlays.build-failures
]
++ (cfg.overlays or []);
config =
{
inherit cudaSupport;
allowUnfree = true;
2024-12-22 03:12:45 -05:00
# FIXME: Roslyn-ls uses dotnet6 https://github.com/NixOS/nixpkgs/blob/d3c42f187194c26d9f0309a8ecc469d6c878ce33/pkgs/by-name/ro/roslyn-ls/package.nix#L21
permittedInsecurePackages =
[
"dotnet-core-combined"
"dotnet-sdk-6.0.428"
"dotnet-sdk-wrapped-6.0.428"
]
++ (cfg.config.permittedInsecurePackages or []);
}
// (builtins.removeAttrs (
if cfg.config or null == null
then {}
else cfg.config
) ["permittedInsecurePackages"]);
};
2024-09-25 15:34:56 -04:00
# Enable use of `nixpkgs.overlays` on both NixOS and NixOnDroid
2024-09-22 23:16:10 -04:00
allowModularOverrides = {
cudaSupport ? false,
system,
2024-09-22 23:16:10 -04:00
}: ({config, ...}: let
pkgs = mkPkgs {
cfg = config.nixpkgs;
2024-12-10 22:28:26 -05:00
nix = config.nix.package;
2024-09-22 23:16:10 -04:00
inherit system cudaSupport;
inherit (inputs) nixpkgs;
};
inherit (pkgs.lib) mkForce;
2024-09-22 23:16:10 -04:00
in {
_module.args.pkgs = mkForce pkgs;
2024-09-22 23:16:10 -04:00
});
# Default system
mkNixOS = {
extraModules ? [],
cudaSupport ? false,
mainUser ? "matt",
}:
inputs.nixpkgs.lib.nixosSystem rec {
system = "x86_64-linux";
specialArgs = inputs // {inherit mainUser;};
modules =
[
2024-09-22 23:16:10 -04:00
(allowModularOverrides {inherit system cudaSupport;})
inputs.home-manager.nixosModules.home-manager
{home-manager.extraSpecialArgs = specialArgs;}
]
++ extraModules;
};
mkNixOnDroid = extraModules: let
system = "aarch64-linux";
in
inputs.nix-on-droid.lib.nixOnDroidConfiguration rec {
2024-09-22 23:16:10 -04:00
extraSpecialArgs = inputs;
home-manager-path = inputs.home-manager.outPath;
pkgs = mkPkgs {
inherit system;
inherit (inputs) nixpkgs;
};
2024-09-22 23:16:10 -04:00
modules =
[
(allowModularOverrides {inherit system;})
2024-09-22 23:16:10 -04:00
({
config,
lib,
...
}: let
inherit (lib) mkForce mkOption types;
2024-09-22 23:16:10 -04:00
in {
# Adapt NixOnDroid to NixOS options
options.environment = {
variables.FLAKE = mkOption {
type = with types; nullOr str;
};
2024-09-22 23:16:10 -04:00
systemPackages = mkOption {
type = with types; listOf package;
default = [];
};
};
2024-09-22 23:16:10 -04:00
config.environment.packages = config.environment.systemPackages;
2024-09-25 15:34:56 -04:00
# This disables the assertion that fails because of nixpkgs.overlays
config._module.args.isFlake = mkForce false;
})
2024-09-22 23:16:10 -04:00
{home-manager = {inherit extraSpecialArgs;};}
]
++ extraModules;
};
}