Skip to content

Commit

Permalink
Merge pull request #3 from nikstur/upstreamed
Browse files Browse the repository at this point in the history
treewide: take care of userborn being upstreamed in nixpkgs
  • Loading branch information
nikstur authored Sep 9, 2024
2 parents b9f7007 + 0dbbc53 commit 0b4d0cc
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 702 deletions.
68 changes: 3 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

Declaratively bear (manage) Linux users and groups.

Upstream status: https://github.com/NixOS/nixpkgs/pull/332719

## Features

- Create system (UID < 1000) and normal (UID >= 1000) users.
Expand All @@ -22,72 +20,12 @@ will run on any Linux.

## Getting Started

To enable Userborn you need to import the module and enable the service:
### NixOS

```nix
services.userborn.enable = true;
```

### Flakes
Userborn is available in Nixpkgs (nixos-unstable). To enable it:

```nix
# file: flake.nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
userborn = {
url = "github:nikstur/userborn";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, userborn, ...}: {
nixosConfigurations = {
yourHost = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
# This is not a complete NixOS configuration and you need to reference
# your normal configuration here.
userborn.nixosModules.userborn
({ ... }: {
services.userborn.enable = true;
})
];
};
};
};
}
```


### Niv

```console
$ niv add nikstur/userborn
Adding package userborn
Writing new sources file
Done: Adding package userborn
```

```nix
# file: configuration.nix
{ ... }:
let
sources = import ./nix/sources.nix;
lanzaboote = import sources.lanzaboote;
in
{
# This is not a complete NixOS configuration and you need to reference
# your normal configuration here.
imports = [ lanzaboote.nixosModules.lanzaboote ];
services.userborn.enable = true;
}
services.userborn.enable = true;
```

### Idempotence
Expand Down
38 changes: 12 additions & 26 deletions flake.lock

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

167 changes: 82 additions & 85 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
url = "github:cachix/pre-commit-hooks.nix";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-compat.follows = "flake-compat";
};
};

Expand All @@ -33,97 +34,93 @@
systems,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } (
{ moduleWithSystem, ... }:
{
systems = import systems;

imports = [ inputs.pre-commit-hooks-nix.flakeModule ];

flake.nixosModules.userborn = moduleWithSystem (
perSystem@{ config }:
{ ... }:
{
imports = [ ./nix/modules/userborn.nix ];

services.userborn.package = perSystem.config.packages.userborn;
}
);

perSystem =
{
config,
system,
pkgs,
lib,
...
}:
{
packages = import ./nix/packages { inherit pkgs; } // {
default = config.packages.userborn;
flake-parts.lib.mkFlake { inherit inputs; } {
systems = import systems;

imports = [ inputs.pre-commit-hooks-nix.flakeModule ];

perSystem =
{
config,
system,
pkgs,
lib,
...
}:
{
packages = {
userborn = pkgs.userborn.overrideAttrs {
src = lib.sourceFilesBySuffices ./rust/userborn [
".rs"
".toml"
".lock"
];
sourceRoot = null;
};
default = config.packages.userborn;
};

checks =
{
clippy = config.packages.userborn.overrideAttrs (
_: previousAttrs: {
pname = previousAttrs.pname + "-clippy";
nativeCheckInputs = (previousAttrs.nativeCheckInputs or [ ]) ++ [ pkgs.clippy ];
checkPhase = "cargo clippy";
}
);
rustfmt = config.packages.userborn.overrideAttrs (
_: previousAttrs: {
pname = previousAttrs.pname + "-rustfmt";
nativeCheckInputs = (previousAttrs.nativeCheckInputs or [ ]) ++ [ pkgs.rustfmt ];
checkPhase = "cargo fmt --check";
}
);
}
// (import ./nix/tests {
inherit pkgs;
extraBaseModules = {
inherit (self.nixosModules) userborn;
};
});

pre-commit = {
check.enable = true;

settings = {
hooks = {
nixfmt = {
enable = true;
package = pkgs.nixfmt-rfc-style;
};
statix.enable = true;
};
};
checks =
let
overlayedPkgs = pkgs.extend (final: prev: { inherit (config.packages) userborn; });
in
{
clippy = config.packages.userborn.overrideAttrs (
_: previousAttrs: {
pname = previousAttrs.pname + "-clippy";
nativeCheckInputs = (previousAttrs.nativeCheckInputs or [ ]) ++ [ pkgs.clippy ];
checkPhase = "cargo clippy";
}
);
rustfmt = config.packages.userborn.overrideAttrs (
_: previousAttrs: {
pname = previousAttrs.pname + "-rustfmt";
nativeCheckInputs = (previousAttrs.nativeCheckInputs or [ ]) ++ [ pkgs.rustfmt ];
checkPhase = "cargo fmt --check";
}
);
inherit (overlayedPkgs.nixosTests)
userborn
userborn-mutable-users
userborn-mutable-etc
userborn-immutable-users
userborn-immutable-etc
;
};

devShells.default = pkgs.mkShell {
shellHook = ''
${config.pre-commit.installationScript}
'';

packages = [
pkgs.niv
pkgs.nixfmt-rfc-style
pkgs.clippy
pkgs.rustfmt
pkgs.cargo-machete
pkgs.cargo-edit
pkgs.cargo-bloat
pkgs.cargo-deny
pkgs.cargo-cyclonedx
];

inputsFrom = [ config.packages.userborn ];
pre-commit = {
check.enable = true;

RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
settings = {
hooks = {
nixfmt-rfc-style.enable = true;
statix.enable = true;
};
};
};

devShells.default = pkgs.mkShell {
shellHook = ''
${config.pre-commit.installationScript}
'';

packages = [
pkgs.niv
pkgs.nixfmt-rfc-style
pkgs.clippy
pkgs.rustfmt
pkgs.cargo-machete
pkgs.cargo-edit
pkgs.cargo-bloat
pkgs.cargo-deny
pkgs.cargo-cyclonedx
];

inputsFrom = [ config.packages.userborn ];

RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
};
}
);

};
};
}
Loading

0 comments on commit 0b4d0cc

Please sign in to comment.