Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flake.parts module #269

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 150 additions & 0 deletions examples/simple-flake-parts/flake.lock

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

30 changes: 30 additions & 0 deletions examples/simple-flake-parts/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# SPDX-FileCopyrightText: 2024 Sefa Eyeoglu <[email protected]>
#
# SPDX-License-Identifier: MPL-2.0

{
description = "Deploy GNU hello to localhost";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
deploy-rs.url = "github:serokell/deploy-rs";
};

outputs = inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [inputs.deploy-rs.flakeModule];

flake.deploy.nodes.example = {
hostname = "localhost";
profiles.hello = {
user = "balsoft";
path = inputs.deploy-rs.lib.x86_64-linux.setActivate inputs.nixpkgs.legacyPackages.x86_64-linux.hello "./bin/hello";
};
};
systems = [
# systems for which you want to build the `perSystem` attributes
"x86_64-linux"
];
};
}
37 changes: 37 additions & 0 deletions flake.lock

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

3 changes: 3 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
url = "github:edolstra/flake-compat";
flake = false;
};
flake-parts.url = "github:hercules-ci/flake-parts";
};

outputs = { self, nixpkgs, utils, ... }@inputs:
rec {
flakeModule = ./nix/flake-module.nix;

overlay = final: prev: let
system = final.stdenv.hostPlatform.system;
darwinOptions = final.lib.optionalAttrs final.stdenv.isDarwin {
Expand Down
115 changes: 115 additions & 0 deletions nix/flake-module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# SPDX-FileCopyrightText: 2024 Sefa Eyeoglu <[email protected]>
#
# SPDX-License-Identifier: MPL-2.0

{config, inputs, lib, ...}: let
inherit (lib) mkOption types;
inherit (inputs) deploy-rs;

cfg = config.flake.deploy;

genericSettings = {
options = {
sshUser = mkOption {
type = with types; nullOr str;
default = null;
};
user = mkOption {
type = with types; nullOr str;
default = null;
};
sshOpts = mkOption {
type = with types; listOf str;
default = [];
};
fastConnection = mkOption {
type = with types; nullOr bool;
default = null;
};
autoRollback = mkOption {
type = with types; nullOr bool;
default = null;
};
confirmTimeout = mkOption {
type = with types; nullOr int;
default = null;
};
activationTimeout = mkOption {
type = with types; nullOr int;
default = null;
};
tempPath = mkOption {
type = with types; nullOr str;
default = null;
};
magicRollback = mkOption {
type = with types; nullOr bool;
default = null;
};
sudo = mkOption {
type = with types; nullOr str;
default = null;
};
remoteBuild = mkOption {
type = with types; nullOr bool;
default = null;
};
interactiveSudo = mkOption {
type = with types; nullOr bool;
default = null;
};
};
};
profileSettings = {
options = {
path = mkOption {
type = types.package;
};
profilePath = mkOption {
type = with types; nullOr str;
default = null;
};
};
};
nodeSettings = {
options = {
hostname = mkOption {
type = types.str;
};
profilesOrder = mkOption {
type = with types; listOf str;
default = [];
};
profiles = mkOption {
type = types.attrsOf profileModule;
};
};
};

nodesSettings = {
options.nodes = mkOption {
type = types.attrsOf nodeModule;
};
};

profileModule = types.submoduleWith {
modules = [genericSettings profileSettings];
};

nodeModule = types.submoduleWith {
modules = [genericSettings nodeSettings];
};

rootModule = types.submoduleWith {
modules = [genericSettings nodesSettings];
};
in {
options.flake.deploy = mkOption {
type = rootModule;
};
config = {
perSystem = {system, ...}: {
checks = lib.mkIf (deploy-rs.lib ? ${system}) (deploy-rs.lib.${system}.deployChecks cfg);
};
};
}
Loading