refactor: modularize flake and import nixpkgs
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-05-20 22:41:45 -04:00
parent 7a52fc6beb
commit 0861880a20
8 changed files with 160 additions and 138 deletions

19
ci.nix Normal file
View file

@ -0,0 +1,19 @@
# CI: https://github.com/Mic92/dotfiles/blob/c2f538934d67417941f83d8bb65b8263c43d32ca/flake.nix#L168
{
system,
pkgs,
self,
}: let
inherit (pkgs.lib) filterAttrs mapAttrs' nameValuePair;
nixosMachines =
mapAttrs'
(name: config: nameValuePair "nixos-${name}" config.config.system.build.toplevel)
((filterAttrs (_: config: config.pkgs.system == system)) self.nixosConfigurations);
devShells =
mapAttrs'
(n: nameValuePair "devShell-${n}")
self.devShells;
in
nixosMachines // devShells

View file

@ -23,10 +23,6 @@
../modules/nvidia.nix ../modules/nvidia.nix
]; ];
nixpkgs = {
config.allowUnfree = true;
overlays = import ./overlays inputs;
};
boot.tmp.useTmpfs = true; boot.tmp.useTmpfs = true;
nix = { nix = {

View file

@ -1,8 +1,7 @@
{ {
basedpyrightPkgs,
config, config,
lib, lib,
pkgs,
basedpyright,
... ...
}: let }: let
inherit (config.vars) neovimIde; inherit (config.vars) neovimIde;
@ -13,7 +12,7 @@ in
withPython3 = true; withPython3 = true;
extraPackages = [ extraPackages = [
basedpyright.legacyPackages.${pkgs.system}.basedpyright basedpyrightPkgs.basedpyright
]; ];
extraLuaConfig = extraLuaConfig =

View file

@ -23,16 +23,10 @@
substituters = [ substituters = [
# Nix-community # Nix-community
"https://nix-community.cachix.org" "https://nix-community.cachix.org"
# FIXME: cache doesn't work
# Personal config cache
# "https://cache.nelim.org"
]; ];
trustedPublicKeys = [ trustedPublicKeys = [
# Nix-community # Nix-community
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
# Personal config cache
# "cache.nelim.org:JmFqkUdH11EA9EZOFAGVHuRYp7EbsdJDHvTQzG2pPyY="
]; ];
}; };

View file

@ -1,27 +1,72 @@
{ {
home-manager, config,
nix-on-droid, lib,
nixpkgs, pkgs,
... ...
} @ inputs: }: {
nix-on-droid.lib.nixOnDroidConfiguration rec { vars = {
extraSpecialArgs = inputs; mainUser = "nix-on-droid";
home-manager-path = home-manager.outPath; hostName = "localhost";
pkgs = import nixpkgs { neovimIde = false;
system = "aarch64-linux";
overlays = import ../../common/overlays inputs;
}; };
modules = [ environment.variables.FLAKE = "/data/data/com.termux.nix/files/home/.nix";
{
options = with pkgs.lib; { terminal.font = "${(pkgs.nerdfonts.override {
environment.variables.FLAKE = mkOption { fonts = [
type = with types; nullOr str; "JetBrainsMono"
};
};
}
{home-manager.extraSpecialArgs = inputs;}
../../common/nix-on-droid.nix
./nix-on-droid.nix
]; ];
})}/share/fonts/truetype/NerdFonts/JetBrainsMonoNerdFontMono-Regular.ttf";
environment.packages =
(with pkgs; [
diffutils
findutils
utillinux
tzdata
hostname
man
gnugrep
ripgrep
gnupg
gnused
gnutar
bzip2
gzip
xz
zip
unzip
openssh
perl
which
alejandra
])
++ [
(pkgs.writeShellApplication {
name = "switch";
runtimeInputs = with pkgs; [
nix-output-monitor
];
text = ''
exec nix-on-droid ${lib.concatStringsSep " " [
"switch"
"--flake ${config.environment.variables.FLAKE}"
"--builders ssh-ng://matt@100.64.0.7"
''"$@"''
"|&"
"nom"
]}
'';
})
];
environment.etcBackupExtension = ".bak";
environment.motd = null;
home-manager.backupFileExtension = "hm-bak";
# Set your time zone.
time.timeZone = "America/Montreal";
# No touchy
system.stateVersion = "23.05";
} }

View file

