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

[wip] Tests for darwin and home-manager #667

Closed
wants to merge 2 commits into from
Closed
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
10 changes: 10 additions & 0 deletions checks/darwin.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
imports = [
../modules/nix-darwin/default.nix
];
nixpkgs.hostPlatform = "aarch64-darwin";
sops.secrets.test_key = { };
sops.defaultSopsFile = ../pkgs/sops-install-secrets/test-assets/secrets.yaml;
sops.age.generateKey = true;
system.stateVersion = 5;
}
14 changes: 14 additions & 0 deletions checks/home-manager.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{ config, ... }: {
imports = [
../modules/home-manager/sops.nix
];
home.stateVersion = "25.05";
home.username = "sops-user";
home.homeDirectory = "/home/sops-user";
home.enableNixpkgsReleaseCheck = false;

sops.age.generateKey = true;
sops.age.keyFile = "${config.home.homeDirectory}/.age-key.txt";
sops.secrets.test_key = { };
sops.defaultSopsFile = ../pkgs/sops-install-secrets/test-assets/secrets.yaml;
}
42 changes: 42 additions & 0 deletions flake.lock

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

32 changes: 30 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@
description = "Integrates sops into nixos";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.nixpkgs-stable.url = "github:NixOS/nixpkgs/release-24.05";

inputs.nix-darwin.url = "github:LnL7/nix-darwin";
inputs.nix-darwin.inputs.nixpkgs.follows = "nixpkgs";

inputs.home-manager.url = "github:nix-community/home-manager";
inputs.home-manager.inputs.nixpkgs.follows = "nixpkgs";

nixConfig.extra-substituters = ["https://cache.thalheim.io"];
nixConfig.extra-trusted-public-keys = ["cache.thalheim.io-1:R7msbosLEZKrxk/lKxf9BTjOOH7Ax3H0Qj0/6wiHOgc="];
outputs = {
self,
nixpkgs,
nixpkgs-stable
}: let
nixpkgs-stable,
nix-darwin,
home-manager,
} @ inputs: let
systems = [
"x86_64-linux"
"x86_64-darwin"
Expand Down Expand Up @@ -36,6 +45,25 @@
sops = ./modules/nix-darwin;
default = self.darwinModules.sops;
};

darwinConfigurations.sops = nix-darwin.lib.darwinSystem {
modules = [ ./checks/darwin.nix ];
specialArgs = {
inherit self;
inherit inputs;
};
};
legacyPackages = nixpkgs.lib.genAttrs ["x86_64-linux" "aarch64-linux" "aarch64-darwin"] (system: let
pkgs = nixpkgs.legacyPackages.${system};
in {
homeConfigurations.sops = home-manager.lib.homeManagerConfiguration {
modules = [
./checks/home-manager.nix
];
inherit pkgs;
};
});

packages = forAllSystems (system:
import ./default.nix {
pkgs = import nixpkgs {inherit system;};
Expand Down
4 changes: 2 additions & 2 deletions modules/nix-darwin/manifest-for.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{ writeTextFile, cfg }:

suffix: secrets: extraJson:
suffix: secrets: templates: extraJson:

writeTextFile {
name = "manifest${suffix}.json";
text = builtins.toJSON ({
secrets = builtins.attrValues secrets;
templates = builtins.attrValues templates;
# Does this need to be configurable?
secretsMountPoint = "/run/secrets.d";
symlinkPath = "/run/secrets";
Expand All @@ -15,7 +16,6 @@ writeTextFile {
ageKeyFile = cfg.age.keyFile;
ageSshKeyPaths = cfg.age.sshKeyPaths;
useTmpfs = false;
templates = cfg.templates;
placeholderBySecretName = cfg.placeholder;
userMode = false;
logging = {
Expand Down