deduplicate

This commit is contained in:
Valentin Gagarin 2024-09-25 12:23:34 +02:00
parent cc3ccbc59a
commit 591dd87752
2 changed files with 39 additions and 111 deletions

View file

@ -1,23 +1,25 @@
let { inputs ? import ./npins
inputs = import ./npins; , system ? builtins.currentSystem
system = "x86_64-linux"; , pkgs ? import inputs.nixpkgs { config = { }; overlays = [ ]; inherit system; }
pkgs = import inputs.nixpkgs { config = { }; overlays = [ ]; system = builtins.currentSystem; }; , lib ? import "${inputs.nixpkgs}/lib"
lib = import "${inputs.nixpkgs}/lib" // { inherit nixosSystem; }; // {
nixosSystem = args: nixosSystem = args:
import "${inputs.nixpkgs}/nixos/lib/eval-config.nix" import "${inputs.nixpkgs}/nixos/lib/eval-config.nix"
( (
{ {
inherit lib; inherit lib;
# Allow system to be set modularly in nixpkgs.system. # Allow system to be set modularly in nixpkgs.system.
# We set it to null, to remove the "legacy" entrypoint's # We set it to null, to remove the "legacy" entrypoint's
# non-hermetic default. # non-hermetic default.
system = null; system = null;
modules = args.modules; modules = args.modules;
} }
// builtins.removeAttrs args [ "modules" ] // builtins.removeAttrs args [ "modules" ]
); );
in }
,
}:
rec { rec {
nixosModules = { nixosModules = {
disko = "${inputs.disko}/module.nix"; disko = "${inputs.disko}/module.nix";
@ -31,7 +33,7 @@ rec {
# test with # test with
# nix-build -A nixosConfigurations.<config>.installTest # nix-build -A nixosConfigurations.<config>.installTest
nixosConfigurations = { nixosConfigurations = {
mastodon = nixosSystem { mastodon = lib.nixosSystem {
inherit system; inherit system;
modules = with nixosModules; [ modules = with nixosModules; [
disko disko
@ -41,7 +43,7 @@ rec {
]; ];
}; };
peertube = nixosSystem { peertube = lib.nixosSystem {
inherit system; inherit system;
modules = with nixosModules; [ modules = with nixosModules; [
disko disko
@ -51,7 +53,7 @@ rec {
]; ];
}; };
pixelfed = nixosSystem { pixelfed = lib.nixosSystem {
inherit system; inherit system;
modules = with nixosModules; [ modules = with nixosModules; [
disko disko
@ -61,7 +63,7 @@ rec {
]; ];
}; };
all = nixosSystem { all = lib.nixosSystem {
inherit system; inherit system;
modules = with nixosModules; [ modules = with nixosModules; [
interactive-vm interactive-vm

102
flake.nix
View file

@ -6,99 +6,25 @@
disko.url = "github:nix-community/disko"; disko.url = "github:nix-community/disko";
}; };
outputs = { self, nixpkgs, disko, ... }: outputs = inputs@{ self, nixpkgs, disko, ... }:
let let
system = "x86_64-linux"; system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system}; default = import ./default.nix { inherit system inputs; };
in { in {
nixosModules = { inherit (default)
nixosModules
nixosConfigurations
# build with
# nix build .#installers.<config>
installers
# run with
# nix run .#deploy.<machine>
deploy
;
## Fediversity modules checks.${system} = default.tests;
fediversity = import ./fediversity;
## VM-specific modules devShells.${system}.default = default.shell;
inherit (disko.nixosModules) disko;
disk-layout = import ./vm/disk-layout.nix;
interactive-vm = import ./vm/interactive-vm.nix;
mastodon-vm = import ./vm/mastodon-vm.nix;
peertube-vm = import ./vm/peertube-vm.nix;
pixelfed-vm = import ./vm/pixelfed-vm.nix;
};
nixosConfigurations = {
mastodon = nixpkgs.lib.nixosSystem {
inherit system;
modules = with self.nixosModules; [
disko
disk-layout
fediversity
interactive-vm
mastodon-vm
];
};
peertube = nixpkgs.lib.nixosSystem {
inherit system;
modules = with self.nixosModules; [
disko
disk-layout
fediversity
interactive-vm
peertube-vm
];
};
pixelfed = nixpkgs.lib.nixosSystem {
inherit system;
modules = with self.nixosModules; [
disko
disk-layout
fediversity
interactive-vm
pixelfed-vm
];
};
all = nixpkgs.lib.nixosSystem {
inherit system;
modules = with self.nixosModules; [
disko
disk-layout
fediversity
interactive-vm
peertube-vm
pixelfed-vm
mastodon-vm
];
};
};
# build with
# nix build .#installers.<config>
installers =
let
installer = (import ./installer.nix) nixpkgs;
in
nixpkgs.lib.mapAttrs (_: config: installer config) self.nixosConfigurations;
# run with
# nix run .#deploy.<machine>
deploy =
let
deployCommand = (pkgs.callPackage ./deploy.nix {});
in
nixpkgs.lib.mapAttrs (name: config: deployCommand name config) self.nixosConfigurations;
checks.${system} = {
mastodon-garage = import ./tests/mastodon-garage.nix { inherit pkgs; };
pixelfed-garage = import ./tests/pixelfed-garage.nix { inherit pkgs; };
};
devShells.${system}.default = pkgs.mkShell {
packages = with pkgs; [
nil
];
};
}; };
} }