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

load devshell from flake #673

Merged
merged 3 commits into from
Nov 17, 2024
Merged
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
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
56 changes: 29 additions & 27 deletions pkgs/sops-install-secrets/nixos-test.nix → checks/nixos-test.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{ lib, testers }:
let
testAssets = ../pkgs/sops-install-secrets/test-assets;

userPasswordTest =
name: extraConfig:
testers.runNixOSTest {
Expand All @@ -8,12 +10,12 @@ let
{ config, lib, ... }:
{
imports = [
../../modules/sops
../modules/sops
extraConfig
];
sops = {
age.keyFile = "/run/age-keys.txt";
defaultSopsFile = ./test-assets/secrets.yaml;
defaultSopsFile = testAssets + "/secrets.yaml";
secrets.test_key.neededForUsers = true;
secrets."nested/test/file".owner = "example-user";
};
Expand Down Expand Up @@ -58,16 +60,16 @@ in
nodes.server =
{ ... }:
{
imports = [ ../../modules/sops ];
imports = [ ../modules/sops ];
services.openssh.enable = true;
services.openssh.hostKeys = [
{
type = "rsa";
bits = 4096;
path = ./test-assets/ssh-key;
path = testAssets + "/ssh-key";
}
];
sops.defaultSopsFile = ./test-assets/secrets.yaml;
sops.defaultSopsFile = testAssets + "/secrets.yaml";
sops.secrets.test_key = { };
};

Expand All @@ -82,17 +84,17 @@ in
nodes.machine =
{ lib, ... }:
{
imports = [ ../../modules/sops ];
imports = [ ../modules/sops ];
sops = {
age.keyFile = "/run/age-keys.txt";
defaultSopsFile = ./test-assets/secrets.yaml;
defaultSopsFile = testAssets + "/secrets.yaml";
secrets.test_key = { };
keepGenerations = lib.mkDefault 0;
};

# must run before sops sets up keys
boot.initrd.postDeviceCommands = ''
cp -r ${./test-assets/age-keys.txt} /run/age-keys.txt
cp -r ${testAssets + "/age-keys.txt"} /run/age-keys.txt
chmod -R 700 /run/age-keys.txt
'';

Expand Down Expand Up @@ -128,10 +130,10 @@ in
nodes.machine =
{ config, ... }:
{
imports = [ ../../modules/sops ];
imports = [ ../modules/sops ];
sops = {
age.keyFile = "/run/age-keys.txt";
defaultSopsFile = ./test-assets/secrets.yaml;
defaultSopsFile = testAssets + "/secrets.yaml";
secrets = {
test_key = { };

Expand Down Expand Up @@ -166,7 +168,7 @@ in

# must run before sops sets up keys
boot.initrd.postDeviceCommands = ''
cp -r ${./test-assets/age-keys.txt} /run/age-keys.txt
cp -r ${testAssets + "/age-keys.txt"} /run/age-keys.txt
chmod -R 700 /run/age-keys.txt
'';
};
Expand Down Expand Up @@ -196,17 +198,17 @@ in
age-ssh-keys = testers.runNixOSTest {
name = "sops-age-ssh-keys";
nodes.machine = {
imports = [ ../../modules/sops ];
imports = [ ../modules/sops ];
services.openssh.enable = true;
services.openssh.hostKeys = [
{
type = "ed25519";
path = ./test-assets/ssh-ed25519-key;
path = testAssets + "/ssh-ed25519-key";
}
];

sops = {
defaultSopsFile = ./test-assets/secrets.yaml;
defaultSopsFile = testAssets + "/secrets.yaml";
secrets.test_key = { };
# Generate a key and append it to make sure it appending doesn't break anything
age = {
Expand All @@ -227,15 +229,15 @@ in
nodes.server =
{ lib, config, ... }:
{
imports = [ ../../modules/sops ];
imports = [ ../modules/sops ];

users.users.someuser = {
isSystemUser = true;
group = "nogroup";
};

sops.gnupg.home = "/run/gpghome";
sops.defaultSopsFile = ./test-assets/secrets.yaml;
sops.defaultSopsFile = testAssets + "/secrets.yaml";
sops.secrets.test_key.owner = config.users.users.someuser.name;
sops.secrets."nested/test/file".owner = config.users.users.someuser.name;
sops.secrets.existing-file = {
Expand All @@ -244,7 +246,7 @@ in
};
# must run before sops
system.activationScripts.gnupghome = lib.stringAfter [ "etc" ] ''
cp -r ${./test-assets/gnupghome} /run/gpghome
cp -r ${testAssets + "/gnupghome"} /run/gpghome
chmod -R 700 /run/gpghome

touch /run/existing-file
Expand All @@ -254,7 +256,7 @@ in
#environment.variables = {
# GNUPGHOME = "/run/gpghome";
# SOPS_GPG_EXEC="${pkgs.gnupg}/bin/gpg";
# SOPSFILE = "${./test-assets/secrets.yaml}";
# SOPSFILE = "${testAssets + "/secrets.yaml"}";
#};
};
testScript = ''
Expand Down Expand Up @@ -282,10 +284,10 @@ in
nodes.machine =
{ config, ... }:
{
imports = [ ../../modules/sops ];
imports = [ ../modules/sops ];
sops = {
age.keyFile = "/run/age-keys.txt";
defaultSopsFile = ./test-assets/secrets.yaml;
defaultSopsFile = testAssets + "/secrets.yaml";
secrets.test_key = { };

# Verify that things work even with `neededForUsers` secrets. See
Expand All @@ -295,7 +297,7 @@ in

# must run before sops sets up keys
boot.initrd.postDeviceCommands = ''
cp -r ${./test-assets/age-keys.txt} /run/age-keys.txt
cp -r ${testAssets + "/age-keys.txt"} /run/age-keys.txt
chmod -R 700 /run/age-keys.txt
'';

Expand Down Expand Up @@ -361,11 +363,11 @@ in
nodes.machine =
{ config, ... }:
{
imports = [ ../../modules/sops ];
imports = [ ../modules/sops ];

sops = {
age.keyFile = "/run/age-keys.txt";
defaultSopsFile = ./test-assets/secrets.yaml;
defaultSopsFile = testAssets + "/secrets.yaml";
secrets.test_key = {
restartUnits = [
"restart-unit.service"
Expand All @@ -390,7 +392,7 @@ in

# must run before sops sets up keys
boot.initrd.postDeviceCommands = ''
cp -r ${./test-assets/age-keys.txt} /run/age-keys.txt
cp -r ${testAssets + "/age-keys.txt"} /run/age-keys.txt
chmod -R 700 /run/age-keys.txt
'';

Expand Down Expand Up @@ -551,7 +553,7 @@ in
user-passwords = userPasswordTest "sops-user-passwords" {
# must run before sops sets up keys
boot.initrd.postDeviceCommands = ''
cp -r ${./test-assets/age-keys.txt} /run/age-keys.txt
cp -r ${testAssets + "/age-keys.txt"} /run/age-keys.txt
chmod -R 700 /run/age-keys.txt
'';
};
Expand All @@ -568,7 +570,7 @@ in

# must run before sops sets up keys
systemd.services."sops-install-secrets-for-users".preStart = ''
printf '${builtins.readFile ./test-assets/age-keys.txt}' > /run/age-keys.txt
printf '${builtins.readFile (testAssets + "/age-keys.txt")}' > /run/age-keys.txt
chmod -R 700 /run/age-keys.txt
'';
}
Expand All @@ -586,7 +588,7 @@ in

# must run before sops sets up keys
systemd.services."sops-install-secrets-for-users".preStart = ''
printf '${builtins.readFile ./test-assets/age-keys.txt}' > /run/age-keys.txt
printf '${builtins.readFile testAssets + "/age-keys.txt"}' > /run/age-keys.txt
chmod -R 700 /run/age-keys.txt
'';
}
Expand Down
4 changes: 0 additions & 4 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ rec {
sops-init-gpg-key = pkgs.callPackage ./pkgs/sops-init-gpg-key { };
default = sops-init-gpg-key;

sops-pgp-hook = pkgs.lib.warn ''
sops-pgp-hook is deprecated, use sops-import-keys-hook instead.
Also see https://github.com/Mic92/sops-nix/issues/98
'' pkgs.callPackage ./pkgs/sops-pgp-hook { };
sops-import-keys-hook = pkgs.callPackage ./pkgs/sops-import-keys-hook { };

# backwards compatibility
Expand Down
8 changes: 5 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,14 @@
checks = eachSystem (
{ pkgs, system, ... }:
let
tests = self.packages.${system}.sops-install-secrets.tests;
packages-stable = import ./default.nix {
pkgs = privateInputs.nixpkgs-stable.legacyPackages.${system};
};
tests-stable = packages-stable.sops-install-secrets.tests;
dropOverride = attrs: nixpkgs.lib.removeAttrs attrs [ "override" ];
tests = dropOverride (pkgs.callPackage ./checks/nixos-test.nix { });
tests-stable = dropOverride (
privateInputs.nixpkgs-stable.legacyPackages.${system}.callPackage ./checks/nixos-test.nix { }
);
suffix-version =
version: attrs:
nixpkgs.lib.mapAttrs' (name: value: nixpkgs.lib.nameValuePair (name + version) value) attrs;
Expand All @@ -105,7 +108,6 @@
darwinConfigurations.sops-arm64 = privateInputs.nix-darwin.lib.darwinSystem {
modules = [
./checks/darwin.nix
#{ nixpkgs.pkgs = nixpkgs.legacyPackages.aarch64-darwin; }
{ nixpkgs.hostPlatform = "aarch64-darwin"; }
];
};
Expand Down
5 changes: 0 additions & 5 deletions pkgs/sops-install-secrets/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
stdenv,
vendorHash,
go,
callPackages,
}:
buildGoModule {
pname = "sops-install-secrets";
Expand All @@ -21,10 +20,6 @@ buildGoModule {
# requires root privileges for tests
doCheck = false;

passthru = {
tests = lib.optionalAttrs stdenv.isLinux (callPackages ./nixos-test.nix { });
};

outputs = [ "out" ] ++ lib.lists.optionals (stdenv.isLinux) [ "unittest" ];

postInstall =
Expand Down
13 changes: 10 additions & 3 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
{
pkgs ? import <nixpkgs> { },
mkShell,
bashInteractive,
go,
delve,
gnupg,
util-linux,
nix,
golangci-lint,
}:
pkgs.mkShell {
nativeBuildInputs = with pkgs; [
mkShell {
nativeBuildInputs = [
bashInteractive
go
delve
Expand Down