From 03c19b674c97ad8e571b02f4a5918098cef2d57e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikodem=20Rabuli=C5=84ski?= Date: Sun, 23 Mar 2025 11:43:37 +0100 Subject: [PATCH 01/13] nilla: init --- flake.lock | 34 ++++++++++++++++++++++++++++++++++ flake.nix | 8 ++++++++ inputs.nix | 10 ++++++++++ nilla.nix | 37 +++++++++++++++++++++++++++++++++++++ shell.nix | 1 + 5 files changed, 90 insertions(+) create mode 100644 inputs.nix create mode 100644 nilla.nix create mode 100644 shell.nix diff --git a/flake.lock b/flake.lock index 5d68e57..d40edeb 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,21 @@ { "nodes": { + "__flake-compat": { + "flake": false, + "locked": { + "lastModified": 1742412704, + "narHash": "sha256-mhazLo8DuZ3c6r5I7hDxxag8ftAM4W0aUjFjQuw8q5c=", + "ref": "refs/heads/main", + "rev": "f7a7752f237bbc59b868058f70cffd3e436b49b7", + "revCount": 69, + "type": "git", + "url": "https://git.lix.systems/lix-project/flake-compat.git" + }, + "original": { + "type": "git", + "url": "https://git.lix.systems/lix-project/flake-compat.git" + } + }, "agenix": { "inputs": { "darwin": [ @@ -510,6 +526,22 @@ "type": "github" } }, + "nilla": { + "flake": false, + "locked": { + "lastModified": 1742722370, + "narHash": "sha256-MqdseA78bo2M3zfb0mjcBPYU2Qn9CF/KH5LZivWRtB0=", + "owner": "nilla-nix", + "repo": "nilla", + "rev": "b30b5a225843ab649a9b140eb3cbbcc8030a7eaf", + "type": "github" + }, + "original": { + "owner": "nilla-nix", + "repo": "nilla", + "type": "github" + } + }, "nix-github-actions": { "inputs": { "nixpkgs": [ @@ -681,6 +713,7 @@ }, "root": { "inputs": { + "__flake-compat": "__flake-compat", "agenix": "agenix", "attic": "attic", "conduit-src": "conduit-src", @@ -696,6 +729,7 @@ "lix-module": "lix-module", "mailserver": "mailserver", "niko-nur": "niko-nur", + "nilla": "nilla", "nixpkgs": "nixpkgs_2", "nvidia-patch": "nvidia-patch", "racket": "racket", diff --git a/flake.nix b/flake.nix index 217b7cc..463e379 100644 --- a/flake.nix +++ b/flake.nix @@ -168,6 +168,14 @@ url = "github:numtide/treefmt-nix"; inputs.nixpkgs.follows = "nixpkgs"; }; + __flake-compat = { + url = "git+https://git.lix.systems/lix-project/flake-compat.git"; + flake = false; + }; + nilla = { + url = "github:nilla-nix/nilla"; + flake = false; + }; }; /* diff --git a/inputs.nix b/inputs.nix new file mode 100644 index 0000000..27826d6 --- /dev/null +++ b/inputs.nix @@ -0,0 +1,10 @@ +let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + inherit (lock.nodes.__flake-compat.locked) narHash rev url; + flake-compat = builtins.fetchTarball { + url = "${url}/archive/${rev}.tar.gz"; + sha256 = narHash; + }; + flake = import flake-compat { src = ./.; }; +in +flake.inputs diff --git a/nilla.nix b/nilla.nix new file mode 100644 index 0000000..48729f7 --- /dev/null +++ b/nilla.nix @@ -0,0 +1,37 @@ +{ + inputs ? import ./inputs.nix, +}: +(import inputs.nilla).create ( + { lib }: + { + config.inputs = builtins.mapAttrs (_: src: { + inherit src; + loader = "raw"; + }) inputs; + + config.builders.nixpkgs-flake = { + settings.type = lib.types.submodule { + options.args = lib.options.create { + type = lib.types.any; + default.value = { }; + }; + }; + settings.default = { }; + build = + pkg: + lib.attrs.generate pkg.systems ( + system: inputs.nixpkgs.legacyPackages.${system}.callPackage pkg.package pkg.settings.args + ); + }; + + config.shells.default = { + systems = [ "x86_64-linux" ]; + builder = "nixpkgs-flake"; + shell = + { mkShell, hello }: + mkShell { + packages = [ hello ]; + }; + }; + } +) diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..0cb2ef7 --- /dev/null +++ b/shell.nix @@ -0,0 +1 @@ +(import ./nilla.nix { }).shells.default.result.${builtins.currentSystem} From 5b421a79d4d1ef5ec126a3d829594c3368a9c95b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikodem=20Rabuli=C5=84ski?= Date: Sun, 23 Mar 2025 12:15:58 +0100 Subject: [PATCH 02/13] nilla: migrate devshells --- flake.nix | 13 ++++----- nilla.nix | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 81 insertions(+), 14 deletions(-) diff --git a/flake.nix b/flake.nix index 463e379..93b8f6a 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,9 @@ { outputs = inputs@{ flake-parts, ... }: + let + nilla = import ./nilla.nix { inherit inputs; }; + in flake-parts.lib.mkFlake { inherit inputs; } { systems = [ "x86_64-linux" @@ -24,17 +27,11 @@ inputs', self', pkgs, + system, ... }: { - devShells.default = pkgs.mkShellNoCC { - packages = [ - inputs'.agenix.packages.agenix - self'.packages.attic-client - # TODO: Contribute darwin support to nh - pkgs.nh - ]; - }; + devShells = builtins.mapAttrs (_: shell: shell.result.${system}) nilla.shells; packages = { # Re-export it for convenience and for caching diff --git a/nilla.nix b/nilla.nix index 48729f7..eb7bf6c 100644 --- a/nilla.nix +++ b/nilla.nix @@ -2,7 +2,7 @@ inputs ? import ./inputs.nix, }: (import inputs.nilla).create ( - { lib }: + { config, lib }: { config.inputs = builtins.mapAttrs (_: src: { inherit src; @@ -20,17 +20,87 @@ build = pkg: lib.attrs.generate pkg.systems ( - system: inputs.nixpkgs.legacyPackages.${system}.callPackage pkg.package pkg.settings.args + system: + inputs.nixpkgs.legacyPackages.${system}.callPackage pkg.package ( + { + self' = builtins.mapAttrs (_: pkg: pkg.result.${system}) config.packages; + } + // pkg.settings.args + ) ); }; + config.builders.custom-load = { + settings.type = lib.types.submodule { + options.args = lib.options.create { + type = lib.types.null; + default.value = null; + }; + }; + settings.default = { }; + build = pkg: lib.attrs.generate pkg.systems (system: pkg.package { inherit system; }); + }; + + config.packages = + let + systems = [ + "x86_64-linux" + "aarch64-linux" + "aarch64-darwin" + ]; + mkPackage = package: { + builder = "nixpkgs-flake"; + inherit systems package; + }; + mkPackageFlakeOutput = + { + input, + output ? input, + }: + { + inherit systems; + builder = "custom-load"; + package = { system }: inputs.${input}.packages.${system}.${output}; + }; + in + { + attic-client = mkPackageFlakeOutput { + input = "attic"; + output = "attic-client"; + }; + attic-server = mkPackageFlakeOutput { + input = "attic"; + output = "attic-server"; + }; + agenix = mkPackageFlakeOutput { input = "agenix"; }; + base-packages = mkPackage ( + { symlinkJoin }: + symlinkJoin { + name = "settei-base"; + paths = [ ]; + } + ); + }; + config.shells.default = { - systems = [ "x86_64-linux" ]; + systems = [ + "x86_64-linux" + "aarch64-linux" + "aarch64-darwin" + ]; builder = "nixpkgs-flake"; shell = - { mkShell, hello }: - mkShell { - packages = [ hello ]; + { + mkShellNoCC, + nh, + self', + }: + mkShellNoCC { + packages = [ + self'.agenix + self'.attic-client + nh + ]; }; }; } From 7bcd83937886e9f17e87dbb0ded52fb34449ba0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikodem=20Rabuli=C5=84ski?= Date: Sun, 23 Mar 2025 12:58:53 +0100 Subject: [PATCH 03/13] nilla: modularize --- modules/nilla/builders/custom-load.nix | 13 +++++++++ modules/nilla/builders/default.nix | 6 +++++ modules/nilla/builders/nixpkgs-flake.nix | 26 ++++++++++++++++++ modules/nilla/default.nix | 3 +++ nilla.nix | 34 ++---------------------- 5 files changed, 50 insertions(+), 32 deletions(-) create mode 100644 modules/nilla/builders/custom-load.nix create mode 100644 modules/nilla/builders/default.nix create mode 100644 modules/nilla/builders/nixpkgs-flake.nix create mode 100644 modules/nilla/default.nix diff --git a/modules/nilla/builders/custom-load.nix b/modules/nilla/builders/custom-load.nix new file mode 100644 index 0000000..b89bc36 --- /dev/null +++ b/modules/nilla/builders/custom-load.nix @@ -0,0 +1,13 @@ +{ lib }: +{ + config.builders.custom-load = { + settings.type = lib.types.submodule { + options.args = lib.options.create { + type = lib.types.null; + default.value = null; + }; + }; + settings.default = { }; + build = pkg: lib.attrs.generate pkg.systems (system: pkg.package { inherit system; }); + }; +} diff --git a/modules/nilla/builders/default.nix b/modules/nilla/builders/default.nix new file mode 100644 index 0000000..fa73437 --- /dev/null +++ b/modules/nilla/builders/default.nix @@ -0,0 +1,6 @@ +{ + includes = [ + ./nixpkgs-flake.nix + ./custom-load.nix + ]; +} diff --git a/modules/nilla/builders/nixpkgs-flake.nix b/modules/nilla/builders/nixpkgs-flake.nix new file mode 100644 index 0000000..a57b0e7 --- /dev/null +++ b/modules/nilla/builders/nixpkgs-flake.nix @@ -0,0 +1,26 @@ +{ + config, + lib, +}: +{ + config.builders.nixpkgs-flake = { + settings.type = lib.types.submodule { + options.args = lib.options.create { + type = lib.types.any; + default.value = { }; + }; + }; + settings.default = { }; + build = + pkg: + lib.attrs.generate pkg.systems ( + system: + config.inputs.nixpkgs.result.legacyPackages.${system}.callPackage pkg.package ( + { + self' = builtins.mapAttrs (_: pkg: pkg.result.${system}) config.packages; + } + // pkg.settings.args + ) + ); + }; +} diff --git a/modules/nilla/default.nix b/modules/nilla/default.nix new file mode 100644 index 0000000..f9e4319 --- /dev/null +++ b/modules/nilla/default.nix @@ -0,0 +1,3 @@ +{ + includes = [ ./builders ]; +} diff --git a/nilla.nix b/nilla.nix index eb7bf6c..7fa2127 100644 --- a/nilla.nix +++ b/nilla.nix @@ -4,43 +4,13 @@ (import inputs.nilla).create ( { config, lib }: { + includes = [ ./modules/nilla ]; + config.inputs = builtins.mapAttrs (_: src: { inherit src; loader = "raw"; }) inputs; - config.builders.nixpkgs-flake = { - settings.type = lib.types.submodule { - options.args = lib.options.create { - type = lib.types.any; - default.value = { }; - }; - }; - settings.default = { }; - build = - pkg: - lib.attrs.generate pkg.systems ( - system: - inputs.nixpkgs.legacyPackages.${system}.callPackage pkg.package ( - { - self' = builtins.mapAttrs (_: pkg: pkg.result.${system}) config.packages; - } - // pkg.settings.args - ) - ); - }; - - config.builders.custom-load = { - settings.type = lib.types.submodule { - options.args = lib.options.create { - type = lib.types.null; - default.value = null; - }; - }; - settings.default = { }; - build = pkg: lib.attrs.generate pkg.systems (system: pkg.package { inherit system; }); - }; - config.packages = let systems = [ From 5d5fcac95ab23f9dd30a636256040a8b7149a30c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikodem=20Rabuli=C5=84ski?= Date: Sun, 23 Mar 2025 12:59:03 +0100 Subject: [PATCH 04/13] flake: start moving away from flake-parts --- flake.nix | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 93b8f6a..2b3dd08 100644 --- a/flake.nix +++ b/flake.nix @@ -3,6 +3,23 @@ inputs@{ flake-parts, ... }: let nilla = import ./nilla.nix { inherit inputs; }; + transpose = + attrs: + let + inherit (inputs.nixpkgs) lib; + # maps an attrset of systems to packages to list of [ {name; system; value;} ] + pkgToListAll = + name: pkg: + map (system: { + inherit name system; + value = pkg.${system}; + }) (builtins.attrNames pkg); + pkgsToListAll = pkgs: map (name: pkgToListAll name pkgs.${name}) (builtins.attrNames pkgs); + # list of all packages in format [ {name; system; value;} ] + allPkgs = lib.flatten (pkgsToListAll attrs); + systems = builtins.groupBy (pkg: pkg.system) allPkgs; + in + builtins.mapAttrs (_: pkgs: lib.listToAttrs pkgs) systems; in flake-parts.lib.mkFlake { inherit inputs; } { systems = [ @@ -22,17 +39,16 @@ ./services ]; + flake.devShells = transpose (builtins.mapAttrs (_: shell: shell.result) nilla.shells); + perSystem = { inputs', self', pkgs, - system, ... }: { - devShells = builtins.mapAttrs (_: shell: shell.result.${system}) nilla.shells; - packages = { # Re-export it for convenience and for caching inherit (inputs'.attic.packages) attic-client attic-server; From 7c0f0ac90efc73f346d6fbeeb5e392cd85b593cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikodem=20Rabuli=C5=84ski?= Date: Sun, 23 Mar 2025 13:17:56 +0100 Subject: [PATCH 05/13] pkgs: migrate to nilla --- flake.nix | 59 ++++++----------- modules/nilla/builders/nixpkgs-flake.nix | 7 +- nilla.nix | 23 +++++-- pkgs/conduit/default.nix | 6 +- pkgs/default.nix | 81 ++++++++++++++---------- 5 files changed, 90 insertions(+), 86 deletions(-) diff --git a/flake.nix b/flake.nix index 2b3dd08..210a0f3 100644 --- a/flake.nix +++ b/flake.nix @@ -35,53 +35,32 @@ ./hosts ./modules ./wrappers - ./pkgs ./services ]; flake.devShells = transpose (builtins.mapAttrs (_: shell: shell.result) nilla.shells); + flake.packages = transpose (builtins.mapAttrs (_: pkg: pkg.result) nilla.packages); - perSystem = - { - inputs', - self', - pkgs, - ... - }: - { - packages = { - # Re-export it for convenience and for caching - inherit (inputs'.attic.packages) attic-client attic-server; - base-packages = pkgs.symlinkJoin { - name = "settei-base"; - paths = with self'.packages; [ - helix - fish - git-commit-last - git-fixup - ]; - }; - }; + perSystem = { + treefmt = { + programs.deadnix.enable = true; + programs.nixfmt.enable = true; + programs.statix.enable = true; + programs.fish_indent.enable = true; + programs.deno.enable = true; + programs.stylua.enable = true; + programs.shfmt.enable = true; + settings.global.excludes = [ + # agenix + "*.age" - treefmt = { - programs.deadnix.enable = true; - programs.nixfmt.enable = true; - programs.statix.enable = true; - programs.fish_indent.enable = true; - programs.deno.enable = true; - programs.stylua.enable = true; - programs.shfmt.enable = true; - settings.global.excludes = [ - # agenix - "*.age" - - # racket - "*.rkt" - "**/rashrc" - ]; - settings.on-unmatched = "fatal"; - }; + # racket + "*.rkt" + "**/rashrc" + ]; + settings.on-unmatched = "fatal"; }; + }; }; inputs = { diff --git a/modules/nilla/builders/nixpkgs-flake.nix b/modules/nilla/builders/nixpkgs-flake.nix index a57b0e7..4b0115f 100644 --- a/modules/nilla/builders/nixpkgs-flake.nix +++ b/modules/nilla/builders/nixpkgs-flake.nix @@ -15,12 +15,7 @@ pkg: lib.attrs.generate pkg.systems ( system: - config.inputs.nixpkgs.result.legacyPackages.${system}.callPackage pkg.package ( - { - self' = builtins.mapAttrs (_: pkg: pkg.result.${system}) config.packages; - } - // pkg.settings.args - ) + config.inputs.nixpkgs.result.legacyPackages.${system}.callPackage pkg.package pkg.settings.args ); }; } diff --git a/nilla.nix b/nilla.nix index 7fa2127..7a72441 100644 --- a/nilla.nix +++ b/nilla.nix @@ -4,7 +4,10 @@ (import inputs.nilla).create ( { config, lib }: { - includes = [ ./modules/nilla ]; + includes = [ + ./modules/nilla + ./pkgs + ]; config.inputs = builtins.mapAttrs (_: src: { inherit src; @@ -32,8 +35,10 @@ builder = "custom-load"; package = { system }: inputs.${input}.packages.${system}.${output}; }; + getPkgs = system: builtins.mapAttrs (_: pkg: pkg.result.${system}) config.packages; in { + # Re-export for convenience and for caching attic-client = mkPackageFlakeOutput { input = "attic"; output = "attic-client"; @@ -44,10 +49,16 @@ }; agenix = mkPackageFlakeOutput { input = "agenix"; }; base-packages = mkPackage ( - { symlinkJoin }: + { symlinkJoin, system }: symlinkJoin { name = "settei-base"; - paths = [ ]; + paths = with (getPkgs system); [ + # TODO: wrappers + # helix + # fish + git-commit-last + git-fixup + ]; } ); }; @@ -62,13 +73,13 @@ shell = { mkShellNoCC, + system, nh, - self', }: mkShellNoCC { packages = [ - self'.agenix - self'.attic-client + config.packages.agenix.result.${system} + config.packages.attic-client.result.${system} nh ]; }; diff --git a/pkgs/conduit/default.nix b/pkgs/conduit/default.nix index c2c44b4..2f1ccdd 100644 --- a/pkgs/conduit/default.nix +++ b/pkgs/conduit/default.nix @@ -1,6 +1,8 @@ { lib, stdenv, + pkgs, + system, fenix, crane, src, @@ -11,12 +13,12 @@ }: let rust = - with fenix; + with fenix.${system}; combine [ stable.cargo stable.rustc ]; - crane' = crane.overrideToolchain rust; + crane' = (crane pkgs).overrideToolchain rust; rocksdb' = rocksdb.overrideAttrs ( final: prev: { version = "9.1.1"; diff --git a/pkgs/default.nix b/pkgs/default.nix index 71a2d48..395dc2c 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -1,35 +1,52 @@ -{ inputs, ... }: +let + systems = [ + "x86_64-linux" + "aarch64-linux" + "aarch64-darwin" + ]; + builder = "nixpkgs-flake"; + mkPackage = package: { + inherit systems package builder; + }; + +in +{ config }: { - perSystem = - { - pkgs, - lib, - inputs', - ... - }: - { - packages.conduit-next = pkgs.callPackage ./conduit { - src = inputs.conduit-src; - crane = inputs.crane.mkLib pkgs; - fenix = inputs'.fenix.packages; - }; - - packages.git-commit-last = pkgs.writeShellApplication { - name = "git-commit-last"; - text = '' - GITDIR="$(git rev-parse --git-dir)" - git commit -eF "$GITDIR/COMMIT_EDITMSG" - ''; - }; - - packages.git-fixup = pkgs.writeShellApplication { - name = "git-fixup"; - text = '' - git log -n 50 --pretty=format:'%h %s' --no-merges | \ - ${lib.getExe pkgs.fzf} | \ - cut -c -7 | \ - xargs -o git commit --fixup - ''; - }; + config.packages.conduit-next = { + inherit systems builder; + package = import ./conduit; + settings.args = { + src = config.inputs.conduit-src.result; + crane = config.inputs.crane.result.mkLib; + fenix = config.inputs.fenix.result.packages; }; + }; + + config.packages.git-commit-last = mkPackage ( + { writeShellApplication }: + writeShellApplication { + name = "git-commit-last"; + text = '' + GITDIR="$(git rev-parse --git-dir)" + git commit -eF "$GITDIR/COMMIT_EDITMSG" + ''; + } + ); + + config.packages.git-fixup = mkPackage ( + { + lib, + writeShellApplication, + fzf, + }: + writeShellApplication { + name = "git-fixup"; + text = '' + git log -n 50 --pretty=format:'%h %s' --no-merges | \ + ${lib.getExe fzf} | \ + cut -c -7 | \ + xargs -o git commit --fixup + ''; + } + ); } From 265fba390834b131743b1c673d7d75257db3cb11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikodem=20Rabuli=C5=84ski?= Date: Sun, 23 Mar 2025 13:35:24 +0100 Subject: [PATCH 06/13] wrappers: migrate to nilla --- flake.nix | 1 - nilla.nix | 1 + pkgs/default.nix | 2 +- wrappers/default.nix | 53 +++++++++++++++++++++----------------- wrappers/helix/default.nix | 4 +-- wrappers/rash/default.nix | 4 +-- 6 files changed, 36 insertions(+), 29 deletions(-) diff --git a/flake.nix b/flake.nix index 210a0f3..30729a5 100644 --- a/flake.nix +++ b/flake.nix @@ -34,7 +34,6 @@ ./assets ./hosts ./modules - ./wrappers ./services ]; diff --git a/nilla.nix b/nilla.nix index 7a72441..302900a 100644 --- a/nilla.nix +++ b/nilla.nix @@ -7,6 +7,7 @@ includes = [ ./modules/nilla ./pkgs + ./wrappers ]; config.inputs = builtins.mapAttrs (_: src: { diff --git a/pkgs/default.nix b/pkgs/default.nix index 395dc2c..f5009d6 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -1,3 +1,4 @@ +{ config }: let systems = [ "x86_64-linux" @@ -10,7 +11,6 @@ let }; in -{ config }: { config.packages.conduit-next = { inherit systems builder; diff --git a/wrappers/default.nix b/wrappers/default.nix index 95040ca..7701749 100644 --- a/wrappers/default.nix +++ b/wrappers/default.nix @@ -1,25 +1,32 @@ -{ inputs, ... }: +{ lib, config }: +let + systems = [ + "x86_64-linux" + "aarch64-linux" + "aarch64-darwin" + ]; + wrappedPerSystem = lib.attrs.generate systems ( + system: + config.inputs.wrapper-manager-hm-compat.result.lib { + pkgs = config.inputs.nixpkgs.result.legacyPackages.${system}; + modules = [ + ./starship + ./helix + # TODO: Enable again + # ./rash + ./fish + ./wezterm + ]; + specialArgs.inputs = builtins.mapAttrs (_: input: input.result) config.inputs; + } + ); + wrappedPerSystem' = builtins.mapAttrs (_: wrapped: wrapped.config.build.packages) wrappedPerSystem; + wrapperNames = builtins.attrNames wrappedPerSystem'."x86_64-linux"; +in { - perSystem = - { pkgs, inputs', ... }: - let - wrapped = inputs.wrapper-manager-hm-compat.lib { - inherit pkgs; - modules = [ - ./starship - ./helix - # TODO: Enable again - # ./rash - ./fish - ./wezterm - ]; - specialArgs = { - inherit inputs inputs'; - }; - }; - all-packages = wrapped.config.build.packages; - in - { - packages = all-packages; - }; + config.packages = lib.attrs.generate wrapperNames (wrapper: { + inherit systems; + builder = "custom-load"; + package = { system }: wrappedPerSystem'.${system}.${wrapper}; + }); } diff --git a/wrappers/helix/default.nix b/wrappers/helix/default.nix index 8bd476d..6703955 100644 --- a/wrappers/helix/default.nix +++ b/wrappers/helix/default.nix @@ -1,8 +1,8 @@ -{ pkgs, inputs', ... }: +{ pkgs, inputs, ... }: { programs.helix = { enable = true; - package = inputs'.helix.packages.default; + package = inputs.helix.packages.${pkgs.system}.default; settings = { theme = "base16_default_dark"; editor = { diff --git a/wrappers/rash/default.nix b/wrappers/rash/default.nix index c142a0e..64c026c 100644 --- a/wrappers/rash/default.nix +++ b/wrappers/rash/default.nix @@ -1,6 +1,6 @@ { pkgs, - inputs', + inputs, config, ... }: @@ -13,7 +13,7 @@ rev = "8eb52c163d6ea7c3cec2cc6b1011ce00738942e1"; hash = "sha256-1yU0ZUBQqYEn85j4T2pLs02MTyJnO5BbYALIa88iomY="; }; - racket-with-libs = inputs'.racket.packages.racket.newLayer { + racket-with-libs = inputs.racket.packages.${pkgs.system}.racket.newLayer { withRacketPackages = ps: with ps; [ readline-gpl From e92e8c287d286ad5286c20208623ab1c24b0b1a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikodem=20Rabuli=C5=84ski?= Date: Sun, 23 Mar 2025 20:58:02 +0100 Subject: [PATCH 07/13] treefmt: migrate to nilla --- flake.nix | 24 +----------------------- modules/nilla/builders/custom-load.nix | 7 +------ nilla.nix | 14 ++++++++++++-- treefmt.nix | 19 +++++++++++++++++++ 4 files changed, 33 insertions(+), 31 deletions(-) create mode 100644 treefmt.nix diff --git a/flake.nix b/flake.nix index 30729a5..5a7791b 100644 --- a/flake.nix +++ b/flake.nix @@ -29,8 +29,6 @@ ]; imports = [ - inputs.treefmt.flakeModule - ./assets ./hosts ./modules @@ -39,27 +37,7 @@ flake.devShells = transpose (builtins.mapAttrs (_: shell: shell.result) nilla.shells); flake.packages = transpose (builtins.mapAttrs (_: pkg: pkg.result) nilla.packages); - - perSystem = { - treefmt = { - programs.deadnix.enable = true; - programs.nixfmt.enable = true; - programs.statix.enable = true; - programs.fish_indent.enable = true; - programs.deno.enable = true; - programs.stylua.enable = true; - programs.shfmt.enable = true; - settings.global.excludes = [ - # agenix - "*.age" - - # racket - "*.rkt" - "**/rashrc" - ]; - settings.on-unmatched = "fatal"; - }; - }; + flake.formatter = nilla.packages.formatter.result; }; inputs = { diff --git a/modules/nilla/builders/custom-load.nix b/modules/nilla/builders/custom-load.nix index b89bc36..b340dec 100644 --- a/modules/nilla/builders/custom-load.nix +++ b/modules/nilla/builders/custom-load.nix @@ -1,12 +1,7 @@ { lib }: { config.builders.custom-load = { - settings.type = lib.types.submodule { - options.args = lib.options.create { - type = lib.types.null; - default.value = null; - }; - }; + settings.type = lib.types.submodule { }; settings.default = { }; build = pkg: lib.attrs.generate pkg.systems (system: pkg.package { inherit system; }); }; diff --git a/nilla.nix b/nilla.nix index 302900a..39a75a2 100644 --- a/nilla.nix +++ b/nilla.nix @@ -55,13 +55,23 @@ name = "settei-base"; paths = with (getPkgs system); [ # TODO: wrappers - # helix - # fish + helix + fish git-commit-last git-fixup ]; } ); + formatter = { + inherit systems; + builder = "custom-load"; + package = + { system }: + let + eval = inputs.treefmt.lib.evalModule inputs.nixpkgs.legacyPackages.${system} ./treefmt.nix; + in + eval.config.build.wrapper; + }; }; config.shells.default = { diff --git a/treefmt.nix b/treefmt.nix new file mode 100644 index 0000000..e033626 --- /dev/null +++ b/treefmt.nix @@ -0,0 +1,19 @@ +{ + projectRootFile = "nilla.nix"; + programs.deadnix.enable = true; + programs.nixfmt.enable = true; + programs.statix.enable = true; + programs.fish_indent.enable = true; + programs.deno.enable = true; + programs.stylua.enable = true; + programs.shfmt.enable = true; + settings.global.excludes = [ + # agenix + "*.age" + + # racket + "*.rkt" + "**/rashrc" + ]; + settings.on-unmatched = "fatal"; +} From 7445304b4b02bb50adfb0338e943920a550be806 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikodem=20Rabuli=C5=84ski?= Date: Sun, 23 Mar 2025 21:14:39 +0100 Subject: [PATCH 08/13] flake: simplify transpose logic --- flake.nix | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/flake.nix b/flake.nix index 5a7791b..e6caf67 100644 --- a/flake.nix +++ b/flake.nix @@ -3,31 +3,23 @@ inputs@{ flake-parts, ... }: let nilla = import ./nilla.nix { inherit inputs; }; - transpose = - attrs: - let - inherit (inputs.nixpkgs) lib; - # maps an attrset of systems to packages to list of [ {name; system; value;} ] - pkgToListAll = - name: pkg: - map (system: { - inherit name system; - value = pkg.${system}; - }) (builtins.attrNames pkg); - pkgsToListAll = pkgs: map (name: pkgToListAll name pkgs.${name}) (builtins.attrNames pkgs); - # list of all packages in format [ {name; system; value;} ] - allPkgs = lib.flatten (pkgsToListAll attrs); - systems = builtins.groupBy (pkg: pkg.system) allPkgs; - in - builtins.mapAttrs (_: pkgs: lib.listToAttrs pkgs) systems; - in - flake-parts.lib.mkFlake { inherit inputs; } { systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ]; - + # NOTE: Assumes every package is available for every system. + # For now let's say this is always the case. + transpose = + attrs: + let + inherit (inputs.nixpkgs) lib; + mappedForSystem = system: builtins.mapAttrs (_: pkg: pkg.result.${system}) attrs; + in + lib.genAttrs systems mappedForSystem; + in + flake-parts.lib.mkFlake { inherit inputs; } { + inherit systems; imports = [ ./assets ./hosts @@ -35,8 +27,8 @@ ./services ]; - flake.devShells = transpose (builtins.mapAttrs (_: shell: shell.result) nilla.shells); - flake.packages = transpose (builtins.mapAttrs (_: pkg: pkg.result) nilla.packages); + flake.devShells = transpose nilla.shells; + flake.packages = transpose nilla.packages; flake.formatter = nilla.packages.formatter.result; }; From c70c38c93f9bbd560fabcbcd058fd3164b4c0d1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikodem=20Rabuli=C5=84ski?= Date: Sun, 23 Mar 2025 22:02:20 +0100 Subject: [PATCH 09/13] services: prepare for migration --- modules/flake/services.nix | 8 ++++---- services/attic.nix | 4 ++-- services/forgejo-runner.nix | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/flake/services.nix b/modules/flake/services.nix index f2f07d4..697b701 100644 --- a/modules/flake/services.nix +++ b/modules/flake/services.nix @@ -21,11 +21,11 @@ let type = with lib.types; listOf str; default = [ config.host ]; }; - config = lib.mkOption { + module = lib.mkOption { type = lib.types.deferredModule; default = { }; }; - hostConfig = lib.mkOption { + hostModule = lib.mkOption { type = with lib.types; attrsOf deferredModule; default = { }; }; @@ -36,8 +36,8 @@ let cfg: lib.genAttrs cfg.hosts (host: { imports = [ - cfg.config - (cfg.hostConfig.${host} or { }) + cfg.module + (cfg.hostModule.${host} or { }) ]; }); diff --git a/services/attic.nix b/services/attic.nix index 91d675f..f9d7501 100644 --- a/services/attic.nix +++ b/services/attic.nix @@ -1,12 +1,12 @@ { - services.attic = + config.services.attic = let atticPort = 9476; in { host = "kazuki"; ports = [ atticPort ]; - config = + module = { config, ... }: { age.secrets.attic-creds = { diff --git a/services/forgejo-runner.nix b/services/forgejo-runner.nix index 693d1d1..98574a1 100644 --- a/services/forgejo-runner.nix +++ b/services/forgejo-runner.nix @@ -1,10 +1,10 @@ { - services.forgejo-runner = { + config.services.forgejo-runner = { hosts = [ "ude" "youko" ]; - config = + module = { config, lib, From ddcf878b92c4e01f08c9b7af1d32e19045f8b429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikodem=20Rabuli=C5=84ski?= Date: Sun, 23 Mar 2025 22:02:59 +0100 Subject: [PATCH 10/13] services: migrate to nilla --- modules/nilla/default.nix | 5 +- modules/nilla/services.nix | 95 ++++++++++++++++++++++++++++++++++++++ nilla.nix | 3 ++ 3 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 modules/nilla/services.nix diff --git a/modules/nilla/default.nix b/modules/nilla/default.nix index f9e4319..6f39646 100644 --- a/modules/nilla/default.nix +++ b/modules/nilla/default.nix @@ -1,3 +1,6 @@ { - includes = [ ./builders ]; + includes = [ + ./builders + ./services.nix + ]; } diff --git a/modules/nilla/services.nix b/modules/nilla/services.nix new file mode 100644 index 0000000..1b72eaf --- /dev/null +++ b/modules/nilla/services.nix @@ -0,0 +1,95 @@ +{ lib, config }: +let + inherit (builtins) + attrNames + attrValues + concatStringsSep + mapAttrs + foldl' + groupBy + length + ; + serviceModule = + { config }: + { + options = { + host = lib.options.create { + type = lib.types.str; + }; + ports = lib.options.create { + type = lib.types.list.of lib.types.port; + default.value = [ ]; + }; + hosts = lib.options.create { + type = lib.types.list.of lib.types.str; + default.value = [ config.host ]; + }; + module = lib.options.create { + type = lib.types.raw; + default.value = { }; + }; + hostModule = lib.options.create { + type = lib.types.attrs.of lib.types.raw; + default.value = { }; + }; + }; + }; + + moduleToHostConfigs = + cfg: + lib.attrs.generate cfg.hosts (host: { + imports = [ + cfg.module + (cfg.hostModule.${host} or { }) + ]; + }); + + maybeGetPreviousConfigs = acc: host: (acc.${host} or { imports = [ ]; }).imports; + + # Copied from nixpkgs/lib/lists.nix + groupBy' = + op: nul: pred: lst: + mapAttrs (_name: foldl' op nul) (groupBy pred lst); + duplicatePorts = lib.fp.pipe [ + attrValues + (map (cfg: cfg.ports)) + lib.lists.flatten + (groupBy' (cnt: _: cnt + 1) 0 toString) + (lib.attrs.filter (_: cnt: cnt > 1)) + attrNames + ] config.services; +in +{ + options.services = lib.options.create { + type = lib.types.attrs.of (lib.types.submodule serviceModule); + default.value = { }; + }; + + options.extraHostConfigs = lib.options.create { + type = lib.types.attrs.of lib.types.raw; + writable = false; + default.value = lib.fp.pipe [ + attrValues + (foldl' ( + acc: cfg: + acc + // mapAttrs (host: c: { + imports = c.imports ++ (maybeGetPreviousConfigs acc host); + }) (moduleToHostConfigs cfg) + ) { }) + ] config.services; + }; + + config.assertions = [ + { + assertion = duplicatePorts == [ ]; + message = + let + plural = length duplicatePorts > 1; + in + "\nBad service config:\nThe following port${if plural then "s" else ""} ${ + if plural then "were" else "was" + } declared multiple times: ${concatStringsSep ", " duplicatePorts}"; + } + ]; +} diff --git a/nilla.nix b/nilla.nix index 39a75a2..5022b91 100644 --- a/nilla.nix +++ b/nilla.nix @@ -8,6 +8,9 @@ ./modules/nilla ./pkgs ./wrappers + + ./services/attic.nix + ./services/forgejo-runner.nix ]; config.inputs = builtins.mapAttrs (_: src: { From b988839a7099235675cbf76cccc01cb04d85fb63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikodem=20Rabuli=C5=84ski?= Date: Sun, 23 Mar 2025 22:46:55 +0100 Subject: [PATCH 11/13] hosts: migrate to nilla --- assets/default.nix | 8 +-- flake.nix | 6 +- hosts/default.nix | 20 +++---- hosts/hijiri-vm/default.nix | 2 +- hosts/hijiri/default.nix | 2 +- hosts/installer/default.nix | 2 +- hosts/kazuki/default.nix | 2 +- hosts/kogata/default.nix | 2 +- hosts/legion/default.nix | 2 +- hosts/ude/default.nix | 2 +- hosts/youko/default.nix | 2 +- modules/default.nix | 12 ---- modules/flake/configurations.nix | 54 ------------------ modules/flake/default.nix | 13 ----- modules/flake/services.nix | 95 -------------------------------- modules/nilla/configurations.nix | 47 ++++++++++++++++ modules/nilla/default.nix | 1 + modules/nilla/services.nix | 4 +- nilla.nix | 6 +- services/default.nix | 2 +- 20 files changed, 79 insertions(+), 205 deletions(-) delete mode 100644 modules/flake/configurations.nix delete mode 100644 modules/flake/default.nix delete mode 100644 modules/flake/services.nix create mode 100644 modules/nilla/configurations.nix diff --git a/assets/default.nix b/assets/default.nix index 123d12c..4e3187c 100644 --- a/assets/default.nix +++ b/assets/default.nix @@ -1,8 +1,8 @@ -{ lib, ... }: +{ lib }: { - options.assets = lib.mkOption { - type = lib.types.unspecified; - readOnly = true; + options.assets = lib.options.create { + type = lib.types.raw; + writable = false; }; config.assets = { diff --git a/flake.nix b/flake.nix index e6caf67..0a35908 100644 --- a/flake.nix +++ b/flake.nix @@ -21,12 +21,12 @@ flake-parts.lib.mkFlake { inherit inputs; } { inherit systems; imports = [ - ./assets - ./hosts ./modules - ./services ]; + flake.nixosConfigurations = nilla.nixosConfigurations; + flake.darwinConfigurations = nilla.darwinConfigurations; + flake.homeConfigurations = nilla.homeConfigurations; flake.devShells = transpose nilla.shells; flake.packages = transpose nilla.packages; flake.formatter = nilla.packages.formatter.result; diff --git a/hosts/default.nix b/hosts/default.nix index 03d464d..5fd901d 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -1,11 +1,11 @@ { config, - self, - inputs, - ... }: +let + inputs = builtins.mapAttrs (_: input: input.result) config.inputs; +in { - imports = [ + includes = [ ./kazuki ./hijiri-vm ./hijiri @@ -17,20 +17,20 @@ ./youko ]; - builders = + config.configBuilders = let sharedOptions = { _file = ./default.nix; settei.sane-defaults.allSshKeys = config.assets.sshKeys.user; settei.flake-qol.inputs = inputs // { - settei = self; + settei = inputs.self; }; }; baseNixos = inputs.nixpkgs.lib.nixosSystem { modules = [ - self.nixosModules.combined + inputs.self.nixosModules.combined sharedOptions ]; specialArgs.configurationName = "base"; @@ -38,7 +38,7 @@ baseDarwin = inputs.darwin.lib.darwinSystem { modules = [ - self.darwinModules.combined + inputs.self.darwinModules.combined sharedOptions ]; specialArgs.configurationName = "base"; @@ -50,7 +50,7 @@ baseNixos.extendModules { modules = [ module - config.__extraHostConfigs.${name} or { } + config.extraHostConfigs.${name} or { } ]; specialArgs.configurationName = name; }; @@ -61,7 +61,7 @@ eval = baseDarwin._module.args.extendModules { modules = [ module - config.__extraHostConfigs.${name} or { } + config.extraHostConfigs.${name} or { } ]; specialArgs.configurationName = name; }; diff --git a/hosts/hijiri-vm/default.nix b/hosts/hijiri-vm/default.nix index db26c63..5f6d088 100644 --- a/hosts/hijiri-vm/default.nix +++ b/hosts/hijiri-vm/default.nix @@ -1,5 +1,5 @@ { - configurations.nixos.hijiri-vm = + config.configurations.nixos.hijiri-vm = { modulesPath, lib, diff --git a/hosts/hijiri/default.nix b/hosts/hijiri/default.nix index bb7db92..a0e6857 100644 --- a/hosts/hijiri/default.nix +++ b/hosts/hijiri/default.nix @@ -1,5 +1,5 @@ { - configurations.darwin.hijiri = + config.configurations.darwin.hijiri = { config, pkgs, diff --git a/hosts/installer/default.nix b/hosts/installer/default.nix index 24bdef8..a1692c6 100644 --- a/hosts/installer/default.nix +++ b/hosts/installer/default.nix @@ -1,6 +1,6 @@ { lib, ... }: { - configurations.nixos = + config.configurations.nixos = let mkInstaller = system: diff --git a/hosts/kazuki/default.nix b/hosts/kazuki/default.nix index df92f1c..029d7d0 100644 --- a/hosts/kazuki/default.nix +++ b/hosts/kazuki/default.nix @@ -1,5 +1,5 @@ { - configurations.nixos.kazuki = + config.configurations.nixos.kazuki = { modulesPath, ... diff --git a/hosts/kogata/default.nix b/hosts/kogata/default.nix index 6bf9e2f..3e7c21f 100644 --- a/hosts/kogata/default.nix +++ b/hosts/kogata/default.nix @@ -1,5 +1,5 @@ { - configurations.darwin.kogata = + config.configurations.darwin.kogata = { pkgs, ... }: { nixpkgs.system = "aarch64-darwin"; diff --git a/hosts/legion/default.nix b/hosts/legion/default.nix index 92c95be..1b41b1e 100644 --- a/hosts/legion/default.nix +++ b/hosts/legion/default.nix @@ -1,5 +1,5 @@ { - configurations.nixos.legion = + config.configurations.nixos.legion = { config, username, diff --git a/hosts/ude/default.nix b/hosts/ude/default.nix index d395fbd..fd3e19b 100644 --- a/hosts/ude/default.nix +++ b/hosts/ude/default.nix @@ -1,5 +1,5 @@ { - configurations.nixos.ude = + config.configurations.nixos.ude = { config, modulesPath, diff --git a/hosts/youko/default.nix b/hosts/youko/default.nix index 3a2fe49..b801507 100644 --- a/hosts/youko/default.nix +++ b/hosts/youko/default.nix @@ -1,5 +1,5 @@ { - configurations.nixos.youko = + config.configurations.nixos.youko = { config, lib, diff --git a/modules/default.nix b/modules/default.nix index 32f8e5f..b1a8e14 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -3,24 +3,12 @@ inputs, ... }: -let - flakeModule = import ./flake { inherit (inputs) nixpkgs darwin home-manager; }; -in { - imports = [ - flakeModule - ]; - flake.homeModules = rec { settei = ./home; default = settei; }; - flake.flakeModules = rec { - settei = flakeModule; - default = settei; - }; - flake.nixosModules = rec { settei = import ./system { inherit (config) perInput; diff --git a/modules/flake/configurations.nix b/modules/flake/configurations.nix deleted file mode 100644 index 67ccc1b..0000000 --- a/modules/flake/configurations.nix +++ /dev/null @@ -1,54 +0,0 @@ -{ - nixpkgs, - darwin, - home-manager, -}: -{ - config, - lib, - ... -}: -with lib; -{ - _file = ./configurations.nix; - - options = { - # Those functions take the final arguments and emit a valid configuration. - # Probably should hardly ever be overriden - builders = { - nixos = mkOption { - type = types.functionTo types.unspecified; - default = _name: nixpkgs.lib.nixosSystem; - }; - darwin = mkOption { - type = types.functionTo types.unspecified; - default = _name: darwin.lib.darwinSystem; - }; - home = mkOption { - type = types.functionTo types.unspecified; - default = _name: home-manager.lib.homeManagerConfiguration; - }; - }; - - configurations = { - nixos = mkOption { - type = types.lazyAttrsOf types.deferredModule; - default = { }; - }; - darwin = mkOption { - type = types.lazyAttrsOf types.deferredModule; - default = { }; - }; - home = mkOption { - type = types.lazyAttrsOf types.deferredModule; - default = { }; - }; - }; - }; - - config.flake = { - nixosConfigurations = mapAttrs config.builders.nixos config.configurations.nixos; - darwinConfigurations = mapAttrs config.builders.darwin config.configurations.darwin; - homeConfigurations = mapAttrs config.builders.home config.configurations.home; - }; -} diff --git a/modules/flake/default.nix b/modules/flake/default.nix deleted file mode 100644 index 78bb73d..0000000 --- a/modules/flake/default.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ - nixpkgs, - darwin, - home-manager, -}: -{ - _file = ./default.nix; - - imports = [ - (import ./configurations.nix { inherit nixpkgs darwin home-manager; }) - ./services.nix - ]; -} diff --git a/modules/flake/services.nix b/modules/flake/services.nix deleted file mode 100644 index 697b701..0000000 --- a/modules/flake/services.nix +++ /dev/null @@ -1,95 +0,0 @@ -# List of features I want this module to eventually have -# TODO: Automatic port allocation -# TODO: Making it possible to conveniently isolate services (running them in NixOS containers) -# TODO: Handling specializations -# TODO: Convenient http handling -# TODO: Automatic backup -{ config, lib, ... }: -let - serviceModule = - { config, ... }: - { - options = { - host = lib.mkOption { - type = lib.types.str; - }; - ports = lib.mkOption { - type = with lib.types; listOf port; - default = [ ]; - }; - hosts = lib.mkOption { - type = with lib.types; listOf str; - default = [ config.host ]; - }; - module = lib.mkOption { - type = lib.types.deferredModule; - default = { }; - }; - hostModule = lib.mkOption { - type = with lib.types; attrsOf deferredModule; - default = { }; - }; - }; - }; - - moduleToHostConfigs = - cfg: - lib.genAttrs cfg.hosts (host: { - imports = [ - cfg.module - (cfg.hostModule.${host} or { }) - ]; - }); - - maybeGetPreviousConfigs = acc: host: (acc.${host} or { imports = [ ]; }).imports; -in -{ - _file = ./services.nix; - - options = { - services = lib.mkOption { - type = with lib.types; attrsOf (submodule serviceModule); - default = { }; - }; - - __extraHostConfigs = lib.mkOption { - type = with lib.types; attrsOf deferredModule; - readOnly = true; - }; - }; - - config.__extraHostConfigs = - let - duplicatePorts = lib.pipe config.services [ - lib.attrValues - (map (cfg: cfg.ports)) - lib.flatten - (lib.groupBy' (cnt: _: cnt + 1) 0 toString) - (lib.filterAttrs (_: cnt: cnt > 1)) - lib.attrNames - ]; - assertMsg = - let - plural = lib.length duplicatePorts > 1; - in - "\nBad service config:\nThe following port${if plural then "s" else ""} ${ - if plural then "were" else "was" - } declared multiple times: ${lib.concatStringsSep ", " duplicatePorts}"; - # Here I collect all the services..config into a flat - # __extraHostConfigs..imports = [ - # ... - # ] - # so that I can easily import them in hosts/default.nix - hostConfigs = lib.pipe config.services [ - lib.attrValues - (lib.foldl' ( - acc: cfg: - acc - // lib.mapAttrs (host: c: { - imports = c.imports ++ (maybeGetPreviousConfigs acc host); - }) (moduleToHostConfigs cfg) - ) { }) - ]; - in - if duplicatePorts != [ ] then throw assertMsg else hostConfigs; -} diff --git a/modules/nilla/configurations.nix b/modules/nilla/configurations.nix new file mode 100644 index 0000000..6f02f7e --- /dev/null +++ b/modules/nilla/configurations.nix @@ -0,0 +1,47 @@ +{ config, lib }: +{ + options = { + configBuilders = { + nixos = lib.options.create { + type = lib.types.function lib.types.raw; + default.value = _name: config.inputs.nixpkgs.result.lib.nixosSystem; + }; + darwin = lib.options.create { + type = lib.types.function lib.types.raw; + default.value = _name: config.inputs.darwin.result.lib.darwinSystem; + }; + home = lib.options.create { + type = lib.types.function lib.types.raw; + default.value = _name: config.inputs.home-manager.result.lib.homeManagerConfiguration; + }; + }; + + configurations = { + nixos = lib.options.create { + type = lib.types.attrs.lazy lib.types.raw; + default.value = { }; + }; + darwin = lib.options.create { + type = lib.types.attrs.lazy lib.types.raw; + default.value = { }; + }; + home = lib.options.create { + type = lib.types.attrs.lazy lib.types.raw; + default.value = { }; + }; + }; + + nixosConfigurations = lib.options.create { + type = lib.types.attrs.lazy lib.types.raw; + default.value = builtins.mapAttrs config.configBuilders.nixos config.configurations.nixos; + }; + darwinConfigurations = lib.options.create { + type = lib.types.attrs.lazy lib.types.raw; + default.value = builtins.mapAttrs config.configBuilders.darwin config.configurations.darwin; + }; + homeConfigurations = lib.options.create { + type = lib.types.attrs.lazy lib.types.raw; + default.value = builtins.mapAttrs config.configBuilders.home config.configurations.home; + }; + }; +} diff --git a/modules/nilla/default.nix b/modules/nilla/default.nix index 6f39646..8a7dea6 100644 --- a/modules/nilla/default.nix +++ b/modules/nilla/default.nix @@ -2,5 +2,6 @@ includes = [ ./builders ./services.nix + ./configurations.nix ]; } diff --git a/modules/nilla/services.nix b/modules/nilla/services.nix index 1b72eaf..1045a4a 100644 --- a/modules/nilla/services.nix +++ b/modules/nilla/services.nix @@ -14,14 +14,14 @@ let { options = { host = lib.options.create { - type = lib.types.str; + type = lib.types.string; }; ports = lib.options.create { type = lib.types.list.of lib.types.port; default.value = [ ]; }; hosts = lib.options.create { - type = lib.types.list.of lib.types.str; + type = lib.types.list.of lib.types.string; default.value = [ config.host ]; }; module = lib.options.create { diff --git a/nilla.nix b/nilla.nix index 5022b91..eba8c90 100644 --- a/nilla.nix +++ b/nilla.nix @@ -8,9 +8,9 @@ ./modules/nilla ./pkgs ./wrappers - - ./services/attic.nix - ./services/forgejo-runner.nix + ./hosts + ./assets + ./services ]; config.inputs = builtins.mapAttrs (_: src: { diff --git a/services/default.nix b/services/default.nix index 1837462..c87f779 100644 --- a/services/default.nix +++ b/services/default.nix @@ -1,5 +1,5 @@ { - imports = [ + includes = [ ./attic.nix ./forgejo-runner.nix ]; From 292695805efd56e704c3e9357adb913e4ecd3c82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikodem=20Rabuli=C5=84ski?= Date: Sun, 23 Mar 2025 22:58:55 +0100 Subject: [PATCH 12/13] modules: migrate to nilla --- flake.nix | 6 +++--- hosts/default.nix | 4 ++-- modules/default.nix | 18 +++++++++++------- modules/nilla/default.nix | 1 + modules/nilla/modules.nix | 17 +++++++++++++++++ nilla.nix | 1 + 6 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 modules/nilla/modules.nix diff --git a/flake.nix b/flake.nix index 0a35908..d9cb6da 100644 --- a/flake.nix +++ b/flake.nix @@ -20,10 +20,10 @@ in flake-parts.lib.mkFlake { inherit inputs; } { inherit systems; - imports = [ - ./modules - ]; + flake.nixosModules = nilla.nixosModules; + flake.darwinModules = nilla.darwinModules; + flake.homeModules = nilla.homeModules; flake.nixosConfigurations = nilla.nixosConfigurations; flake.darwinConfigurations = nilla.darwinConfigurations; flake.homeConfigurations = nilla.homeConfigurations; diff --git a/hosts/default.nix b/hosts/default.nix index 5fd901d..ac91988 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -30,7 +30,7 @@ in baseNixos = inputs.nixpkgs.lib.nixosSystem { modules = [ - inputs.self.nixosModules.combined + config.nixosModules.combined sharedOptions ]; specialArgs.configurationName = "base"; @@ -38,7 +38,7 @@ in baseDarwin = inputs.darwin.lib.darwinSystem { modules = [ - inputs.self.darwinModules.combined + config.darwinModules.combined sharedOptions ]; specialArgs.configurationName = "base"; diff --git a/modules/default.nix b/modules/default.nix index b1a8e14..08dc44b 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -1,17 +1,21 @@ { config, - inputs, - ... }: +let + inputs = builtins.mapAttrs (_: input: input.result) config.inputs; + perInput = system: flake: { + packages = flake.packages.${system}; + }; +in { - flake.homeModules = rec { + config.homeModules = rec { settei = ./home; default = settei; }; - flake.nixosModules = rec { + config.nixosModules = rec { settei = import ./system { - inherit (config) perInput; + inherit perInput; isLinux = true; }; combined = { @@ -34,9 +38,9 @@ default = combined; }; - flake.darwinModules = rec { + config.darwinModules = rec { settei = import ./system { - inherit (config) perInput; + inherit perInput; isLinux = false; }; combined = { diff --git a/modules/nilla/default.nix b/modules/nilla/default.nix index 8a7dea6..bfcd452 100644 --- a/modules/nilla/default.nix +++ b/modules/nilla/default.nix @@ -3,5 +3,6 @@ ./builders ./services.nix ./configurations.nix + ./modules.nix ]; } diff --git a/modules/nilla/modules.nix b/modules/nilla/modules.nix new file mode 100644 index 0000000..7b8a6dc --- /dev/null +++ b/modules/nilla/modules.nix @@ -0,0 +1,17 @@ +{ lib }: +{ + options = { + nixosModules = lib.options.create { + type = lib.types.attrs.of lib.types.raw; + default.value = { }; + }; + darwinModules = lib.options.create { + type = lib.types.attrs.of lib.types.raw; + default.value = { }; + }; + homeModules = lib.options.create { + type = lib.types.attrs.of lib.types.raw; + default.value = { }; + }; + }; +} diff --git a/nilla.nix b/nilla.nix index eba8c90..bc20103 100644 --- a/nilla.nix +++ b/nilla.nix @@ -11,6 +11,7 @@ ./hosts ./assets ./services + ./modules ]; config.inputs = builtins.mapAttrs (_: src: { From 06a76ae98f2aaaad3f7090f88f4837cb274915c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikodem=20Rabuli=C5=84ski?= Date: Sun, 23 Mar 2025 23:02:23 +0100 Subject: [PATCH 13/13] flake: remove flake-parts --- flake.lock | 23 +---------------------- flake.nix | 28 +++++++++++----------------- 2 files changed, 12 insertions(+), 39 deletions(-) diff --git a/flake.lock b/flake.lock index d40edeb..a07e474 100644 --- a/flake.lock +++ b/flake.lock @@ -276,26 +276,6 @@ } }, "flake-parts_2": { - "inputs": { - "nixpkgs-lib": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1741352980, - "narHash": "sha256-+u2UunDA4Cl5Fci3m7S643HzKmIDAe+fiXrLqYsR2fs=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "f4330d22f1c5d2ba72d3d22df5597d123fdb60a9", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "flake-parts", - "type": "github" - } - }, - "flake-parts_3": { "inputs": { "nixpkgs-lib": "nixpkgs-lib" }, @@ -509,7 +489,7 @@ }, "niko-nur": { "inputs": { - "flake-parts": "flake-parts_3", + "flake-parts": "flake-parts_2", "nixpkgs": "nixpkgs" }, "locked": { @@ -722,7 +702,6 @@ "disko": "disko", "fenix": "fenix", "firefox-darwin": "firefox-darwin", - "flake-parts": "flake-parts_2", "helix": "helix", "home-manager": "home-manager", "lix": "lix", diff --git a/flake.nix b/flake.nix index d9cb6da..bf7d117 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,6 @@ { outputs = - inputs@{ flake-parts, ... }: + inputs: let nilla = import ./nilla.nix { inherit inputs; }; systems = [ @@ -18,26 +18,20 @@ in lib.genAttrs systems mappedForSystem; in - flake-parts.lib.mkFlake { inherit inputs; } { - inherit systems; - - flake.nixosModules = nilla.nixosModules; - flake.darwinModules = nilla.darwinModules; - flake.homeModules = nilla.homeModules; - flake.nixosConfigurations = nilla.nixosConfigurations; - flake.darwinConfigurations = nilla.darwinConfigurations; - flake.homeConfigurations = nilla.homeConfigurations; - flake.devShells = transpose nilla.shells; - flake.packages = transpose nilla.packages; - flake.formatter = nilla.packages.formatter.result; + { + inherit (nilla) nixosModules; + inherit (nilla) darwinModules; + inherit (nilla) homeModules; + inherit (nilla) nixosConfigurations; + inherit (nilla) darwinConfigurations; + inherit (nilla) homeConfigurations; + devShells = transpose nilla.shells; + packages = transpose nilla.packages; + formatter = nilla.packages.formatter.result; }; inputs = { nixpkgs.url = "github:nixos/nixpkgs?ref=nixpkgs-unstable"; - flake-parts = { - url = "github:hercules-ci/flake-parts"; - inputs.nixpkgs-lib.follows = "nixpkgs"; - }; disko = { url = "github:nix-community/disko"; inputs.nixpkgs.follows = "nixpkgs";