Skip to content

Commit

Permalink
feat: use flake-parts to clean up the flake.nix
Browse files Browse the repository at this point in the history
This is much more manageable!
  • Loading branch information
jalil-salame committed Oct 4, 2024
1 parent 584945f commit e03cd65
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 198 deletions.
26 changes: 26 additions & 0 deletions flake-modules/checks.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{ lib, ... }:
{
perSystem =
{ pkgs, self', ... }:
{
checks =
let
src = builtins.path {
path = ../.;
name = "configuration.nix";
};
runCmdInSrc =
name: cmd:
pkgs.runCommandNoCC name { } ''
cd ${src}
${cmd}
mkdir $out
'';
in
{
fmt = runCmdInSrc "fmt-src" "${lib.getExe self'.formatter} --check .";
lint = runCmdInSrc "lint-src" "${lib.getExe pkgs.statix} check .";
typos = runCmdInSrc "typos-src" "${lib.getExe pkgs.typos} .";
};
};
}
25 changes: 25 additions & 0 deletions flake-modules/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{ inputs, ... }:
let
overlays = builtins.attrValues inputs.self.overlays;
in
{
imports = [
./checks.nix
./devshells.nix
./docs.nix
./example-vm.nix
./nixos-modules.nix
./nvim.nix
./overlays.nix
./scripts.nix
];

perSystem =
{ system, pkgs, ... }:
{
_module.args.pkgs = import inputs.nixpkgs { inherit system overlays; };

# Nix files formatter (run `nix fmt`)
formatter = pkgs.nixfmt-rfc-style;
};
}
13 changes: 13 additions & 0 deletions flake-modules/devshells.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
_: {
perSystem =
{ pkgs, self', ... }:
{
devShells.default = pkgs.mkShellNoCC {
buildInputs = [
pkgs.just
self'.packages.nvim
];
QEMU_OPTS_WL = "--enable-kvm -smp 4 -device virtio-gpu-rutabaga,gfxstream-vulkan=on,cross-domain=on,hostmem=2G,wsi=headless";
};
};
}
16 changes: 16 additions & 0 deletions flake-modules/docs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{ lib, ... }:
{
perSystem =
{ pkgs, ... }:
{
packages = {
# Documentation
inherit (import ../docs { inherit pkgs lib; })
docs
nixos-markdown
nvim-markdown
home-markdown
;
};
};
}
46 changes: 46 additions & 0 deletions flake-modules/example-vm.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{ inputs, lib, ... }:
{
# Example vm configuration
flake.nixosConfigurations.vm =
let
system = "x86_64-linux";
overlays = builtins.attrValues inputs.self.overlays;
config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ "steam-original" ];
pkgs = import inputs.nixpkgs { inherit system overlays config; };
in
lib.nixosSystem {
inherit system pkgs;
modules = [
inputs.self.nixosModules.vm # import vm module
{
time.timeZone = "Europe/Berlin";
i18n.defaultLocale = "en_US.UTF-8";
users.users.jdoe = {
password = "example";
isNormalUser = true;
extraGroups = [
"wheel"
"video"
"networkmanager"
];
};
home-manager.users.jdoe = {
home = {
username = "jdoe";
homeDirectory = "/home/jdoe";
};
jhome = {
enable = true;
gui.enable = true;
dev.rust.enable = true;
};
};
nix.registry.nixpkgs.flake = inputs.nixpkgs;
jconfig = {
enable = true;
gui.enable = true;
};
}
];
};
}
43 changes: 43 additions & 0 deletions flake-modules/nixos-modules.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{ inputs, lib, ... }:
{
flake.nixosModules =
let
nvim-config.imports = [
inputs.nixvim.homeManagerModules.nixvim
../nvim
];
homeManagerModuleSandalone = import ../home {
inherit nvim-config;
inherit (inputs) stylix;
};
homeManagerModuleNixOS = import ../home { inherit nvim-config; };
nixosModule = {
imports = [
(import ../system { inherit (inputs) stylix; })
inputs.home-manager.nixosModules.home-manager
] ++ lib.optional (inputs.lix-module != null) inputs.lix-module.nixosModules.default;
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
sharedModules = [ homeManagerModuleNixOS ];
};
# Pin nixpkgs
nix.registry.nixpkgs.flake = inputs.nixpkgs;
};

machines = [ "vm" ];
mkMachine = hostname: {
imports = [
nixosModule
(import (../machines + "/${hostname}"))
];
home-manager.sharedModules = [ { jhome.hostName = hostname; } ];
};
machineModules = lib.genAttrs machines mkMachine;
in
{
default = nixosModule;
inherit nixosModule homeManagerModuleNixOS homeManagerModuleSandalone;
}
// machineModules;
}
24 changes: 24 additions & 0 deletions flake-modules/nvim.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{ inputs, ... }:
let
standalone = ../nvim/standalone.nix;
in
{
flake.overlays.nixvim = inputs.nixvim.overlays.default;

perSystem =
{ pkgs, system, ... }:
{
# Check standalone nvim build
checks.nvim = inputs.nixvim.lib.${system}.check.mkTestDerivationFromNixvimModule {
inherit pkgs;
module = ../nvim/standalone.nix;
};

# Nvim standalone module
packages.nvim = inputs.nixvim.legacyPackages.${system}.makeNixvimWithModule {
inherit pkgs;
module = standalone;
};

};
}
26 changes: 26 additions & 0 deletions flake-modules/overlays.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{ inputs, ... }:
{
# Add unstable packages to overlay
flake.overlays.unstable =
final: prev:
let
unstablePkgs = inputs.unstable.legacyPackages.${prev.stdenv.hostPlatform.system};
in
{
# Get unstable packages
unstable = unstablePkgs;

# Update vim plugins with the versions from unstable
vimPlugins = prev.vimPlugins // unstablePkgs.vimPlugins;

# Get specific packages from unstable
inherit (unstablePkgs)
gitoxide
jujutsu
neovim-unwrapped
ruff # nixpkgs stable version is improperly configured by nixvim
# wezterm
;
};

}
14 changes: 14 additions & 0 deletions flake-modules/scripts.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
let
scripts = import ../scripts;
in
{
# Add scripts to overlay
flake.overlays.scripts = final: prev: scripts final;

# Add scripts to packages
perSystem =
{ pkgs, ... }:
{
packages = scripts pkgs;
};
}
12 changes: 7 additions & 5 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e03cd65

Please sign in to comment.