Add module system basics & nix itself
diff --git a/flake.lock b/flake.lock
index b9629ec..c0bca6c 100644
--- a/flake.lock
+++ b/flake.lock
@@ -31,10 +31,27 @@
"type": "github"
}
},
+ "registry": {
+ "flake": false,
+ "locked": {
+ "lastModified": 1657791189,
+ "narHash": "sha256-Z2ckMWqybpJjIdGIPuHcYzTL7DPTbFKpBZJJgGfFUog=",
+ "owner": "nixos",
+ "repo": "flake-registry",
+ "rev": "7a481cef7e86d6ceb4aec244d9bb085619360ba1",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nixos",
+ "repo": "flake-registry",
+ "type": "github"
+ }
+ },
"root": {
"inputs": {
"flake-utils": "flake-utils",
- "nixpkgs": "nixpkgs"
+ "nixpkgs": "nixpkgs",
+ "registry": "registry"
}
}
},
diff --git a/flake.nix b/flake.nix
index c4a49dc..d2dc6af 100644
--- a/flake.nix
+++ b/flake.nix
@@ -2,15 +2,41 @@
description = "Minion's NixOS configuration (since 2022-08-19)";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
+ inputs.registry = {
+ url = "github:nixos/flake-registry";
+ flake = false;
+ };
- outputs = {
- self,
- nixpkgs,
- flake-utils,
- }:
+ outputs = inputs: let
+ inherit (inputs) self nixpkgs flake-utils;
+ in
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
+
+ utils = import ./utils/utils.nix pkgs.lib;
+
+ username = "minion";
in {
+ nixosConfigurations = {
+ default = pkgs.lib.nixosSystem {
+ inherit system;
+
+ home-manager.useGlobalPkgs = true;
+
+ modules = pkgs.lib.pipe ./modules [
+ utils.nixFilesIn
+ utils.importAll
+ (utils.interpretNonstandardModule (args:
+ args
+ // {
+ home =
+ args.config.home-manager."${username}";
+ }))
+ ];
+
+ specialArgs = inputs // {inherit username;};
+ };
+ };
devShell = pkgs.mkShell {
nativeBuildInputs = with pkgs; [nodePackages.prettier alejandra];
buildInputs = [];
diff --git a/modules/nix.nix b/modules/nix.nix
new file mode 100644
index 0000000..999068c
--- /dev/null
+++ b/modules/nix.nix
@@ -0,0 +1,20 @@
+{
+ pkgs,
+ registry,
+ ...
+}: {
+ config = {
+ nix = {
+ settings = {
+ experimental-features = ["nix-command" "flakes"];
+ auto-optimise-store = true;
+ keep-outputs = true;
+ flake-registry = "${registry}/flake-registry.json";
+ };
+ gc = {
+ automatic = true;
+ options = "--delete-older-than 7d";
+ };
+ };
+ };
+}
diff --git a/modules/secrets.nix b/modules/secrets.nix
index f891de7..cb55e20 100644
--- a/modules/secrets.nix
+++ b/modules/secrets.nix
@@ -1,8 +1,8 @@
-{ pkgs, ... }: {
- config = {
- environment.systemPackages = with pkgs; [
- sops
- ];
- sops.defaultSopsFile = ../secrets/secrets.json;
- };
+{pkgs, ...}: {
+ config = {
+ environment.systemPackages = with pkgs; [
+ sops
+ ];
+ sops.defaultSopsFile = ../secrets/secrets.json;
+ };
}
diff --git a/utils/importAll.nix b/utils/importAll.nix
new file mode 100644
index 0000000..b6130fb
--- /dev/null
+++ b/utils/importAll.nix
@@ -0,0 +1,3 @@
+# Pretty basic function to import all files in a list, because it looks nicer to
+# do utils.importAll than this map operation
+nixFiles: map import nixFiles
diff --git a/utils/interpretNonstandardModule.nix b/utils/interpretNonstandardModule.nix
index 533cf6c..edb4231 100644
--- a/utils/interpretNonstandardModule.nix
+++ b/utils/interpretNonstandardModule.nix
@@ -3,7 +3,7 @@
# This function takes a list of modules, as well as arguments to import them
# with, and returns a list of modules, each with the standard NixOS module
# properties as well as with custom properties as described in /README.md
-modules: args: let
+transformArgs: modules: args: let
resolver = module: let
importedModule =
if builtins.typeOf module == "path"
@@ -13,14 +13,14 @@
if builtins.typeOf importedModule == "lambda"
then
resolvedModule
- args
+ (transformArgs args)
else resolvedModule;
in {
home = module.home or {};
module = {
- module.config or {};
- module.imports or {};
- module.options or {};
+ config = module.config or {};
+ imports = module.imports or {};
+ options = module.options or {};
};
};
in (
diff --git a/utils/nixFilesIn.nix b/utils/nixFilesIn.nix
new file mode 100644
index 0000000..b5340bd
--- /dev/null
+++ b/utils/nixFilesIn.nix
@@ -0,0 +1,2 @@
+# Modified from http://chriswarbo.net/projects/nixos/useful_hacks.html
+lib: dir: map (name: dir + "/${name}") (lib.attrNames (lib.filterAttrs (name: _: lib.hasSuffix ".nix" name) (builtins.readDir dir)))
diff --git a/utils/utils.nix b/utils/utils.nix
new file mode 100644
index 0000000..8b1b731
--- /dev/null
+++ b/utils/utils.nix
@@ -0,0 +1,8 @@
+lib:
+builtins.listToAttrs builtins.map (path: {
+ name = nixpkgs.lib.pipe path [
+ (nixpkgs.lib.removeSuffix ".nix")
+ (nixpkgs.lib.removePrefix ./.)
+ ];
+ value = import path;
+}) ((import ./nixFilesIn.nix) ./.)