@ -1,72 +0,0 @@
{
config,
lib,
pkgs,
...
}: {
vars = {
mainUser = "nix-on-droid";
hostName = "localhost";
neovimIde = false;
};
environment.variables.FLAKE = "/data/data/com.termux.nix/files/home/.nix";
terminal.font = "${(pkgs.nerdfonts.override {
fonts = [
"JetBrainsMono"
];
})}/share/fonts/truetype/NerdFonts/JetBrainsMonoNerdFontMono-Regular.ttf";
environment.packages =
(with pkgs; [
diffutils
findutils
utillinux
tzdata
hostname
man
gnugrep
ripgrep
gnupg
gnused
gnutar
bzip2
gzip
xz
zip
unzip
openssh
perl
which
alejandra
])
++ [
(pkgs.writeShellApplication {
name = "switch";
runtimeInputs = with pkgs; [
nix-output-monitor
];
text = ''
exec nix-on-droid ${lib.concatStringsSep " " [
"switch"
"--flake ${config.environment.variables.FLAKE}"
"--builders ssh-ng://matt@100.64.0.7"
''"$@"''
"|&"
"nom"
]}
'';
})
];
environment.etcBackupExtension = ".bak";
environment.motd = null;
home-manager.backupFileExtension = "hm-bak";
# Set your time zone.
time.timeZone = "America/Montreal";
# No touchy
system.stateVersion = "23.05";
}

View file

@ -42,39 +42,29 @@
secrets, secrets,
... ...
}: let }: let
inherit (import ./lib.nix inputs) mkNixOS mkNixOnDroid mkPkgs;
supportedSystems = ["x86_64-linux" "aarch64-linux"]; supportedSystems = ["x86_64-linux" "aarch64-linux"];
perSystem = attrs: perSystem = attrs:
nixpkgs.lib.genAttrs supportedSystems (system: let nixpkgs.lib.genAttrs supportedSystems (system:
pkgs = nixpkgs.legacyPackages.${system}; attrs system (mkPkgs system nixpkgs));
in
attrs system pkgs);
# Default system
mkNixOS = mods:
nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = inputs;
modules =
[
{home-manager.extraSpecialArgs = inputs;}
./common
]
++ mods;
};
in { in {
nixosConfigurations = { nixosConfigurations = {
# Desktops
wim = mkNixOS [ wim = mkNixOS [
./devices/wim ./devices/wim
secrets.nixosModules.default secrets.nixosModules.default
]; ];
binto = mkNixOS [./devices/binto]; binto = mkNixOS [./devices/binto];
# NAS
nos = mkNixOS [ nos = mkNixOS [
./devices/nos ./devices/nos
secrets.nixosModules.nos secrets.nixosModules.nos
]; ];
# Build / test server
servivi = mkNixOS [ servivi = mkNixOS [
./devices/servivi ./devices/servivi
secrets.nixosModules.servivi secrets.nixosModules.servivi
@ -103,20 +93,7 @@
]; ];
}; };
nixOnDroidConfigurations.default = import ./devices/android inputs; nixOnDroidConfigurations.default = mkNixOnDroid [./devices/android];
formatter = perSystem (_: pkgs: pkgs.alejandra);
# CI: https://github.com/Mic92/dotfiles/blob/c2f538934d67417941f83d8bb65b8263c43d32ca/flake.nix#L168
checks = perSystem (system: pkgs: let
inherit (pkgs.lib) filterAttrs mapAttrs' nameValuePair;
nixosMachines = mapAttrs' (
name: config: nameValuePair "nixos-${name}" config.config.system.build.toplevel
) ((filterAttrs (_: config: config.pkgs.system == system)) self.nixosConfigurations);
devShells = mapAttrs' (n: nameValuePair "devShell-${n}") self.devShells;
in
nixosMachines // devShells);
devShells = perSystem (_: pkgs: { devShells = perSystem (_: pkgs: {
default = pkgs.mkShell { default = pkgs.mkShell {
@ -149,5 +126,12 @@
]); ]);
}; };
}); });
formatter = perSystem (_: pkgs: pkgs.alejandra);
# For nix-fast-build
checks =
perSystem (system: pkgs:
import ./ci.nix {inherit system pkgs self;});
}; };
} }

57
lib.nix Normal file
View file

@ -0,0 +1,57 @@
{
basedpyright,
home-manager,
nix-on-droid,
nixpkgs,
...
} @ inputs: rec {
# Import pkgs from a nixpkgs
mkPkgs = system: input:
import input {
inherit system;
config.allowUnfree = true;
overlays = import ./common/overlays inputs;
};
# Function that makes the attrs that make up the specialArgs
mkArgs = system:
inputs
// {
pkgs = mkPkgs system nixpkgs;
basedpyrightPkgs = mkPkgs system basedpyright;
};
# Default system
mkNixOS = mods:
nixpkgs.lib.nixosSystem rec {
system = "x86_64-linux";
specialArgs = mkArgs system;
modules =
[
{home-manager.extraSpecialArgs = specialArgs;}
./common
]
++ mods;
};
mkNixOnDroid = mods:
nix-on-droid.lib.nixOnDroidConfiguration rec {
extraSpecialArgs = mkArgs "aarch64-linux";
home-manager-path = home-manager.outPath;
pkgs = extraSpecialArgs.pkgs;
modules =
[
{
options = with pkgs.lib; {
environment.variables.FLAKE = mkOption {
type = with types; nullOr str;
};
};
}
{home-manager = {inherit extraSpecialArgs;};}
./common/nix-on-droid.nix
]
++ mods;
};
}