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

feat: configure DNIeRemote via HM module. (Partially) implements #24 #60

Merged
merged 4 commits into from
Jan 9, 2025
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
10 changes: 10 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,23 @@
nixos-autofirma-firefoxIntegration-sign-document = pkgs.callPackage ./nix/tests/nixos/autofirma/firefoxIntegration/sign-document.nix { inherit self; };
## Configurador FNMT-RCM
nixos-configuradorfnmt-firefoxIntegration-request = pkgs.callPackage ./nix/tests/nixos/configuradorfnmt/firefoxIntegration/request-certificate.nix { inherit self; };
##DNIe Remote
nixos-dnieremote-config-jumpintro-wifi = pkgs.callPackage ./nix/tests/nixos/dnieremote/config/jumpintro-wifi.nix { inherit self; };
nixos-dnieremote-config-jumpintro-usb = pkgs.callPackage ./nix/tests/nixos/dnieremote/config/jumpintro-usb.nix { inherit self; };
nixos-dnieremote-config-jumpintro-no = pkgs.callPackage ./nix/tests/nixos/dnieremote/config/jumpintro-no.nix { inherit self; };
nixos-dnieremote-config-wifiport = pkgs.callPackage ./nix/tests/nixos/dnieremote/config/wifiport.nix { inherit self; };

# Home Manager Modules
## AutoFirma
hm-as-nixos-module-autofirma-cli-sign-document = pkgs.callPackage ./nix/tests/hm-as-nixos-module/autofirma/cli/sign-document.nix { inherit self home-manager; };
hm-as-nixos-module-autofirma-firefoxIntegration-sign-document = pkgs.callPackage ./nix/tests/hm-as-nixos-module/autofirma/firefoxIntegration/sign-document.nix { inherit self home-manager; };
## Configurador FNMT-RCM
hm-as-nixos-module-configuradorfnmt-firefoxIntegration-request = pkgs.callPackage ./nix/tests/hm-as-nixos-module/configuradorfnmt/firefoxIntegration/request-certificate.nix { inherit self home-manager; };
## DNIe Remote
hm-as-nixos-module-dnieremote-config-jumpintro-wifi = pkgs.callPackage ./nix/tests/hm-as-nixos-module/dnieremote/config/jumpintro-wifi.nix { inherit self home-manager; };
hm-as-nixos-module-dnieremote-config-jumpintro-usb = pkgs.callPackage ./nix/tests/hm-as-nixos-module/dnieremote/config/jumpintro-usb.nix { inherit self home-manager; };
hm-as-nixos-module-dnieremote-config-jumpintro-no = pkgs.callPackage ./nix/tests/hm-as-nixos-module/dnieremote/config/jumpintro-no.nix { inherit self home-manager; };
hm-as-nixos-module-dnieremote-config-wifiport = pkgs.callPackage ./nix/tests/hm-as-nixos-module/dnieremote/config/wifiport.nix { inherit self home-manager; };
};
};
};
Expand Down
25 changes: 25 additions & 0 deletions nix/dnieremote/hm-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ inputs: {
}:
with lib; let
cfg = config.programs.dnieremote;
intro2value = {
"no" = "0";
"usb" = "241";
"wifi" = "242";
};
inherit (pkgs.stdenv.hostPlatform) system;
in {
options.programs.dnieremote = {
Expand All @@ -22,8 +27,28 @@ in {
The DNIeRemote package after applying configuration.
'';
};
jumpIntro = mkOption {
type = types.enum [ "usb" "wifi" "no" ];
default = "no";
description = "Skip the intro and jump to a specific screen.";
};
wifiPort = mkOption {
type = types.int;
default = 9501;
description = "The port to use for the Wi-Fi connection.";
};
usbPort = mkOption {
type = types.int;
default = 9501;
description = "The port to use for the USB connection.";
};
};
config = mkIf cfg.enable {
home.packages = [cfg.finalPackage];
home.file."dnieRemote.cfg".text = ''
jumpintro=${intro2value.${cfg.jumpIntro}};
wifiport=${toString cfg.wifiPort};
usbport=${toString cfg.usbPort};
'';
};
}
50 changes: 49 additions & 1 deletion nix/dnieremote/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ inputs: {
}:
with lib; let
cfg = config.programs.dnieremote;
intro2value = {
"no" = "0";
"usb" = "241";
"wifi" = "242";
};
inherit (pkgs.stdenv.hostPlatform) system;
in {
options.programs.dnieremote = {
Expand All @@ -14,16 +19,59 @@ in {
finalPackage = mkOption {
type = types.package;
readOnly = true;
default = cfg.package;
default = cfg.package.overrideAttrs (old: {
nativeBuildInputs = old.nativeBuildInputs or [] ++ [ pkgs.makeWrapper ];

postFixup = old.postFixup + ''
mv $out/bin/dnieremotewizard $out/bin/dnieremotewizard-customwrap
cat > $out/bin/dnieremotewizard <<'EOF'
#!${pkgs.stdenv.shell}
export XAUTHORITY=$HOME/.Xauthority
export HOME=/etc/dnieRemote
EOF
cat >> $out/bin/dnieremotewizard <<EOF
exec $out/bin/dnieremotewizard-customwrap "\$@"
EOF
chmod +x $out/bin/dnieremotewizard
'';
});
defaultText =
literalExpression
"`programs.dnieremote.package` with applied configuration";
description = ''
The DNIeRemote package after applying configuration.
'';
};
jumpIntro = mkOption {
type = types.enum [ "usb" "wifi" "no" ];
default = "no";
description = "Skip the intro and jump to a specific screen.";
};
wifiPort = mkOption {
type = types.int;
default = 9501;
description = "The port to use for the Wi-Fi connection.";
};
usbPort = mkOption {
type = types.int;
default = 9501;
description = "The port to use for the USB connection.";
};
openFirewall = mkOption {
type = types.bool;
default = false;
description = "Open the firewall for the selected port.";
};
};
config = mkIf cfg.enable {
environment.systemPackages = [cfg.finalPackage];
environment.etc."dnieRemote/dnieRemote.cfg".text = ''
jumpintro=${intro2value.${cfg.jumpIntro}};
wifiport=${toString cfg.wifiPort};
usbport=${toString cfg.usbPort};
'';
networking.firewall = mkIf cfg.openFirewall {
allowedTCPPorts = [ cfg.wifiPort ];
};
};
}
55 changes: 55 additions & 0 deletions nix/tests/hm-as-nixos-module/dnieremote/config/jumpintro-no.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{ self, pkgs, home-manager, lib }:
let
stateVersion = "${lib.versions.major lib.version}.${lib.versions.minor lib.version}";
in

pkgs.nixosTest {
name = "test-hm-as-nixos-module-dnieremote-config-jumpintro-no";
nodes.machine = { config, pkgs, modulesPath, ... }: {
imports = [
home-manager.nixosModules.home-manager
(modulesPath + "./../tests/common/x11.nix")
];

test-support.displayManager.auto.user = "autofirma-nix-user";

users.users.autofirma-nix-user = {
isNormalUser = true;
};

home-manager.users.autofirma-nix-user = {config, ... }: {
imports = [
self.homeManagerModules.dnieremote
];

programs.dnieremote.enable = true;
programs.dnieremote.jumpIntro = "no";

home.stateVersion = stateVersion;
};

environment.systemPackages = with pkgs; [
xorg.xhost.out
];
system.stateVersion = stateVersion;
};

testScript = ''
def user_cmd(cmd):
return f"su -l autofirma-nix-user --shell /bin/sh -c $'export XDG_RUNTIME_DIR=/run/user/$UID ; {cmd}'"

machine.wait_for_unit("default.target")
machine.wait_for_x()

# Authorize root (testScript user) to connect to the user's X server
machine.succeed(user_cmd("xhost +local:"))

machine.execute(user_cmd("dnieremotewizard >&2 &"))

# Wait for the wizard to start and present the introduction screen
machine.wait_for_window('Introducción', 30)
machine.sleep(5)
machine.screenshot("screen")
'';
}

55 changes: 55 additions & 0 deletions nix/tests/hm-as-nixos-module/dnieremote/config/jumpintro-usb.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{ self, pkgs, home-manager, lib }:
let
stateVersion = "${lib.versions.major lib.version}.${lib.versions.minor lib.version}";
in

pkgs.nixosTest {
name = "test-hm-as-nixos-module-dnieremote-config-jumpintro-usb";
nodes.machine = { config, pkgs, modulesPath, ... }: {
imports = [
home-manager.nixosModules.home-manager
(modulesPath + "./../tests/common/x11.nix")
];

test-support.displayManager.auto.user = "autofirma-nix-user";

users.users.autofirma-nix-user = {
isNormalUser = true;
};

home-manager.users.autofirma-nix-user = {config, ... }: {
imports = [
self.homeManagerModules.dnieremote
];

programs.dnieremote.enable = true;
programs.dnieremote.jumpIntro = "usb";

home.stateVersion = stateVersion;
};

environment.systemPackages = with pkgs; [
xorg.xhost.out
];
system.stateVersion = stateVersion;
};

testScript = ''
def user_cmd(cmd):
return f"su -l autofirma-nix-user --shell /bin/sh -c $'export XDG_RUNTIME_DIR=/run/user/$UID ; {cmd}'"

machine.wait_for_unit("default.target")
machine.wait_for_x()

# Authorize root (testScript user) to connect to the user's X server
machine.succeed(user_cmd("xhost +local:"))

machine.execute(user_cmd("dnieremotewizard >&2 &"))

# Wait for the wizard to start and jump into the usb screen and fail due to no usb device
machine.wait_for_window('Finalización', 30)
machine.sleep(5)
machine.screenshot("screen")
'';
}

55 changes: 55 additions & 0 deletions nix/tests/hm-as-nixos-module/dnieremote/config/jumpintro-wifi.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{ self, pkgs, home-manager, lib }:
let
stateVersion = "${lib.versions.major lib.version}.${lib.versions.minor lib.version}";
in

pkgs.nixosTest {
name = "test-hm-as-nixos-module-dnieremote-config-jumpintro-wifi";
nodes.machine = { config, pkgs, modulesPath, ... }: {
imports = [
home-manager.nixosModules.home-manager
(modulesPath + "./../tests/common/x11.nix")
];

test-support.displayManager.auto.user = "autofirma-nix-user";

users.users.autofirma-nix-user = {
isNormalUser = true;
};

home-manager.users.autofirma-nix-user = {config, ... }: {
imports = [
self.homeManagerModules.dnieremote
];

programs.dnieremote.enable = true;
programs.dnieremote.jumpIntro = "wifi";

home.stateVersion = stateVersion;
};

environment.systemPackages = with pkgs; [
xorg.xhost.out
];
system.stateVersion = stateVersion;
};

testScript = ''
def user_cmd(cmd):
return f"su -l autofirma-nix-user --shell /bin/sh -c $'export XDG_RUNTIME_DIR=/run/user/$UID ; {cmd}'"

machine.wait_for_unit("default.target")
machine.wait_for_x()

# Authorize root (testScript user) to connect to the user's X server
machine.succeed(user_cmd("xhost +local:"))

machine.execute(user_cmd("dnieremotewizard >&2 &"))

# Wait for the wizard to start and jump into the wifi screen
machine.wait_for_window('Vinculación dispositivo y DNIe', 30)
machine.sleep(5)
machine.screenshot("screen")
'';
}

59 changes: 59 additions & 0 deletions nix/tests/hm-as-nixos-module/dnieremote/config/wifiport.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{ self, pkgs, home-manager, lib }:
let
stateVersion = "${lib.versions.major lib.version}.${lib.versions.minor lib.version}";
in

pkgs.nixosTest {
name = "test-hm-as-nixos-module-dnieremote-config-wifiport";
nodes.machine = { config, pkgs, modulesPath, ... }: {
imports = [
home-manager.nixosModules.home-manager
(modulesPath + "./../tests/common/x11.nix")
];

test-support.displayManager.auto.user = "autofirma-nix-user";

users.users.autofirma-nix-user = {
isNormalUser = true;
};

home-manager.users.autofirma-nix-user = {config, ... }: {
imports = [
self.homeManagerModules.dnieremote
];

programs.dnieremote.enable = true;
programs.dnieremote.jumpIntro = "wifi";
programs.dnieremote.wifiPort = 4444;

home.stateVersion = stateVersion;
};

environment.systemPackages = with pkgs; [
xorg.xhost.out
];
system.stateVersion = stateVersion;
};

testScript = ''
def user_cmd(cmd):
return f"su -l autofirma-nix-user --shell /bin/sh -c $'export XDG_RUNTIME_DIR=/run/user/$UID ; {cmd}'"


machine.wait_for_unit("default.target")
machine.wait_for_x()

bind_ip = machine.execute("ip -4 route get 1.1.1.1 | grep -oP '(?<=src )\d+(\.\d+){3}'")[1].rstrip('\n')

# Authorize root (testScript user) to connect to the user's X server
machine.succeed(user_cmd("xhost +local:"))

machine.succeed("grep 'wifiport=4444;' /home/autofirma-nix-user/dnieRemote.cfg")

# Wait for the wizard to start and jump into the wifi screen
machine.execute(user_cmd("dnieremotewizard >&2 &"))

machine.wait_for_open_port(4444, bind_ip, 30)
'';
}

32 changes: 32 additions & 0 deletions nix/tests/nixos/dnieremote/config/jumpintro-no.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{ self, pkgs, lib }:
let
stateVersion = "${lib.versions.major lib.version}.${lib.versions.minor lib.version}";
in

pkgs.nixosTest {
name = "test-nixos-module-dnieremote-config-jumpintro-no";
nodes.machine = { config, pkgs, modulesPath, ... }: {
imports = [
self.nixosModules.dnieremote
(modulesPath + "./../tests/common/x11.nix")
];

programs.dnieremote.enable = true;
programs.dnieremote.jumpIntro = "no";

system.stateVersion = stateVersion;
};

testScript = ''
machine.wait_for_unit("default.target")
machine.wait_for_x()

machine.execute("dnieremotewizard >&2 &")

# Wait for the wizard to start and present the introduction screen
machine.wait_for_window('Introducción', 30)
machine.sleep(5)
machine.screenshot("screen")
'';
}

Loading
Loading